Hacker News new | past | comments | ask | show | jobs | submit login
Silver: A free implementation of Swift for .NET, Java, Android, and Cocoa (elementscompiler.com)
249 points by milen on Feb 9, 2015 | hide | past | favorite | 104 comments



I'm curious to know how well it performs. I spent the better part of this weekend rewriting 4k lines of Swift in Objective-C because I couldn't deal with the 60-90 second compile times.


Swift has some land mine issues where the compiler can hit snags handling certain snippets of code (e.g casting to/from Any/AnyObject, method overloading based on constraints, etc) which if you have enough of them will segfault the compiler with something along the lines of "expression too complicated, break it down".

I've had to rewrite my approach a few times because of this to avoid certain coding techniques, but once I've rewritten to avoid them, Swift can happily compile my 7-8k LOC code-base in ~6s.


Is there a list somewhere of Swift compiler issues to avoid? Seems like "avoiding certain coding techniques" is what is currently necessary until Apple gets back on top of things...

One other example FWIW: having a largish array of Int arrays causes the compiler to either go into an endless loop or simply take too long, UNLESS the type of the array is specified.

var data = [[1,2,3],[4,5,6], ... ] // > 20 elements -> compiler hangs

as opposed to:

var data:[[Int]] = [[1,2,3],[4,5,6], ... ] // compiles quickly


Finding Swift really buggy atm - where XCode, Swift Compiler and SourceCode service routinely crashes multiple times a day for me. A lot of my time is spent sympathizing with the compiler and getting hit with hard fought lessons on what things to avoid - basically don't step too far outside the Swift Programming Guide. Apple's also glacially slow at responding to bug reports - I'm keenly waiting on the next Q/A release of XCode/Swift.

There's a whole repo dedicated to Swift compiler crashes being maintained at: https://github.com/practicalswift/swift-compiler-crashes


If only this had been a language that was dogfooded to the rest of the company, we might not be dealing with these beta-like issues.


I think it was - the first app written in Swift was Apple's WWDC app. Released before they announced Swift. Though it wasn't a hugely complex app.


Dogfooding usually implies that the technology is used in mainline business operations. It needs to be more than building a demo, it needs to provide sustenance.


This isn't strictly true, if you not the wording around this it is quite cautious, "written with swift". There are only 4 swift objects in the app.


I don't think I'm doing anything too fancy, but who knows? I probably have too many conversions to Objective-C objects that I used to workaround beta compiler issues that are probably fixed by now, but I haven't found a lot of guidance on what to avoid (I'm declaring types pretty much everywhere) and since the compiler isn't crashing, the list of compiler crashes doesn't really help.

It's a shame because Swift is a neat language. But because Xcode doesn't support incremental compilation for Swift, a single character change causes the entire project to rebuild. Couple that with LLDB crashing because I'm including Objective-C frameworks (via Cocoapods), and the whole experience becomes absolutely terrible.


Are you saying you are OK with compiler performance affecting the design (and possibly quality) of your code??


Nobody says you have to OK with something you mitigated against.

I remember on several occasions fighting Visual C++ over code it bombed out on. Having a precompiled header scheme to make up for poor performance. Yes it sucks, but you don't do these things because you think it's acceptable, it's because the alternative is more painful.


And of course, Apple just seeded an Xcode beta that supports incremental builds.


So, the Swift compiler is slow? I mean, I expected it to be slower than Objective-C due to its dynamic nature, but that slow?

Disclosure: I write Android apps, so I'm only occasionally peeking at how the iOS dev scene is developing. I've already been thinking of trying to write Android apps in Scala, but maybe this Swift to Java compiler is also worth looking at


From what I known, Kotlin or Xtend are better options than Scala, regarding execution speed of the current code generation and package size, even with ProGuard.


No, not really.


Any available benchmarks?


Considering this downvoting-because-I-don't-like-being-wrong ... maybe just benchmark it yourself.

If you have time for making stuff up and downvoting, then you surely have time to run some benchmarks.


Apple only just today released an update to the compiler that enabled incremental builds. Before that it had to recompile everything every time. That alone will probably make a big difference.


