Apple swift

I'm reading up on apple's new C language, Swift. It can return from a function multiple values with any combination of data types.

That is all. I'm sold!

The Swift programming language is the successor of Objective-C, I think it's not a C-family member but a C++-family member.
It has been developed to update the old-fashioned Obj-C and to result more easy and clear in use than it.
I didn't try it yet but voices on its performances are constrasting: someone says that it's faster than Obj-C, someone else says it's slower...
The only thing that it's clear is that it's an Apple-only language, due to the fact that it will run only on MAC/iOS.

yeah, it's iOS, OS X only which is a shame. It should be platform independent.

It's very friendly, it has a syntax that remembers me that one of Ruby.

I'm skimming through the use manual now. It's simple and powerful. It takes a little getting use to even for me since I know objective C.

I see a lot of rookie mistakes here on the forum like

if (x = 1)

C allows for this without throwing any errors. In swift this is illegal and will error. Neat change.

IMHO that should not be considered an error at all (I mean in the "C world"). I mean, it's legal even it's not logic. Who would have to know if an assignement has been done or not? In the other hand, who would have to do an assignement in an equality testing?
Why did they use two different symbols? I understand that there are historic considerations behinds, but I do not know them :wink:
Personally, I began programming with BASIC, and used the "=" sign both the operations, and I disagreed the way C interpretes those operands.

In swift you can do

if var x = 1

or

if let x = 1 //let is const in C

and that would be legal. I'm not sure how declaring the variable in the if condition works but that's legal.

I guess declaring a variable in the condition would be an automatic true?

Oh btw, the datatype on variables are assumed like

var x = 1

The compiler assumes x is an int since you assigned it an integer but you can you can manually do it too.

var x: Int = 1

mistergreen:
In swift you can do

if var x = 1

I guess declaring a variable in the condition would be an automatic true?

Its no different to C++:

if( int x = 1 )

Dunno about swift, however, C++ will return false if 0 was assigned.

Oh btw, the datatype on variables are assumed

C++11 has the 'auto' data type.

I'll stick with my platform independent stuff for now.

pYro_65:

if( int x = 1 )

Dunno about swift, however, C++ will return false if 0 was assigned.

In swift an int 1 and 0 can't represent true and false respectively. Only Boolean values.

Swift is now open source. I'm looking forward to being able to use it on my Arduinos! Is anybody out there looking at porting it?

moderator: removed crosspost

I haven't played around with Swift, but from what I've seen of it, it looks like a decent language. I've also looked into Rust - it too looks decent to work with.

But the "new kid" language I have the most experience with recently has been Go (btw, if you look into this, use the term "GoLang" in your searches - it will make things easier due to the commonality of the languages name).

I had to learn this language fairly quickly with a colleague of mine at my job, because we were implementing a driver for Docker and containers for my employer's public-facing API. After more than a bit of frustration, both I and my friend became "go converts".

The greatest thing we like about it, is that it doesn't let you "get away" with stuff. For instance, if you declare a variable but don't use it - it won't compile. At first, that (and many other small differences) feels like a huge burden - it makes you want to scream. Ultimately, though, it teaches you better coding style and control - so that you don't have orphaned code or anything else like that in your codebase. This leads to better understanding of the actual source code, and easier maintainability in the future.

Just one minor feature among many that has me sold on it.

Swift, though, I only gave a cursory look into, because back then it was an "Apple-only" product. Now that it is open source, though - it may be time I gave it a better look.

leo72:
IMHO that should not be considered an error at all (I mean in the "C world"). I mean, it's legal even it's not logic. Who would have to know if an assignement has been done or not? In the other hand, who would have to do an assignement in an equality testing?
Why did they use two different symbols?

Because they're two different operations.

Mathematically, "x = x + 1" in C or BASIC is nonsensical; Pascal and Algol were much better, IMO, in having an assignment operator ":=", so "x := x + 1;" (think of it as a left-pointing arrow, was how I was taught to look at it)

Here are reasons not to use Swift:

Mac Lock.
Fake or psuedo Linux port.
Apple and it's agressive abuse of patents.
Apple is the enemy of Open Source.
iJails
Richard Stallman hates Apple the most. :wink:
Apple Fanboys

Ufoguy:
Here are reasons not to use Swift:

Apple Fanboys

I love to read balanced critiques :slight_smile:

...R

mistergreen:
I'm reading up on apple's new C language, Swift. It can return from a function multiple values with any combination of data types.

That is all. I'm sold!

Whereas with C we have to resort to passing references and pointers to get more data back.
And then we learn C++ classes and the 'issue' becomes moot.

Ufoguy:
Here are reasons not to use Swift:

Mac Lock.
Fake or psuedo Linux port.
Apple and it's agressive abuse of patents.
Apple is the enemy of Open Source.
iJails
Richard Stallman hates Apple the most. :wink:
Apple Fanboys

I really hate to see total mythology in programming discussions. This is knee-jerk anti-apple open-source zealot nonsense.

You are probably using a Chrome Browser? Chrome was built with Apples open-source webkit, which has become the foundation of 70% of the internet (chrome, opera, safari, and nearly every mobile browser). If you have noticed, nearly every non-JVM new language is compiled by LLVM (rust, julia, go, swift, etc), and Clang is really taking over GCC throughout the industry. Where are these things from? Apple open source.

There is no such thing as iJails. Android is becoming just as locked down. Yes all of the underpinnings are open source... but guess what so is Apples (darwin.org). But the application space is where google derives value (that and by selling your information). Turns out companies and progress require money, and making money requires selling something unique and has customer value. Apple is no different.

i also really want i can write swift code for arduino.