7 ms·
> the best of C# and Rust e.g.? I've only just scratched the surface of Rust and dismissed C# as a Java clone (but maybe I shouldn't have?). What's some exam
by wyldfire 11y ago
> the best of C# and Rust
e.g.? I've only just scratched the surface of Rust and dismissed C# as a Java clone (but maybe I shouldn't have?). What's some examples of the best of Swift that you see?
- chadzawistowski 11y agoOne case where C# is far superior to Java is generics. Generics were a cutting-edge feature in 2005. Microsoft took the opportunity to start from scratch, and released the .Net Framework 2.0 without backwards-compatibility, and with full support for generics. A List<String> is actually a List of String. When Sun released Java 5, they didn't want to disrupt the established Java ecosystem. Their implementation is called "type erasure". As an example, List<String> is actually just List<Object>, with automatic runtime typecasting to String. https://docs.oracle.com/javase/tutorial/java/generics/erasure.html https://docs.oracle.com/javase/tutorial/java/generics/erasur... Java's solution works well enough, but it breaks down in certain scenarios, such as multiple levels of generics. For example, when getting an element from a List<List<String>>, Object is not cast to List<String> (which doesn't really exist), but merely List. C#'s implementation of generics became even more sophisticated with C#4, which introduced covariance and contravariance. https://msdn.microsoft.com/en-us/library/ee207183.aspx https://msdn.microsoft.com/en-us/library/ee207183.aspx
- santaclaus 11y ago> Generics were a cutting-edge feature in 2005. Generics have been around since at least the early '80s.
- chadzawistowski 11y agoWell, "cutting-edge" in enterprise technology. Another interesting failed prototype on the JVM was the language "Pizza" https://en.wikipedia.org/wiki/Pizza_%28programming_language%29 https://en.wikipedia.org/wiki/Pizza_%28programming_language%...
- nostrademons 11y agoAda isn't enterprise technology? https://en.wikibooks.org/wiki/Ada_Programming/Generics https://en.wikibooks.org/wiki/Ada_Programming/Generics http://www.cs.dartmouth.edu/reports/TR86-104.pdf http://www.cs.dartmouth.edu/reports/TR86-104.pdf (From 1984.)
- lern_too_spel 11y agoWhen does it matter what an element from a List<List<String>> is cast to at runtime? In a properly-written statically-typed program, types are a compile-time construct (ignoring the machinery of dynamic linking and method call semantics in particular implementations, which don't matter to the programmer), and though you may use them at runtime via reflection, I would argue that 99% of the time that you do, you're writing bad code. http://stackoverflow.com/questions/20918650/what-are-the-benefits-of-javas-types-erasure http://stackoverflow.com/questions/20918650/what-are-the-ben...
- dkharrat 11y agoType erasure introduces limitations on what you can do at runtime that forces a developer to write code to workaround it. For example, in Java you can't write a generic method that instantiates an object based on the type of the generic. The workaround is typically to pass in the Class type as an additional parameter to the method, which in theory should not be necessary. A lot of JVM-based languages are required to introduce additional complexity in the language to simulate reified generics (e.g. Scala's Manifest/TypeTag classes).
- airless_bar 11y ago> A lot of JVM-based languages are required to introduce additional complexity in the language to simulate reified generics (e.g. Scala's Manifest/TypeTag classes). I'm not sure how this makes sense. These tags are just standard context bounds, which are extremely useful and quite awesome. You make it sound as if these tags were some kind of special feature added to the language, or context bounds were solely invented to support these tags.
- cakoose 11y ago> For example, in Java you can't write a generic method that instantiates an object based on the type of the generic. The workaround is typically to pass in the Class type as an additional parameter to the method, which in theory should not be necessary. If a method needs to instantiate an object, the normal technique is to accept a factory function as a parameter. You can do the same thing with type-erased generics. C# decided to create a shortcut for calling the constructor of a generic type parameter. But, for example, you can't call static methods of a generic type parameter (and a constructor is really just a slightly special static method).
- pjmlp 11y ago> Generics were a cutting-edge feature in 2005. I was already using C++ templates in 1994 with Borland C++ for Windows 3.1! Ada, CLU and ML go back to the late 70's / early 80's.
- raverbashing 11y agoYes, but I guess that code would break in a million ways today in a modern C++ compiler It certainly worked at the time, for that specific compiler
- pjmlp 11y agoIt was still a language feature even if it wasn't available 100% bug free in all C++ compilers. C code also used to break left and right long after C90 was approved. I had to use K&R C style code in 1999 because the HP-UX compiler at a customer location didn't knew any better, but that didn't mean other C features weren't available elsewhere.
- raverbashing 11y ago> I had to use K&R C style code in 1999 because the HP-UX compiler at a customer location didn't knew any better, but that didn't mean other C features weren't available elsewhere. Curious, what did you need to do specifically? Parameter declarations weren't inlined? But anyway, C, being smaller, breaks in fewer ways
- pjmlp 11y ago> Curious, what did you need to do specifically? Parameter declarations weren't inlined? In those days HP-UX C compiler was still transitioning between K&R and ANSI standards. We could only properly compile without strange errors while using K&R function declarations. If memory serves me right, it was the first HP-UX release having support for 64bit file systems.
- pkolaczk 11y agoTemplates are not proper generics. Templates can be used to emulate generics, but they are not the same thing at all. Templates are not first-class citizen of the type system (they don't survive to the typechecking phase), while generics are. You cannot write a generic list implementation in C++ and have it typechecked.
- pkolaczk 11y agoOne case where Java generics are far superior to C# (actually CLR) is implementing more advanced generics on top of JVM thanks to erasure. C# generics are too weak to express concepts found in Scala or Haskell type system directly, but at the same time too strong to serve as a base for a standalone implementation of such type systems.
- peripitea 11y agoHaving worked with both for several years, I would rate C# as a much better language than Java. The language by itself is noticeably better, but the difference is even more pronounced if you include the ecosystem -- Visual Studio vs. Java IDEs, the class libraries, ASP.NET MVC vs. Struts and its ilk. I would check it out if you have the need to do any Windows-related programming. (Not sure how great the support is outside Windows.)
- meddlepal 11y agoUh, when was the last time you worked with Java? Struts isn't a popular framework anymore and hasn't been for awhile. IntelliJ absolutely trounces VSS and some combination of Spring Boot, DropWizard or Vert.x blows ASP.NET MVC away. Not to mention the whole ecosystem is a hell of a lot more open. There is a library for just about anything under the sun.
- mhd 11y agoEnterprise environments tend to be very conservative when it comes to stuff they let you install or even use. Often you can't just drop JARs in there, never mind use your own JRE. So you're often stuck with technology that sites like these consider quite ancient… It gets even worse on desktops, as sysadmins might be able to isolate a server enough to allow some "new" tech, but vetting a new Java version or library for a few thousand office desktops is a task nobody really wants to do. So I wouldn't be surprised to still see some Java 1.4 Swing apps in use at big insurance or pharma companies. (And if I'd had to pick between that or do a web app that supports their IE8 browsers…)
- Recurecur 11y ago"Enterprise environments" also have to be very conservative about security issues - which often means they're forced to update to currently supported versions of software. Java 8 is the only version currently receiving security updates. The same thing applies to many other software packages, including browsers, Linux and Spring. Sane IA folks don't like to deploy known security holes. It sounds like you're dealing with some backwards-thinking folk. ;-)
- raverbashing 11y ago"and dismissed C# as a Java clone" It definitely looks like that, but I'll take C# over Java any day Java API looks like it was built by the worse bureaucrats they could find and one piece doesn't fit another except in a very specific (non-obvious) way
- AsyncAwait 11y agoSome of the things off the top of my head in no particular order; protocols, (closer to traits than interfaces), Optional types, (elsewhere no null types), pattern matching (if let, case let), guards, (so you can cover your preconditions nicely), immutable let bindings first, var variables second, (with mutability being tied to the binding outsite of reference types/classes), tuples, lazy evaluation, flexible closure syntax, fairly powerful type inference, enums as tagged unions, (or as standard C enums if you want), extensions - even for core structures if you need it - straighforward way to define custom or overload existing operators, type system powerful enough to be able to implement a fairly convincing Functor, Applicative or Monad without much effort, structs AND classes, most things are value types... But most importantly to me, Swift is composed in such a way that it just 'clicks' for me, ie many times many times I can guess how something is likely called or how it will behave without looking at the docs and I have a solid chance of being right - that 'intuitiveness' is something that is lacking in many other languages I've used over the years. In regards to C#, by now it is definitely not just a Java clone anymore, in particular saner type system and much more functional features edge it for me over Java, plus the speed of evolution is much greater in the C# land. If you want to see how C# and Java differ but are tied to the JVM, try Kotlin: http://kotlinlang.org http://kotlinlang.org - it's fairly similar in feel to C# and has 100% Java compatibility.