22 ms·
>> if it compiles, then it just seems to work This. I spent the first 14 years of my career in statically typed languages and only this year began working prof
by christophilus 11y ago
>> if it compiles, then it just seems to work
This. I spent the first 14 years of my career in statically typed languages and only this year began working professionally on a Rails app... I really miss the compiler.
- shrugger 11y agoYou might be interested in the Crystal language. It's a statically-typed, Object-oriented, Ruby inspired language. It's Ruby with types, basically. You might also be interested in Elixir which ties in to the Erlang ecosystem, but if you are super into OOP (like me) you might find it slightly more difficult, but since you have experience with static-types, you probably know some FP stuff, and so it's not that bad. Either way, best of luck. It takes a brave soul to fight with Rails. I've been writing Ruby for about three years now and still haven't touched Rails just because I can imagine how little fun it is to try and debug dynamic-typed web stuff. Noooooo thanks.
- brightball 11y agoIt's odd how people are in their perspectives on static vs dynamic. I can't for the life of me understand how people tolerate static typing on the web. Every time I've tried it the experience has been so tedious. I just figure, everything is coming in as a string no matter what. It's going back out as a string. The only place it needs to be anything other than a string is something interesting is being done with it and since dynamic typing lets you just worry about it in those cases, it removes a lot of unnecessary code. On the flip side, outside of web work i can't imagine the reverse.
- appsappsapps 11y agoWhat typed languages have you used and what aspects do you find tedious? I find that the experience of writing brittle type-checking logic and tests in dynamic languages is rather tedious in its own right.
- Matthias247 11y agoI find that even the typing experience is faster with static types, since we get better autocompletion/intellisense and there is no need to lookup documentation or other code all the time.
- ShaneWilton 11y ago> I just figure, everything is coming in as a string no matter what. It's going back out as a string. Maybe so, but that only accurately describes things at the boundaries of your system. Your database tables still have columns that hold integers, dates, or floats. Sure, you could do the type coercions as needed, but at that point you're missing out on the valuable opportunity to validate your data as it enters the system. You can provide meaningful errors to users as early as possible, you can avoid defensive checks nearly everywhere else within your code, and you can just generally trust that invariants about your data are going to hold throughout the rest of your program. This leads to smaller test suites, more concise codebases, and higher security assurances overall. If you look at the sorts of vulnerabilities that often pop up in Rails for example, many of them simply don't affect you if you use something like Virtus [0] to validate the types of your data as it enters the system. I don't do much web development, but statically typed web development is the only way I've ever been able to tolerate it. [0] https://github.com/solnic/virtus https://github.com/solnic/virtus
- spdionis 11y agoYou can avoid defensive checks anyway. Just don't writre them! /s
- rvense 11y agoYou build your system as a box that takes strings in and sends strings out. You then have to do a bunch of checks (as part of your de/serializing) at the boundaries only. Inside the box, all your logic and transformations are type safe, and indeed you can turn some logic issues into mechanically checked type-level issues, which are basically free unit tests.
- SOLAR_FIELDS 11y agoI like this for lightweight applications. I imagine it could become a bottleneck for anything moderately heavyweight when it comes to data processing. Most web apps are designed to not do any heavyweight lifting on the client side, so it is a nice general paradigm for that.
- rvense 11y agoWhy a bottleneck? Static types don't have to add any runtime overhead. In fact, the type information isn't present at runtime at all in some languages. It's a compile-time guarantee that actually allows you to remove some runtime checks and assertions. And I think all bechmarks show that static languages are as a rule faster than dynamic languages. If you're comparing two different designs in a statically language where one involves making lots of new types and the other just shuffles strings back and forth, then I can't say and it'd depend on the specific case. Generally, helping the compiler is a good thing, and obviously things like switching on an enumeration is much faster than a long line of string comparisons. Actually, strings are just a horrible datatype, so unconstrained and inefficient. Use strings less!
- noblethrasher 11y agoYou know what else takes in strings and spits out strings? A compiler! Here are a couple of other under-appreciated facts about compilers: 1. For regular grammars, they are easy to build with any kind of programming language. 2. For regular grammars, they are really really easy to build with statically-typed programming languages. Now days, my web development is essentially just compiler construction for regular languages, and it just so happens that extremely statically-typed like the MLs (F#, in my case) are damn good for writing compilers (one joke is that it’s the only thing they’re good for). I write far fewer lines of code per feature than I ever did with ”dynamically“ typed languages like PHP, and it’s usually right the first time.
- insulanian 11y agoYes everything is a string on the web, but IMO it's not the primitive data types that I'm concerned about so much - it's about the data structure (classes / interfaces). If I refer to my item's description property as `item.descripition`, statically typed language will scream that I have mistyped the property name before letting me run that code or, God forbid, releasing it.
- deleted 11y ago[deleted]
- naasking 11y ago> I just figure, everything is coming in as a string no matter what. It's going back out as a string. And everything in memory is a sequence of bytes. I don't see the relevance of this line of reasoning. I guarantee that whatever experience you've had with statically typed languages on the web, it's not a good language. Interfacing with dynamic systems is simply a matter of good abstractions, which many languages simply lack. Take a look at F#'s type providers to see where you can go with this.
- shrugger 11y agoYou might be interested in the Crystal language. It's a statically-typed, Object-oriented, Ruby inspired language. It's Ruby with types, basically. You might also be interested in Elixir which ties in to the Erlang ecosystem, but if you are super into OOP (like me) you might find it slightly more difficult, but since you have experience with static-types, you probably know some FP stuff, and so it's not that bad. Either way, best of luck. It takes a brave soul to fight with Rails. I've been writing Ruby for about three years now and still haven't touched Rails just because I can imagine how little fun it is to try and debug dynamic-typed web stuff. Noooooo thanks.
- astrodust 11y agoRust has some really good compile-time checking, it really makes you express everything in a completely non-ambiguous way. C++ on the other hand compiles stuff that may or may not work at all, it doesn't care, which can lead to all sorts of undefined behaviour down the road. Compilers are not all created equal.
- swaroop 11y agoThe new C++ Core Guidelines & Guidelines Support Library and related tools are interesting efforts to specifically solve those problems.
- Buttons840 11y agoIf the issue is that "C++ compiles stuff that may or may not work at all" then I don't see how those guidelines will help the situation. A C++ project may or may not follow those guidelines and then we're back where we started.
- swaroop 11y agoMy understanding is that the tools are the answer - it's a linter that must be run before landing/merging. See https://youtu.be/hEx5DNLWGgA https://youtu.be/hEx5DNLWGgA for a demo of such tools.
- SomeCallMeTim 11y ago
- biot 11y agoGive it another year and the new batch of hotshot developers will reinvent static typing and perhaps one or two other features from the 1970s, but it'll have some cool name and only implement 50% of the functionality.
- andybak 11y agoModern static typing isn't remotely related to typing from the "1970's"
- vanderZwan 11y agoWell, depends on what you mean with modern static typing. In some ways, mainstream programming is finally catching up with ML, which is from the 1970s. If you mean cutting edge PL research it's a different story of course.
- CuriousSkeptic 11y agoOk, 1969, but fairly close! https://en.m.wikipedia.org/wiki/Hindley–Milner_type_system https://en.m.wikipedia.org/wiki/Hindley–Milner_type_system
- nostrademons 11y agoThe type systems in modern languages like Swift, Rust, Scala, Haskell, and even Kotlin go way beyond classical Hindley-Milner. Classical Hindley-Milner gives you parametric polymorphism over algebraic data types, along with an inference algorithm. No subtyping, no casts, no coercions, no overloading, no polymorphic literals, no interfaces. You basically get SML. Consider that in 2006, MPTCs with fundeps was the preferred way to represent "a collection of items that can be compared via equality" [1]. Associated types were a vague research idea [2] that showed a lot of promise, but hadn't been implemented in any language with type inference (they did exist in C++ templates, but C++ isn't exactly what people think of when you say "modern type system"). Now both Rust and Swift feature polished implementations of associated types and use them pervasively in the standard library. [1] https://en.wikibooks.org/wiki/Haskell/Advanced_type_classes#Multi-parameter_type_classes https://en.wikibooks.org/wiki/Haskell/Advanced_type_classes#... [2] https://prime.haskell.org/wiki/AssociatedTypes https://prime.haskell.org/wiki/AssociatedTypes