Slashdot Mirror


Apple Announces New Programming Language Called Swift

jmcbain (1233044) writes "At WWDC 2014 today, Apple announced Swift, a new programming language. According to a report by Ars Technica: 'Swift seems to get rid of Objective C's reliance on defined pointers; instead, the compiler infers the variable type, just as many scripting languages do. ... The new language will rely on the automatic reference counting that Apple introduced to replace its garbage-collected version of Objective C. It will also be able to leverage the compiler technologies developed in LLVM for current development, such as autovectorization. ... Apple showed off a couple of cases where implementing the same algorithm in Swift provided a speedup of about 1.3X compared to the same code implemented in Objective C.'" Language basics, and a few worthwhile comments on LtU.

35 of 636 comments (clear)

  1. First Rhyme by Art3x · · Score: 4, Funny

    AAPL's YAPL

  2. Good bye source compatibility by ugen · · Score: 4, Interesting

    Good bye source compatibility. We hardly knew ye.
    First Windows, and now OSX. I am still maintaining applications that are built crossplatform (Windows/Mac/Linux, with unified GUI look) but it's getting harder every year and, by the looks of it, will be impossible soon.
    Which means that an individual developer (like myself) or a smaller shop would have to choose one big player/OS vendor and stick with it. That increases risk and makes small players that much less viable (while, of course, helping the big ones consolidate user base and profit).
    Funny how the world works.

    1. Re:Good bye source compatibility by angel'o'sphere · · Score: 5, Insightful

      Since when does Qt not work X-platform anymore?

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    2. Re:Good bye source compatibility by Lunix+Nutcase · · Score: 4, Insightful

      Why is this dumb post modded insightful? You can still use all the same languages you did before.

    3. Re:Good bye source compatibility by Anonymous Coward · · Score: 4, Informative

      What possible application could ever require GDB as a dependency?

      LLDB is a far superior debugger anyways.

    4. Re:Good bye source compatibility by ugen · · Score: 4, Interesting

      Qt does not (and cannot) support Windows "Metro" (or whatever the name is for the C#/event driven/non Win32 environment now)
      By the same token it won't be able to support this new environment.

      Qt, XWidgets and others like them rely on basic C compatibility and certain common UI themes and primitives to be able to build cross-platform libraries and applications. With proprietary, non-portable and non-overlapping languages vendors make sure that any development has to target their platform specifically.

      Aside from that, if new development environment does not support linking against "old" binary libraries - developers also don't get the benefit of code reuse (since they won't be able to use existing libraries for things like image handling, graphics, sound, networking, you name it).

    5. Re:Good bye source compatibility by Anonymous Coward · · Score: 5, Funny

      Creating GUI's in OSX is currently problematic because of font issues.

      Obviously this must be the case as no-one else is creating GUIs in OS X either. That, and the fact that OS X is hated the world over by designers for it's awful handling of fonts.

    6. Re:Good bye source compatibility by ddtstudio · · Score: 4, Insightful

      Hey, I'm not a developer/coder/programmer, so I honor and respect the work you've put in to things in the past. But if you've been tying yourself to a "unified GUI look" across platforms, you've long been dooming your products and yourself.

      As a UX person, I can throw data at you all day long that shows device/OS specificity and familiarity are key elements in making something work for the user. I'm sure you don't literally mean you chose either a menu bar in all app windows on every platform or a top-of-the-screen menu bar on every platform, but the obvious reason why that would be wrong also holds for controls, colors, placement, text sizes, and so on to the last turtle at the bottom.

    7. Re:Good bye source compatibility by Anonymous Coward · · Score: 4, Funny

      Could you tell me who your team is? I have a tumblr for really shitty software and I'd love to feature them!

    8. Re:Good bye source compatibility by Jane+Q.+Public · · Score: 4, Funny

      That, and the fact that OS X is hated the world over by designers for it's awful handling of fonts.

      As a programmer, I can tell you that designers are hated the world over for their awful handling of fonts.

    9. Re:Good bye source compatibility by macs4all · · Score: 4, Informative

      Apple has always been hostile to unified look on their platform.

      You do realize, of course, that you are talking about the company that literally wrote the book on good, consistent UI design, right?

      The above, linked pdf copy dates from 1995 (the earliest actual copy I could find in a 2 minute search), but Apple first published their most-excellent HIG manual on or around 1985, before most slashdotters were even born.

      Now, get off my lawn!

    10. Re:Good bye source compatibility by ljw1004 · · Score: 4, Informative

      Are you sure about the "metro"? Name is dead, but I was under impression that all new windows "apps" had to be written in C# against a new SDK that has neither binary nor source compatibility with Win32/posix/C/C++. I'd be glad to be wrong

      You're wrong! You can write Windows Store apps in C++ just fine. This C++ can use win32, posix, STL etc just fine. (however, all apps run in a sandbox, so some win32/posix functions aren't as powerful as normal, e.g. the sandbox doesn't let a Windows Store app enumerate files on the hard disk outside of the files it's allowed to touch).

      You can also write Windows Phone apps in the same C++. So a mobile app developer could write their core in posix platform-neutral C++, and have it portable across Android+iOS+Windows. I know a few who do.

      Of course posix doesn't have anything to do with windowing systems or touch, and win32 APIs (e.g. gdi32.dll, user32.dll) don't apply to windows store or phone apps since they don't have GDI or the traditional windowing system. So your C++ code will invoke new WinRT APIs to access the new functionalities. WinRT is perfectly compatible with posix/win32 APIs. Indeed, for some functionality (e.g. audio), you're REQUIRED to use win32 APIs because they're not exposed in WinRT.

      Here's some example code that shows how you'd mix the new WinRT APIs to get hold of sandbox-specific stuff, and then interop with traditional posix APIs. It also shows how the asynchronous nature of WinRT APIs combine with the synchronous traditional posix APIs:

              auto f1 = Windows::ApplicationModel::Package::Current->InstalledLocation;
              create_task(f1->GetFolderAsync("Assets")).then([this](StorageFolder ^f2)
              {
                      create_task(f2->GetFileAsync("Logo.scale-100.png")).then([this](StorageFile ^f3)
                      {
                              auto path = f3->Path;
                              FILE *f = _wfopen(path->Data, L"r");
                              byte buf[100];
                              fread(buf, 1, 100, f);
                              fclose(f)
                      });
              });

  3. Whoa 1.3x by the+eric+conspiracy · · Score: 4, Funny

    That's what about 1/10,000th of what hiring a good programmer would get you, at the price of not being to find any programmers.

    1. Re:Whoa 1.3x by SQLGuru · · Score: 4, Funny

      Now hiring Swift programmers. 10 years experience required. /sarcasm.

  4. Who designed this, and what drugs were they on? by shutdown+-p+now · · Score: 4, Interesting

    "Immutability has a slightly different meaning for arrays, however. You are still not allowed to perform any action that has the potential to change the size of an immutable array, but you are allowed to set a new value for an existing index in the array. This enables Swift’s Array type to provide optimal performance for array operations when the size of an array is fixed."

    i.e. Swift arrays that are "immutable" actually aren't. Way to rewrite the dictionary. But wait, it gets worse. Here's for some schizophrenia.

    "Structures and Enumerations Are Value Types. A value type is a type that is copied when it is assigned to a variable or constant, or when it is passed to a function. Swift’s Array and Dictionary types are implemented as structures."

    So far so good. I always liked collections that don't pretend to be any more than an aggregate of values, and copy semantics is a good thing in that context (so long as you still provide a way to share a single instance). But wait, it's all lies:

    "If you assign an Array instance to a constant or variable, or pass an Array instance as an argument to a function or method call, the contents of the array are not copied at the point that the assignment or call takes place. Instead, both arrays share the same sequence of element values. When you modify an element value through one array, the result is observable through the other. For arrays, copying only takes place when you perform an action that has the potential to modify the length of the array. This includes appending, inserting, or removing items, or using a ranged subscript to replace a range of items in the array"

    Swift, a language that is naturally designed to let you shoot your foot in the most elegant way possible, courtesy of Apple.

  5. Re:It's about time by Anonymous Coward · · Score: 5, Funny

    I can't wait to add this to my résumé.... I already have 2 years of experience with Swift!

  6. Swift Programmers Wanted by the+eric+conspiracy · · Score: 4, Funny

    Must have 5 years experience.

  7. Re:and it needs an new OS the mess up other apps by Anonymous Coward · · Score: 5, Funny

    and the comment grammar no sense slashdot article read.

    captcha: verbally. Seriously?

  8. SWIFT programmers by msobkow · · Score: 4, Interesting

    They could have chosen a name other than that of the international banking protocols. Asking for SWIFT programmers is going to get them a bevy of COBOL coders who know the protocol.

    --
    I do not fail; I succeed at finding out what does not work.
  9. Re:and it needs an new OS the mess up other apps by Anonymous Coward · · Score: 4, Funny

    *that poorly.

  10. You think that is the problem? by Ecuador · · Score: 4, Informative

    I mean, there is already a swift programming language. Yes, it is not popular, but when you decide on a name for your language don't you at least google it first? Is "swift" so unbelievably cool that a name collision (even with a "small" entity) does not matter? But, yeah, it is Apple we are talking about, they probably invented the word "swift" which people and companies like SUZUKI have been copying for other uses here and there...

    --
    Violence is the last refuge of the incompetent. Polar Scope Align for iOS
    1. Re:You think that is the problem? by mrjimorg · · Score: 4, Funny

      No, they Siri'd it. And Siri told them that there was no restaurants in the immediate area with the name swift so they figured they were ok

  11. Re:Somebody post a SWIFT example PLEASE! by Proudrooster · · Score: 4, Informative

    Ok, you guys are too slow, I RTFA and downloaded the iBook. So far, I am very much liking the SYNTAX, especially OBJECTS and FUNCTIONS, they even brought the LET keyword in from BASIC. SWIFT will make programming Apple products much easier for the C loving syntax crowd, from what I can see. Ahhh... what a breath of fresh air. Code snippet below of creating an object and exercising it. I feel bad for those that suffered through Objective-C.


    “class Square: NamedShape {
            var sideLength: Double

            init(sideLength: Double, name: String) {
                    self.sideLength = sideLength
                    super.init(name: name)
                    numberOfSides = 4
            }

            func area() -> Double {
                    return sideLength * sideLength
            }

            override func simpleDescription() -> String {
                    return "A square with sides of length \(sideLength)."
            }
    }
    let test = Square(sideLength: 5.2, name: "my test square")
    test.area()
    test.simpleDescription()”

    Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/us/jEUH0.l

  12. Re:Just what we need, another C++ clone by mark-t · · Score: 5, Funny

    ... a badly implemented subset of C++

    You mean like C++?

  13. Re:Since when does Qt "work" with OS X? by Kesha · · Score: 5, Informative

    There is VLC
    There is CMake
    There is my project -- https://sourceforge.net/projec...
    There is Sorenson Squeeze -- http://www.sorensonmedia.com/s...
    I am sure there are others

  14. Re:Since when does Qt "work" with OS X? by Guy+Harris · · Score: 4, Informative

    No this is NOT a troll, please read.

    A claim of cross-platform is one thing. But in practice I know of no significant apps using Qt that exist in the wild that work on OS X.

    Please provide a link to any mainstream working application for Mac OS X that uses Qt.

    $ otool -L /Applications/Google\ Earth.app//Contents//MacOS//Google\ Earth
    /Applications/Google Earth.app//Contents//MacOS//Google Earth:
    @rpath/libgoogleearth_free.dylib (compatibility version 0.0.0, current version 0.0.0)
    /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 19.0.0)
    /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 155.0.0)
    @rpath/QtCore.framework/Versions/4/QtCore (compatibility version 4.7.0, current version 4.7.4)
    @rpath/QtGui.framework/Versions/4/QtGui (compatibility version 4.7.0, current version 4.7.4)
    @rpath/QtWebKit.framework/Versions/4/QtWebKit (compatibility version 4.7.0, current version 4.7.4)
    @rpath/QtNetwork.framework/Versions/4/QtNetwork (compatibility version 4.7.0, current version 4.7.4)

    ...

    I don't know of a single one because Qt's support for XCode is incredibly poor.

    Do you have to use Xcode, the IDE, to develop OS X apps? Or by "Xcode" do you mean "Xcode the IDE, plus the command-line tools"?

  15. If you care about Windows Phone or Windows RT by tepples · · Score: 4, Informative

    It doesn't use Metro's libraries.

    Anything that doesn't use the Windows Runtime API (what you call "Metro's libraries") will not be approved for the Windows Store and will not run on Windows RT tablets or Windows Phone 8 smartphones.

  16. Windows Phone and RT do not require C# by tepples · · Score: 5, Informative

    I was under impression that all new windows "apps" had to be written in C# against a new SDK that has neither binary nor source compatibility with Win32/posix/C/C++. I'd be glad to be wrong, but that's what I've seen so far.

    Only Windows Phone 7 and Xbox Live Indie Games required C#.* C++ works on Windows Phone 8 and Windows RT, though they do require use of the Windows Runtime API. For actual Windows on x86, you can continue developing desktop applications without having to deal with Windows Runtime (the "Metro" crap).

    * In theory, they required verifiably type-safe CIL compatible with the .NET Compact Framework. In practice, they required C#, as standard C++ is not verifiably type-safe, and DLR languages require functionality not in .NET CF.

  17. Compatibility is no problem, before or after swift by perpenso · · Score: 5, Informative

    Good bye source compatibility. We hardly knew ye.

    I have absolutely no compatibility problems. I strictly use objective-c for only user interface code. The core functional application code is written in c/c++. I have multiple iOS/Android apps whose core code is shared and can even be compiled with a console app under Mac OS X or Linux, I use this for regression testing and fuzzing. A headless Linux box in the closet exercises this core code. Similar story for Mac OS X and Windows.

    Swift code can replace objective-c code and it matters little to me. Has zero impact on other platforms I target.

    Admittedly I've ported other people's code between Windows, Mac and Linux for years and written my own code for Windows, Mac and Linux for years and as a result I am extremely aggressive about separating UI code from functional code.

    For those people using some sort of cross-platform wrapper for their project, if it supports Mac OS X objective-c it will probably support Swift. Even if it takes time for the wrapper developers so what, the use of Swift is entirely optional.

  18. Viva Eco by fulldecent · · Score: 4, Insightful

    Ok, so now you'll be developing software using Apple's frameworks and Apple's language to run on Apple's runtime, after passing Apple's compiler (i.e. LLVM) for download using Apple's store (after finding your product with Apple's iAD) directly onto Apple's products built with Apple's custom processors, after you register as an Apple Developer. If your app needs to do something outside this environment, you can use said APIs now to reach out to Apple's Could and Apple's Database servers. And if your app is really successful as measured by Apple Crash Reporting and Apple Usage statistics or Apple's iTunes Connect, then they'll just straight out fucking copy you.

    Something about the new "language" is what makes that summary start sounding ridiculous.

    --

    -- I was raised on the command line, bitch

  19. Bjarne Stroustrup by phantomfive · · Score: 4, Interesting

    Bjarne Stroustrup once gave some ideas on what requirement should be met before he would consider designing a new programming language. This was his list:

    * What problem would the new language solve?
    * Who would it solve problems for?
    * What dramatically new could be provided (compared to every existing language)?
    * Could the new language be effectively deployed (n a world with many well-supported languages)?
    * Would designing a new language simply be a pleasant distraction from the hard work of helping people build better real-world tools and systems?

    Apple can definitely deploy the new language effectively, but I'm not sure it solves any problems.

    --
    "First they came for the slanderers and i said nothing."
  20. Re:Since when does Qt "work" with OS X? by R3d+M3rcury · · Score: 5, Insightful

    There are plenty of apps that use QT--probably the most mainstream one is Google Earth.

    Now, look at me with a straight face and say, "And Google Earth has a great UI!"

    To me, this is the problem with cross-platform UI. It starts from a mistaken premise: Windows and Mac or iOS and Android have the same basic UI. There's even a grain of truth to it. But it doesn't really work.

    The example I love to use is French and English. They are, basically, the same language, right? They both have words, sentences, and paragraphs. They both have nouns, verbs, and adjectives. So if you just translate the words and move around the adjectives, you've got a French/English translator! It's that simple!

    No, not really. If it's 100 degrees outside and you've just come from the outside and remark to a pretty girl "Je suis chaud" (literally, I am hot), she might very well slap your face. Because you've just said that you are hot as in, "Oh, baby, you make me so hot."

    And those are the silly mistakes that cross-platform UIs make.

    Take a simple one from Mac versus Windows: On the Mac, in a dialog box, the default button is always the right-most button. So you have a dialog box that says, "Are you sure you want to do this?" and the right-most button would say, "OK" and the button to the left of it would say, "Cancel." On Windows, the default "OK" button would be on the left with the "Cancel" button the right of it.

    Alignment, again, is a question. I'm not sure there's a standard on Windows--I've seen things centered and I've seen them aligned right. On Mac OS X, there's a standard. Which means when Windows aligns them on the right like on the Mac, I'm always pressing the Cancel button.

    So, yeah, you can use QT to have a cross platform application and it will work fine. And it's great, if you have an application like Google Earth, which has lots of great GIS capabilities so that the result is worth the pain. But, frankly, if Microsoft did an equivalent to Google Earth but made a Mac application that was "correct," I'd use it in a heartbeat. Because, all else being equal, I'd rather have an application that "speaks my language" to one that only sort of does.

    Have you ever spoken to a tech support person from another country with a thick accent? That's the equivalent of using Google Earth on a Mac.

  21. Re:Compatibility is no problem, before or after sw by perpenso · · Score: 4, Informative

    Here is a Mac OS X GUI app with a window and a button implemented in objective-c (main.h, AppDelegate.h and AppDelegate.m). The button handler calls C code (Work.h and Work.c) to do some work. Note that if C++ code had been used then AppDelegate.m would have been renamed to .mm so that Xcode would compile it as Objective-C++, necessary to link properly against the C++ code it uses.

    //  main.m
    #import <Cocoa/Cocoa.h>
    int main(int argc, const char * argv[]){
        return NSApplicationMain(argc, argv);
    }

    //  AppDelegate.h
    #import <Cocoa/Cocoa.h>
    @interface AppDelegate : NSObject <NSApplicationDelegate>
    @property (assign) IBOutlet NSWindow *window;
    @end

    //  AppDelegate.m
    #import "AppDelegate.h"
    #include "Work.h"
    @implementation AppDelegate
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    }
    - (IBAction)buttonPressed:(id)sender {
        some_work();
    }
    @end

    //  Work.h
    void some_work(void);

    //  Work.c
    #include <stdio.h>
    #include "Work.h"
    void some_work(void) {
        FILE *fp = fopen("/tmp/work.txt", "w");
        if (fp != NULL) {
            fprintf(fp, "Hello World\n");
            fclose(fp);
        }
    }

  22. Re:Since when does Qt "work" with OS X? by Carewolf · · Score: 4, Informative

    Take a simple one from Mac versus Windows: On the Mac, in a dialog box, the default button is always the right-most button. So you have a dialog box that says, "Are you sure you want to do this?" and the right-most button would say, "OK" and the button to the left of it would say, "Cancel." On Windows, the default "OK" button would be on the left with the "Cancel" button the right of it.

    Oh, stop trolling. You have obviously never used Qt, it will automatically fix the order of the dialog buttons for you. You can even launch the same application under GNOME and get one order, and under KDE and get another. It is controlled by the widget-style it uses. And it does more than that, it also matches the reading direction of the language you are using so that it reverses for Hebrew, Arabic or other right-to-left languages.

    There are things that you need to handle yourself in a crossplatform application, but that is not one of them.

  23. In related news... by surfcow · · Score: 4, Funny

    ... HR departments began advertising for programmers with 3+ years of Swift programming experience.