Tuesday, 28 July 2015

10 Typical Programming Features Borrowed By Swift

10 Typical Programming Features Borrowed By Swift

1) Dictionaries (aka hash tables) -- from JavaScript

JavaScript programmers have long used square brackets to take in an integer as a traditional array or accept a string that then behaves like a hash table. Now Swift programmers can do the same thing. Apple calls the hash tables "Dictionaries" and offers a clean syntax for initializing them.

2)  Inferred data types -- from functional programming languages

Forcing variables to stick to a particular data type is an efficient way for programmers to catch bugs before the code even runs. The compiler checks data types and flags incompatibilities.
Of course, in modern programming, no one wants to spend all of those keystrokes specifying data types for every variable. Lately some of the best compilers have started inferring types from the data, which is usually easy to do when a variable is initialized. This began with some of the functional languages, like ML, and has since appeared in Haskell, Scala, and Opa, among others. Now that Microsoft added the feature to Version 3.0 of .Net, it's practically mainstream. Thanks to Swift, iOS developers can now save a few keystrokes, too.

3) Data structure declarations -- from C# and Java

What kind of data is stored in a data structure? Java introduced Generic types in Version 5 so that programmers could tell the compiler which data type will be pushed into the HashMaps, Arrays, or Collections. The greater-than and less-than symbols, aka angle brackets, specified what types would go inside. Around the same time, Microsoft added them to C#. Now it's Swift's turn to let programmers tell the compiler what to expect.

4) String templating -- from Cold Fusion, JSP, and others

Maybe computers worked with numbers long ago, but today it seems like most of a programmer's job is to glue together strings. Many programming tools offer ways to insert a variable's value into a template. Web tools such as Cold Fusion and Java Server Pages have long provided a simple way to mix data with HTML in templates.
Swift offers a sleek templating system with an escaped open parentheses, followed by the expression to evaluate, followed by a closed parentheses. Three extra characters may be the smallest number of keystrokes needed to offer this functionality.

5) Optional semicolons -- from JavaScript and Python

What's with all the semicolon hate? They're just a simple way for designating the end of a programming statement, but somehow a growing number of developers can't be bothered to type them.
In the past few years, some JavaScript and Python programmers have debated whether semicolons are truly optional. Is a semicolon necessary or merely good form? Swift weighs in definitely in the debate: Semicolons are optional at the end of lines. If you want to pack multiple expressions in the same line, you'll need a semicolon, but if you put them on individual lines, you don't need to wear out your right pinkie tapping the semicolon key.

6)Protocols (aka interfaces) -- from Java and C#

When programmers create elaborate object-oriented class structures in Java and C#, they often begin with an interface at the foundation. The interface is a basic class that defines the structure for all of the functions that the classes must offer if they want to fit the definition. Swift uses the term "protocol" for sketching out a blueprint for a collection of classes.

7)Tuples -- from Lisp and Python

Sometimes a method needs to return more than one value. Early languages like Lisp assumed that everything was a list or a tuple, and more modern languages like Python offer explicit syntax for matching up the N value returned from a method with the N variables that will be bound to them. Swift follows in this tradition.

8)Automatic reference (akin to garbage collection) -- from Java, C#, and (gasp) Objective-C

Early reports suggested that Swift was sporting garbage collection, those automatic routines that sweep through memory reclaiming bytes no longer in use. Java and C# programmers love garbage collection, at least until it causes their machine to freeze up for a second. Swift uses automatic reference counting, a similar solution that's been popular with Objective-C users. In this case, the acorn didn't fall far from the tree.

9) Signed and unsigned integers -- C# and Objective-C

Good system program often means working at the byte level. While some abstract languages, such as Java, have avoided the complexity of unsigned integers, other languages, such as C#, have embraced them. Swift offers signed and unsigned integers of one, two, four, and eight bytes -- just like Objective-C and all the better to hack.

10) Closures -- from Lisp and Scheme via JavaScript

JavaScript programmers love to pack up little anonymous bits of code and pass them around like functions. They picked up these closures from languages like Lisp and Scheme that fully developed the idea of Lambda functions. Swift now comes with closures and the ability to pass along functions as first-class objects.

Source: http://www.infoworld.com/article/2606431/application-development/155797-10-prominent-features-stolen-by-Apple-s-Swift-and-where-they-came-fro.html#slide1

No comments:

Post a Comment