5 ms·
I have never used a strongly typed language. But it seems like it would be almost strictly superior to the php and ruby I use now. So why on earth isn't everyth
by sopooneo 11y ago
I have never used a strongly typed language. But it seems like it would be almost strictly superior to the php and ruby I use now. So why on earth isn't everything strongly typed? What's the downside?
- outworlder 11y agoNot many downsides, if implemented right. Problem is, most languages have very simplistic type systems, which get in your way, specially if you are trying to code a function that will operate with many different possible "types". Then they add kludges to make life bearable (see also: Generics), that will then add complexity. And are sometimes horribly implemented (see: Java's type erasure), or C++ compiler authors struggling with its template system (and users struggling to this day). Or sometimes they don't even add the kludges, making life tedious (see: Go, and endless discussions about adding generics to it) The other category of hacks is what's usually called "Reflection", or "Introspection". Any time a language designer feels necessary to add such a name for the ability to lookup things, then you know you are in a world of pain. The contortions required to by some languages to implement Ruby's 'respond_to?' method can get ridiculous. So much so, that the usual workaround is to add 'interfaces', which are a type(that does nothing useful), and so you can check the type. Or pass it around to something that will expect that over-arching type. Sometimes you just don't care about a thing's type. And, many times, the types that you should care about are not the ones that are actually specified. If I'm doing something important, I don't want the compiler to check if the type is integer, I want it to check if the type is, say, Miles, as opposed to Kilometers. That's what's important, or my costly space probe will literally crash. A language should make it easy to do so, otherwise people won't bother. Or probes will crash. Even though the program compiled. And the UML diagrams are spotless, with the factories all building the object types they were supposed to.
- deleted 11y ago[deleted]
- astrange 11y agoC/Java-type strong languages have the downside that they're super redundant. Typing "MyObject myObject = new MyObject();" is not fun in your free time. The same goes for any other required proof in your program, when you already know you're right. Hey, remember this guy? He used to be pretty famous, you know. https://sites.google.com/site/steveyegge2/is-weak-typing-strong-enough https://sites.google.com/site/steveyegge2/is-weak-typing-str... http://steve-yegge.blogspot.com/2008/05/dynamic-languages-strike-back.html http://steve-yegge.blogspot.com/2008/05/dynamic-languages-st...
- campers 11y agoKotlin on the JVM is a nice improvement over Java, still statically typed, the compiler infers the type for obj. var obj = MyObject() ... obj.foo() So you could change the obj instantiation to a different type and as long as the new type has foo() too then you're good to go. Also you can have your typed properties stored in a map, which you could also add other values to dynamically at runtime. from https://kotlinlang.org/docs/reference/delegated-properties.html https://kotlinlang.org/docs/reference/delegated-properties.h... class MutableUser(val map: MutableMap<String, Any?>) { var name: String by map var age: Int by map } I haven't used Scala but its (Duck)Structual Typing seems like it would get closer again to a dynamic typing feel with static types. Java is pretty verbose and limited in ways, and many devs having backgrounds in EJBs and Struts doesn't help. It would be interesting to see the same side-by-side project comparison in those links with a team using Scala well. Anyway thats all coming from my bias of having done 12 years of Java and 1 year of full Javascript with Angular.
- swah 11y agoStevey would criticize languages left and right, though. I wonder if he is coding in dynamic languages at Google nowadays... Most likely he is writing Go while complaining about it. (miss you stevey please resume writing)
- astrange 11y agoNeither of these are even the article I was thinking of. There was one with the same method written in Java and Perl, doing the same thing, and both obviously correct. But the Perl one was much much shorter because you didn't have to type any types.
- empath75 11y agoIt's kind of a headache to get started if you just want something quick and dirty.
- cname 11y agoIsn't Ruby strongly typed (like Python)? Or do you mean statically typed?
- Terr_ 11y agoSpeaking as someone who often looks at PHP and wishes it were Java, I'll try some devil-advocacy... Ttatic-typed stuff requires more decision-making effort from the user as they write code. (In exchange for lowering the effort to read/analyze it later.) Naive decisions can impact how other people use your code, requiring them to "fix it up". (Fortunately, refactoring tools can help.) Another downside is when the type system the language provides only partially addresses your vision. Then it gets a little tricky to decide how to optimize your baby-to-bathwater ratio.
- Joeri 11y agoAfter going back and forth between weak and strong (static) typing (php, js, java and scala) i would say weak typing lets you code quicker because you can be less explicit about what you're doing, but strong static typing lets you make code production-grade sooner because of all the additional checks which catch bugs. Weak typing feels more productive while coding, but when all is said and done often ends up being less so. In php you can do strict typing at the function call boundary, which is where it really matters, but you need the discipline to do it consistently. I like scala's approach of inferring types as much as possible and only stopping you when you're trying to do something semantically impossible. Scala often feels like a weakly typed system while coding, which is why it's so fun. For that matter, functional style java 8 feels the same way some of the time. I think the ideal system is strongly typed but maximally inferred to minimize verbosity and maximize coding productivity. Scala is too weird to be that language though.
- seanwilson 11y ago> What's the downside? If you're used to dynamic imperative languages, you have to learn a lot of new concepts, ways of thinking and new kinds of errors messages. Also, it's hard for ecosystems for strongly typed languages to compete because of current popularity.