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.

55 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 Frosty+Piss · · Score: 3, Insightful

      Qt does not (and cannot) support Windows "Metro"

      "Windows Metro" is dead, irrelevant to this discussion. QT will continue to be available for Apple's little garden. Your comment constitues "fear mongering".

      --
      If you want news from today, you have to come back tomorrow.
    9. Re:Good bye source compatibility by StikyPad · · Score: 3, Informative

      Whatever source compatibility existed before Swift (and the degree to which that exists is surely debatable), it was not removed by Swift. Objective-C, C/C++, and Swift can coexist in the same project. I believe they can even coexist inline, which makes me shudder to think, but there it is. Still, you could ostensibly have a UI in Swift and your core business logic in C, if your architecture is solid. (Obviously YMMV, and there are bugs to be discovered, to be sure.)

    10. Re:Good bye source compatibility by ugen · · Score: 3, Insightful

      That's not what cross-platform compatibility implies. Placement of specific elements and their view is a subject of "themes" and is readily customizable.
      As a developer I care about underlying primitives - things like "windows", "buttons", "menus" or more generically "events", "inputs" etc. Once those underlying things can no longer be shared - you have to write a new product from scratch for every platform.

      Think of something like Adobe Photoshop (I assume as a UX person you are using it?). It is possible to have a version for Windows, and one for Mac precisely because you have those common underlying primitives and APIs, even though they don't necessarily look the same in all respects.

      If commonality of platforms is gone - even a company like Adobe will have really hard time building products for both platforms. That will eventually affect users too, since they will likely have to select different (and no longer compatible) products for each platform as well. For now that's not the case - but given where things go, it probably will be.

    11. 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.

    12. Re:Good bye source compatibility by R3d+M3rcury · · Score: 3, Insightful

      It's a good point.

      Consider the menu bar. It's a pretty handy place for commands. On the Mac, it sits at the top of the screen. On Windows, it sits along the top of your window. Now if we consider Fitts' Law for a moment and compare Mac and Windows, the menu bar is much easier to access on the Mac than it is on Windows because it's sitting at the top of the screen.

      So, putting things that people access somewhat frequently into a menu item on the menu bar isn't a horrible thing on the Mac. But on Windows--because the menu bar is harder to access--it will frustrate your users. You probably want to set up some kind of contextual menu on Windows.

      Do it the Mac way, you've annoyed your Windows users. Do it the Windows way and you confuse your Mac users (who are used to searching the menu bar to find things). Or devote the time and effort to doing it both ways.

    13. 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!

    14. 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)
                      });
              });

    15. Re:Good bye source compatibility by phantomfive · · Score: 3, Funny

      I believe they can even coexist inline, which makes me shudder to think, but there it is.

      If that makes you shudder, then this will terrify you. It compiles in eight different languages.

      --
      "First they came for the slanderers and i said nothing."
  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.

    1. Re:Who designed this, and what drugs were they on? by mbkennel · · Score: 3, Interesting


      That is bizarre. So if you see a function signature which takes an array as a parameter, you either do know that elements will be changed, or will not be changed---but only depending on potentially hidden implementation of that function?

      And which things have the 'potential to modify' the length of an array? Implementation defined?

      Fortran 90+ had it right. You just say for each argument whether the intent is data to go 'in' (can't change it), 'out' (set by implementation), or 'inout', values go in, and may be modified.

    2. Re:Who designed this, and what drugs were they on? by shutdown+-p+now · · Score: 3, Informative

      And which things have the 'potential to modify' the length of an array? Implementation defined?

      It's defined by the operations on the array. Basically, appending, inserting or removing an element would do that, but subscript-assigning to an element or a range will not.

      Fortran 90+ had it right. You just say for each argument whether the intent is data to go 'in' (can't change it), 'out' (set by implementation), or 'inout', values go in, and may be modified.

      Funnily enough, they do actually have in/out/inout parameters in the language.

      Note however that the story for arrays here does not apply only to parameters. It's also the behavior if you alias the array by e.g. assigning it to a different variable. So it's not fully covered by parameter passing qualifiers.

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

      You completely miss the point.

      Regarding immutability, it's not about an array of constants. It's about an immutable array - as in, an array which has its content defined once, and not changed afterwards. They actually do use the term "immutable" for this, and this is what it means in any other language. It's also what it means in Swift - for example, an immutable dictionary cannot be mutated at all, neither by adding or removing elements to it, nor by changing a value associated with some existing key. The only special type here is array, for which immutability is effectively redefined to mean "immutable length, mutable contents" - which is a very weird and counter-intuitive definition when the word "immutable" is involved (e.g. in Java you also can change elements of an array but cannot add new ones - but this is the rule for all arrays in Java, and it doesn't call that "immutable"). The fact that there's no way to have a truly immutable array is just icing on the cake.

      And they don't pass collections by reference. They say that value types are passed by value (duh), and that both dictionaries and arrays are value types (unusual, but ok). But then they completely redefine what copying an array means, with a very strange copy-on-write semantics whereby they do implicitly copy them if you touch them "in the wrong way" (e.g. by appending an element), but not if you touch them in the "right way" (e.g. by mutating an existing element). Again, this magic is utterly specific to arrays - for dictionaries, they behave like true value types at all type, and use full-fledged copy-on-write under the hood to avoid unnecessary copies - so if you "touch" a dictionary in a way that mutates it, it makes a copy, and it doesn't matter how you do so - by inserting a new key-value pair or by changing a value for an existing key. Not only this is very much non-orthogonal (why make copying of arrays and dictionaries so different?), the behavior that's defined for arrays just doesn't make any sense in distinguishing between various ways to mutate them.

  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.

    1. Re:Swift Programmers Wanted by HornWumpus · · Score: 3, Funny

      Good news; I've got over 20 years experience. (bullshitting my way into positions with languages I don't know. Then learning fast.)

      Guaranteed results...'I can guarantee anything you want.' Bender

      --
      John McAfee 'It was like that time I hired that Bangkok prostitute; to do my taxes, while I fucked my accountant'
  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. Re:New bells and whistles by angel'o'sphere · · Score: 3, Interesting

    Depends on the language.
    In groovy closures are perfectly readable, as they are in Smalltalk.
    Problem is that closures are often considered second class citizens, hence they get plugged in later nad then they look wiered.

    --
    Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  9. 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.
  10. Re:Yet another C variant? by Shag · · Score: 3, Informative

    They've already got LLVM and Clang, no? Or did you mean better than those?

    --
    Village idiot in some extremely smart villages.
  11. Designed for safety & performance by bradrum · · Score: 3, Interesting

    I find these two aspects interesting and wonder what the trade off is. Longer compiler times?

    "Designed for Safety
    Swift eliminates entire classes of unsafe code. Variables are always initialized before use, arrays and integers are checked for overflow, and memory is managed automatically. Syntax is tuned to make it easy to define your intent — for example, simple three-character keywords define a variable (var) or constant (let)."

    " Swift code is transformed into optimized native code, "

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

    *that poorly.

  13. 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

  14. Re:None of the baggage of C? by Anonymous Coward · · Score: 3, Informative

    Yes, Swift itself does not have the baggage of C just like Python does not have the baggage of C. The fact that both languages can interoperate with C does not change that.

  15. 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

  16. Colour me skeptical... by ChunderDownunder · · Score: 3, Insightful

    Apple had a fine language 20 years ago. It was said to influence the design of Ruby and Python. They butchered it into an Algol-like syntax because 'real programmers' can't grok s-expressions. Then they abandoned Dylan.

    Next, they created a language for mobile devices. Its programming model was said influence the design of JavaScript. Then they abandoned NewtonScript.

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

    ... a badly implemented subset of C++

    You mean like C++?

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

    Oooh, sorry. We're only looking for candidates with at least 5 years of experience with Swift.

  19. 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

  20. 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"?

  21. Re:Since when does Qt "work" with OS X? by angel'o'sphere · · Score: 3, Insightful

    Then compile your code with Eclipse or from the command line.
    What has XCode to do with developing Qt?

    --
    Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  22. Clearly his team needs it. Don't question why. by Anonymous Coward · · Score: 3, Insightful

    My god, it's like I'm at Stack Overflow, reading the typical stupid and cocky "WHY ARE YOU DOING IT THAT WAY?!?#?!?@?!@?!?" responses that are so prevalent over there.

    His team probably has its reasons for using or requiring GDB. And you know what? They're probably pretty damn legitimate reasons, too.

    I'm sure they know about LLDB. But it's probably not what they need, and thus they do not use it.

    If they need GDB, then that's what they need. It's that simple.

    What we don't need is somebody like you questioning the validity of their very real need.

    1. Re:Clearly his team needs it. Don't question why. by Anonymous Coward · · Score: 3, Informative

      So then install GDB. There is no reason to stop supporting Mavericks because it doesn't come with GDB preinstalled.

  23. Re:It's about time by scheme · · Score: 3, Insightful

    Wow, I happen to meet that requirement. I've been using SWIFT for quite a few years and have done image processing and molecular docking workflows in it./p.

    --
    "When you sit with a nice girl for two hours, it seems like two minutes. When you sit on a hot stove for two minutes, it
  24. 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.

  25. 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.

  26. 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.

  27. 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

  28. Re:Somebody post a SWIFT example PLEASE! by maccodemonkey · · Score: 3, Insightful

    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.

    To be honest, while this snippet is a few lines shorter, it's arguably more complicated than the corresponding Obj-C. It drops returning self in the init, and drops a few lines that would have had to go in to the class definition, but you gain a few unsightly keywords like "override", having to add the keyword "func" to every function, and you gain some more syntactical mess like "->".

    It's not horrible, but I'm not sure this sample is more readable than Obj-C. As others have noted, Swift has the habit of taking the important parts of a function (like what it's named and what it returns, or what name a class is and what it subclasses) and shoving them off to entirely different sides of the function declaration.

  29. 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."
  30. 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.

  31. 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);
        }
    }

  32. 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.

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

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