Reading through the details dampened my excitement. It has proprietary extensions to the Swift language (http://docs.elementscompiler.com/Silver/LanguageExtensions/) and it has differences and limitations as well. (http://docs.elementscompiler.com/Silver/DifferencesAndLimita...).

They do however state it is free for use.


I don't have time to look, but when I signed up, I was given the option for a free trial and the option to spend $500+ depending on the package. I'll have to look closer, but I suspect this is xaraminesque.


The Swift part of it is free. The C# and Oxygene parts cost, which aren't needed to develop in Swift.


It's understandable that they require a few extensions, for concepts from other environments. Some of the limitations are unfortunate, though.

"Patterns are not supported in Switch cases, yet"

:(


"yet". and actually implemented for the next Beta drop.


Ah, great!


Looks pretty shady. Proprietary code through-and-through, and it's "cross platform" because it compiles down to their own proprietary language. It's unclear how you deal with native libraries, if at all.

I'll pass, thanks.


Proprietary code, completely unlike the Swift frontend.


Not only that, but good luck keeping up with Apple's developments once they start buckling down and updating the language.


We have a long history of doing more than "keeping up" ;)


I know this guys from long time. Their RemObjects/DataAbstract is IMHO the best remoting framework ever done (I have use Delphi, .NET, Python, Obj-C, VisualFoxPro and test several frameworks for that).

They are supporting their implementation of Pascal for several years now, and my experience of using DataAbstract from obj-c show the interfacing is good.


Cool! But, is it possible that this violates Apple's TOS or any legal limitation on use of the Swift language? I remember there being a lot of heated discussion about making Swift officially open source back when it was announced, but I don't recall ever hearing anyone suggest a community project to make an OSS compiler for it. This is most interesting, but I'd love to know that Apple would be okay with this, or would have no recourse to shut it down, prior to putting in the time to pick it up.


The problem is not whether it is legal to use Swift in a 3rd party environment, but the lack of support in the 3rd party eco-system per se means the attempt would vanish, in time.

I believe most of us who actually use Objective-C choose it not because the language itself is designed to be simple and elegant, (and yes the language is simple and elegant,) but because the Cocoa and Cocoa-Touch are well supported by Apple. No offence to the effort outside of APPL, but it is not enough to support a full-fledged eco-system with all 3rd-party F/OSS written in Objective-C that is compatible with what Apple currently uses in order to build reusable components. GNUStep has existed for so many years, and Étoilé for years as well, but I did not see emergence of adoption in community comparable to that of other popular F/OSS frameworks, e.g. Mono and Qt. And I do not see how this issue could be circumvented, unless some big player shows up and adopt any of these projects, like what Google did to Android.


Programming languages cannot be copyrighted. It doesn't look like they've reimplemented any Apple APIs, so there wouldn't appear to be any room for an Oracle-style lawsuit claiming that standard library code was copied.

I don't know what the trademark situation might be, though.


> Programming languages cannot be copyrighted

Are you sure? I'm genuinely curious to see a reference/precedent. Also, does that restrict patentability of programming language features? (I personally can see PLs not being copyrightable, but being patentable.)


For Europe, there's http://en.wikipedia.org/wiki/SAS_Institute_Inc_v_World_Progr....

There's not really any case law I'm aware of in the US, mostly because nobody's ever tried. Copyright doesn't cover "facts, ideas, systems, or methods of operation". You can trademark the name of a language, and its documentation and any distributed software are under copyright, but the process required to translate that language into machine code isn't eligible for copyright.

Parts of the implementation might be patentable, but I don't know of any cases of anyone successfully patenting a programming language.

The Oracle vs. Google lawsuit is still going back and forth in the courts. It's worth noting that even Oracle isn't claiming that the parts of Android that involve parsing and compiling Java code are infringing on their copyright. The matter of controversy is that they claim copyright on the design of the Java standard library.

Swift's standard library is pretty much Cocoa, which isn't being rewritten here.



They should make it 100% free for students. Once they graduate and enter the workforce they will recommend this tool to employers.


I believe it's free for everyone.

> RemObjects Silver is absolutely free of charge to use, both during the current beta period, and once we release the shipping version.


Silver itself might be free, but I think only if you bought the compiler already,

http://elementscompiler.com/elements/pricing.aspx


> Silver itself might be free, but I think only if you bought the compiler already,

so it isn't free software at all.


We make three compilers. Oxygene, C# and Swift. The Swift compiler is/will be completely free use for everybody — no purchase required.


That's for the C# and Oxygene (Pascal) frontends. The Swift part of it is free.


Genuinely curious.

Why Swift for multi-platform rather than C#, Clojure, JavaScript, or <insert other language here>?


Swift is statically typed, so it doesn't really compete with JS or Clojure. The company already has a C# implementation for sale.

Also, Swift was designed to compile to native code, unlike any of the other three languages.


> Swift is statically typed, so it doesn't really compete with JS or Clojure.

This seems to imply that developers make a static vs. dynamic choice separately prior to and separate from evaluating other aspects of languages to choose between them. While some developers may do that all the time, and some may do that some of the time, I don't think its true as a generalization.

Certainly Go is statically-typed, and often portrayed as competing fairly directly with Ruby/Python, which are not.


.NET has NGEN since 1.0.


And .NET code _does_ compile to native code even without NGEN - it just does it 'Just In Time'. It's pretty close to native code just before that step, so the actual native compilation is very fast.


Sorry, I was imprecise.

Swift was designed for the iOS platform as a replacement for Apple's dialect of Objective C. This is an unmanaged environment. There's no VM or garbage collection, although both languages support automatic reference counting.

C# was designed for the CLR and has a large standard library that relies on garbage collection. It also has features permitting calls into unmanaged code, but the language was still designed for a VM.


Except there isn't any VM when the code is AOT compiled to native code with NGEN, MDIL in Windows Phone 8, .NET Native, or in iOS.

The presence of garbage collection has nothing to do with being native or not.

Besides a language runtime and VM aren't the same thing.

Actually Swift makes use of Objective-C runtime to achieve interoperability with Objective-C libraries.

Oberon, Oberon-2, Modula-3, Component Pascal, D, Spec#, Dafny are all examples of languages that compile to native code, were used to write operating systems and use garbage collection.


You can surprisingly effectively cross-compile C and C++ to Javascript now, with Emscripten.


The point is to AOT compile to native code.



When talking about AOT compilation, we generally tend to mean that the compiler produces a binary consisting of machine code at some unspecified time before the user attempts to run the application.

In the context of that blog post, there are two compilation steps: First emscripten would be used to produce JS. Then Mozilla's JS engine would compile that JS down to machine code at runtime.

They call the latter step with OdinMonkey AOT when they compile the entire thing at runtime, but before starting execution. But the way most people differentiate, this would still be considered JIT - it still depends on executing the compiler each time the application is started.


The point I was trying to get across is that by cross-compiling from C/C++ with Emscripten, static type information can be used to give native performance, that a program written directly in Javascript wouldn't. It's still AOT in that sense - it's not like JIT where only hot bits of code get converted to native to code, and only then when some heuristics have determined what actual types the code ends up dealing with at runtime.


But it isn't AOT in CS speak.


I'm not sure how you claim to be the authority on 'CS speak', but it's a sufficiently blurred line here, for reasons I clearly explained and which you seem unable to understand. Emscripten/asm.js can use static information to generate Javascript which can be compiled to native code, before the code in question is run, aka Ahead of Time.


Well, I majored in compiler design.

Ahead of time compilation is used to describe the process of generating machine code at compilation time, in a form that can be executed directly by a processor without any additional transformation process.

Which clearly is not happening here, as the code is converted into JavaScript and relies on a JavaScript implementation to run. Regardless of the optimization processes used by the JavaScript engine.


The nuances unfortunately appear to escape you.


I wasn't aware there was a CPU that could run that code natively without a JIT translation layer.


There isn't, perhaps you're getting confused again.


I understand that Apple built Swift to compile to native code, but I thought the allure of this product was running on the JVM and .NET runtimes.

I guess I should clarify that I get why using Swift for OSX and iOS might make sense. The question is about using it for other platforms.


Mono supports ahead-of-time compiling to native code. I'm pretty that's used on iPhone.


Anyone interested in building open source parser API for Swift? Join me here

http://compilerjobs.com/db/jobs_view.php?editid1=984

If parser API succeeds, we will also target making a compiler.


What are the legalities?


Swift is just a language specification. It cannot be patented or copyright-ed. Anyone is free to make tools around the language specification. Just like there are many compilers for C/C++ on different platforms, we intend to make one for Swift on Linux/Windows.


The fact that arrays and dictionaries are classes rather than structs is a major problem with this. That's a massive semantic difference between their implementation and Apple's, and it's one that won't show up as a compile-time error. Taking code written for Apple's implementation and using it on Silver is likely to result in a nightmare of crazy debugging trying to track down all the cases where you're now sharing arrays/dictionaries rather than copying them. This really needs to be fixed, and if it's truly impossible, IMO it's bad enough that the thing should be scrapped.


This looks interesting, although adding language extensions makes me a bit nervous. What's the ABI compatibility story when targeting Cocoa? Can I mix and match with native Swift classes? Is the native Swift runtime used?


The language extensions are there to support concepts that don't exist in Swift, for example await and exception handling are pretty much a requirement when targetting .NET and Java/Android.

It's ABI compatible with Cocoa, all classes end up usable from Cocoa.

It does not use the swift runtime.


I just want to write web apps in Swift. Any news on that front?


So much this. It'd be an excellent alternative to Go, with it's nice type system and pretty advanced PL features: I'd love to write web services in Swift, but that's contingent on being able to deploy it to Linux et al.


Maybe you should check out OCaml then. It can be deployed to Linux/Windows/Mac OS X without problems, ARM devices. Offers native compilation and can even be compiled to JavaScript. The compiler is fast and freely available.

The type systems is even better and more advanced. Coming from Swift I was kinda surprised that its pattern matching was a statement and not an expression, as typical functional languages do.


The state of OCaml documentation is not great... I have had such a pain finding documentation. Generally, the only source for it is the French university that created/promotes it [0]. But even their pages are often almost a decade old and I have frequently found errors in the documentation.

Overall, while OCaml is a truly beautiful language (and I do really enjoy writing in it[1]), it is really tough to get work done efficiently because so few resources seem to exist.

With that said, I discovered a mod_ocaml Apache module implementation[2] (that is really outdated and not very efficient) and moved it to github. (I am not the author, nor have I had time to work on it either.) But if there was any interest in reviving this, I'd certainly give it a go. This seems to be a potentially viable way to increase interest in server-side OCaml usage.

[0] http://caml.inria.fr/resources/doc/index.en.html

[1] https://github.com/eatonphil/owebl

[2] https://github.com/eatonphil/mod_ocaml


> The state of OCaml documentation is not great... I have had such a pain finding documentation. Generally, the only source for it is the French university that created/promotes it.

That might have been true 5 years ago, but the OCaml Community site [0] is rather easy to find and links to many tutorials and books. Among these is the excellent Real World OCaml [1] book which is pretty great for experienced developers switching languages and available in print and freely online. Other resources for more beginning programmers exist as well. The INRIA resources are, indeed, rather poor and except fro the language reference, rather outdated.

Directly programming for Apache hasn't been popular for years now in any language I know (actually, only mod_php is popular, if at all, mod_python is completely dead and no idea about mod_perl). Usually languages have their own servers that get reverse-proxied by a frontend server like Apache or Nginx. And for this purpose Ocsigen [2] has been available (allowing an front-and-backend OCaml approach). If something simpler is desired, CoHTTP [3] exists, which is both a HTTP client and server. Reviving mod_ocaml is, in my opinion a waste of time and effort.

[0] http://ocaml.org/

[1] https://realworldocaml.org/

[2] http://ocsigen.org/

[3] https://github.com/mirage/ocaml-cohttp


Great points. I was being too vague. My biggest gripe was that I could only learn more of the syntax from the INRIA documentation. The books and OCaml websites definitely covered a lot of general programming recipes and more common paradigms. Ultimately since there were still so few examples I always ended up having to look at the actual language reference for useful information. As we're aware though, it is outdated. In particular, I found really getting a handle on object-oriented OCaml was tough. Probably just because other aspects of OCaml could be guessed/inferred from SML/*ML documentation.

My comments on mod_ocaml were also a little vague. When I began server-side programming I loved mod_php because of how simple it was. I only brought up mod_ocaml because (if it worked) it is probably the single easiest way to start writing ocaml web pages. Given, it is absolutely not performant whatsoever. I just kinda saw it as a gateway from hobbyist-level interest.

Thanks for all your resources though!


I started working on a Swift web framework this summer, but I abandoned it because the language kept changing too fast for me to keep up. If I get some free time, I'll pick it up again.


Well if this compiler works as advertised, you should be able to use Java / .NET libraries for web applications.


You can use it with ASP.NET, JSP and whatnot, correct.


So does it mean I can finally develop apps in Swift language on Windows? Very cool!


I hope this doesn't come across as rude, but I can't tell from the site: will this be "free" as in open source or "free" as in freeware?


This appears to be another language frontend for their existing proprietary compiler.


"Anyways" is not standard, might want to change that on the landing page.

I would have just pinged privately but I don't see any contact link on the page.


Why not create a Swift Compiler and Toolchain for LLVM?


The official swift compiler is already LLVM/Clang based.


Actually it's possible this compiler uses LLVM under the hood - many compilers do these days.

This particular one appears to not be open source, though.


So, is the Java version now a JVM language, like Scala and Groovy? Can I use it in IntelliJ or do I have to use this IDE they made?


> is the Java version now a JVM language, like Scala and Groovy

I guess so, ditto with .net and android -- that's what happens when a programming language creator, here Apple, specs out a language at the same time they implement it. Could be why Swift is getting many implementations whereas a language only paying lip service to the idea of a spec, say Groovy after Dec 1995, is still stuck on one impl.


Make a cross plattform game framework to this - as good as SpriteKit and I'm set. :)

Otherwise I have to go with HaXe


Actually I am really of the opposite opinion! Since I am not interested in developing games but rather in cross-platform support I think that Silver is what Haxe should have been!


We're not of the opposite opinion then ;-) I think Silver is also what HaXe should have been!


These folks started out with a product to integrate Delphi with .Net.


A closed-source compiler? In 2015?


People who want to make a living writing software? in 2015? I know, the idea seems quaint.


[deleted]


Apples? I prefer oranges.


It's not open source.


Apple needs to buy this company in 3, 2, 1... This is an ideal start to countering the concepts from Xamarin out of the .net camp and I would love to see them build up some form of XAML-like UI tech and tooling for x-plat UI dev so you could push the envelope on code-reuse. That would take a big dump of capital.

It would also make for a push in the market for this style of x-plat dev. If you can get to the major and minor platforms with one code-base and a single-stack dev team, oh what a smooth world it could be.

Windows 10 on all devices, written in Swift to a universal in visual studio. Wonder if I'd get to see a macbook running windows with a dev writing swift in VS.


Why not just write your app using F# w/Xamarin. Target iOS, Android, Windows Phone using a decent functional language.


What possible reason would Apple have to buy this company?


Indeed, Swift is their way to keep developers building non-portable apps.


Buy it to kill it.


Swift developers, building across platforms, can get their Apple-loving code into enterprises through the front door so Apple hardware can start coming through that way as well. Push the Apple brand via programming language in order to sell more hardware.

Is the longview really that a closed platform with a narrowly used language will increase the share of revenue from Mac sales?

Swift + walled garden are OK for selling phones, but for OSX to go beyond <10% of PC marketshare, they could use a language to erode resistance to Macs in the biggest markets for PCs. Microsoft puts Office on the Mac. Now, you can also have business systems built on Swift that can work on shiny Mac hardware AND crusty Windows boxes.

You buy this company because they love Swift and can help get a foothold on dev teams in the enterprise. No matter how many kids come up using Swift to make their phone apps, they are going to get pushed into building C# and java, and a bunch of other languages, using other hardware and tools, when they joins the ranks. You buy this company so you can control the direction of their efforts and use it to put more eggs in other baskets.


I suspect if Apple wants Swift to target other platforms they'll use their own compiler.


Which reminds me, I just checked out Apportable's Foundation. It has come a long way since the earlier GNUstep-based one. Impressive!


Apple doesn't care about non-Apple platforms.


I don't think apple wants to push for cross platform development. Looking at the last decades I would sustain the opposite idea, they are trying to just build tools who can work only on their own ecosystem


I don't think Apple would like to support other platforms.




Consider applying for YC's first-ever Fall batch! Applications are open till Aug 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: