New Apple Coding Language + Live Coding = WOW

Monkey Archive Forums/Digital Discussion/New Apple Coding Language + Live Coding = WOW

Difference(Posted 2014) [#1]
http://www.apple.com/apple-events/june-2014/

Check it out :-)


AdamRedwoods(Posted 2014) [#2]
Memory is managed automatically, and you don’t even need to type semi-colons.

https://developer.apple.com/swift/

No semi-colons? Finally!


nikoniko(Posted 2014) [#3]
it is similar to python with brackets.


Raph(Posted 2014) [#4]
iTunes link for the reference book, it's free: https://itunes.apple.com/gb/book/swift-programming-language/id881256329?mt=11

Looks pretty clean actually. I hate Obj C, so...


Xaron(Posted 2014) [#5]
That's great indeed! Well done Apple!


Shinkiro1(Posted 2014) [#6]
Swift and the XCode environment just remind me of things Bret Victor has been talking about for some years now.
Still, it's really cool.


Nobuyuki(Posted 2014) [#7]
no semicolons? I'm sold. I want to see what a For loop looks like though.


FelipeA(Posted 2014) [#8]
for loops:




Shinkiro1(Posted 2014) [#9]
The more I look into it the more I like it.
Btw, here is the free book/docs: https://itunes.apple.com/us/book/the-swift-programming-language/id881256329?mt=11


therevills(Posted 2014) [#10]
New target for MonkeyX? ;)


Difference(Posted 2014) [#11]
New target for MonkeyX? ;)

It would be interesting to take advantage of metal in some way.


dragon(Posted 2014) [#12]
ObjectiveC is a very bad and unreadable language...
So it is not very hard to create someting better...
It looks like Haxe - but without semicolons and without multi-targets


therevills(Posted 2014) [#13]
OMG it has the keyword "LET".... 1980s BASIC here we come!!


Samah(Posted 2014) [#14]
My God that is disgusting. I'd rather Objective-C. Looks to me like they're just reinventing the wheel for the sake of pleasing the Apple fanboys.


degac(Posted 2014) [#15]
Sure LET stands for CONST.
Clear and meaninful.

To be honest a language dedicated only (for what I know...) to Apple's ecosystem is quite boring and not so useful.

More interesting the METAL thing (a sort of highly optimized OpenGL for Apple A7). A sort of AMD-Mantle in the Directx field.


Supertino(Posted 2014) [#16]
I have always liked he type faces on MAC, Windows just cannot do it as nice.


Goodlookinguy(Posted 2014) [#17]
I don't understand why they couldn't just make a live testing environment for an existing popular scripting language like Lua, JavaScript, or Python. They have the resources to pull it off. Inventing a new language for it seems so unnecessary and causes unnecessary work for developers to adapt to learning this new language construct. But hey, whatever. I'm going to keep using Monkey X and my MiniC version, *cough* I mean Lua and JavaScript's bast*rd child.


Sammy(Posted 2014) [#18]
Apple only or cross-platform(probably Apple only I know but I can't find the link to confirm it)?


Goodlookinguy(Posted 2014) [#19]
I believe it's built into XCode, which means it's for Apple only. I could be wrong; so don't quote me on it.


Why0Why(Posted 2014) [#20]
It looks pretty nice but I don't ever envision myself investing the time to learn anything again that isn't cross platform(unless I am doing something embedded that is very specific.)


Danilo(Posted 2014) [#21]
For system API programming you don't have much choices. You can only use Objective-C for Cocoa programming.
I think it is good to have an alternative to Objective-C on Mac OS X for system API programming (writing libs).
On all other systems, direct API programming is usually done with languages of the C-family (C, C++, C#), and
Apple's Objective-C is different from that. With Swift they add now a 2nd language for Cocoa/API programming.

Objective-C:
ITableView *myTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
[myTableView insertSubview:mySubview atIndex:2];
[myTableView layoutIfNeeded];

UIColor *color = [UIColor colorWithRed:0.5 green:0.0 blue:0.5 alpha:1.0];

Swift:
let myTableView = UITableView(frame: CGRectZero, style: .Grouped)
myTableView.insertSubview(mySubview, atIndex: 2)
myTableView.layoutIfNeeded()

let color = UIColor(red: 0.5, green: 0.0, blue: 0.5, alpha: 1.0)

In my opinion Swift is more readable. Especially using the dot syntax to access members and methods, like C++/C#/Java/Haxe/Monkey X/...

I see it just as an alternative to Objective-C on Apple systems, and I think I will use Swift
for Cocoa programming in the future, instead Objective-C.


therevills(Posted 2014) [#22]
Heres an example of a simple OSX application written in Swift and Objective C:

Swift code
TestAppDelegate.swift
Import Cocoa

Class AppDelegate: NSObject, NSApplicationDelegate {
	@IBOutlet var window: NSWindow
	@IBOutlet var first : NSTextField
	@IBOutlet var last : NSTextField
	@IBOutlet var full : NSTextField

	func applicationDidFinishLaunching(aNotification: NSNotification?) {
		// Insert code here to initialize your application
	}

	func applicationWillTerminate(aNotification: NSNotification?) {
	}

	@IBAction func buttonClicked(sender : AnyObject) {
		full.stringValue = first.stringValue + “ “ + last.stringValue
		let myPopup:NSAlert = NSAlert()
		myPopup.messageText = “Hello”;
		myPopup.informativeText = “Full name is: \[full.stringValue]”
		myPopup.runModal()
	}
}


Objective C code
TestAppDelegate.h
#import <Cocoa/Cocoa.h>

@interface TESTingAppDelegate : NSObject <NSApplicationDelegate>
@property(weak) IBOutlet NSTextField *first;
@property(weak) IBOutlet NSTextField *second;
@property(weak) IBOutlet NSTextField *full;

@property(assign) IBOutlet NSWindow *window;

@end

TestAppDelegate.m
#import "TESTingAppDelegate.h"

@implementation TESTingAppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
	// Insert code here to initialize your application
}

- (IBAction)buttonClicked:(id)sender {
	self.full.stringValue = [NSString stringWithFormat:@"%@%@", self.first.stringValue, self.second.stringValue];
	NSAlert *alert = [[NSAlert alloc] init];
	alert.messageText =@"Hello";
	alert.informativeText = [@"Full name is " stringByAppendingString:self.full.stringValue];
	[alert runModal];
}

@end


To me the Swift code is a lot simpler and easy to read... but there are some very strange design decisions in Swift...


nikoniko(Posted 2014) [#23]
FlappySwift https://github.com/fullstackio/FlappySwift


garyk1968(Posted 2014) [#24]
Its far simpler and more approachable for beginners than ObjectiveC.

That said I don't know why they kept the IBOutlet/IBAction junk thats been a legacy of ObjC and very quirky. Other languages just instantiate of type UIButton or UILabel or whatever and the class itself has the methods and properties for handling the events, makes it much easier.

Gary


consty(Posted 2014) [#25]
Very impressive movement from Apple.

Where this language originally comes from?
Is this the actual implementation? http://swift-lang.org/main/

I watched the video on youtube and here's my opinion:

Pros:
- Impressive language, looks like a more advanced Javascript.
- Works flawlessly along side with the C based stack.
- It works as easy as a scripting language
- Can be compiled to native code thanks to LLVM (though Apple loves LLVM long time, since all of it's development stack is currently works in LLVM)
- Looks like beginners will love it (this is a very positive thing, more flappy bird clones please :) )

Cons:
- Looks like an experimental toy language, we will need to see it how will it come within 3 years from now.
- For use only within in the Apple ecosystem (either you're in or you're out, nothing more to discuss)
- Not open source (technically you don't care as long as it works and you work with it, but if you are more into stuff like decision making, like politics/marketing/management then you will surely can make up your mind).
- Personal view: It looks like they want to deprecate Objective C.


Sub_Zero(Posted 2014) [#26]
nice