3 ms·
What's with the obsession about (static) typing? I have written code in untyped languages all my life and it has never been a problem for me. The only problem
by k__ 13y ago
What's with the obsession about (static) typing?
I have written code in untyped languages all my life and it has never been a problem for me.
The only problem I see with bigger JavaScript apps is the callback-hell.
Funny thing is, most to-JavaScript languages focus on the type aspect.
If I could write linear asynchronous code everything would be much more readable after coming back to some code a few months later.
- joe_fishfish 13y agoAgreed. Dynamic typing is fine once you get used to it, but the only thing I've found to solve the callback hell is a publish / subscribe architecture, which brings its own problems.
- eru 13y agoI've started with (bad) static typing in C, Pascal and friends, then got to use the dynamic Lisp and Python. But now I'm at (good) static typing again with Haskell (and OCaml). Good static typing saves you about half the units tests. And you don't even have to worry too much about that `half' being correct, because the type machinery in your compiler has been checked by thousands of people before. Whereas your tests are normally written from scratch. Types also make your testing life much easier. QuickCheck is about the gold standard in rules based testing, and QuickCheck in a type-inferred language is just so much less verbose than when you have to either manually add all type annotiations or have to go without types. (That's mostly because Haskell allows overloading by return type.)
- Bahamut 13y agoPromises & named functions are your friends! So you can do stuff like this: callToRemoteApi().then(processData) .then(makeAnotherCallToAnotherApi) .then(processAllTheData)
- camus2 13y agoYou still need to write functions ,that's the issue. => functions will make things a bit better,but await and generator syntax are the key to solve some issues.
- esailija 13y agoGenerators and await don't really give anything substantial after promises except less superficially verbose syntax and not even that when using CoffeeScript where `return` and `function(){}` are really light-weight. Actually what issues generators and await solve are same as what CoffeeScript "solves". Although with generators you "can use normal control flow constructs". Except in most cases you probably use map or forEach instead of loops anyway. And try-catch is really broken.
- de90 13y agoFor me I like static typing because it adds a sanity check of the data getting passed around. Sure, most of the time it catches nothing, but it is nice when it does. Humans will always make mistakes, so static typing improves the amount of help\tools computers can put forth.
- camus2 13y agothe problem is NOT static typing vs dynamic typing but weak typing vs strong typing and type coercion. In basic ruby ,unless you mess with classes, [1,2]+1 WILL fail , though ruby is not staticaly typed. Ruby is STRONGLY typed, and that's a great thing. Javascript will do everything it can not to fail: String([1,2]) => "1,2" + 1 => "1,21" IMHO That's madness,because Javascript is basically making a decision for you.That was acceptable in 1995, that is not in 2013. And that's its biggest flaw.Writing javascript means working against the language. But there is a reason for that. Javascript is not good at throwing errors or handling them, at all. So it's not about static vs dynamic typing. There is no good solution for that problem unless TC39 decides to fix it. Enforcing dependency injection concepts and duck typing might work, but not always. For instance, you could check if a string is a string with function(x){ x=x.substr(); // will throw a TypeError if I pass an Array. } Before doing anything with x, it might help reduce some mistakes. and you might use it on return types. But it's verbose and doesnt work all the time.
- nfoz 13y agoIt was not acceptable in 1995, either.
- mattmanser 13y agoBut have you used statically typed langauges? Unless you've used both you won't be aware of the advantages. The big one for me is inheriting other people's code bases, in dynamic languages they're a complete and utter nightmare, especially when written by incompetent programmers, which seems to make up a worryingly large number of programmers. Or someone just learning and not aware of conventions. You just can't assume a method or function actually does what it says it does. Or returns what it says it does. And you can't even see what it's expecting or what things are being passed to it. You have to fine-toothcomb the method, it slows you down massively. I have worked on a fair few bad code bases now and luckily for me the majority of that's been in static languages. It makes it so much easier. Some of the other advantages of static typing include: 1. having incredibly good auto code completion 2. never having to remember or look up a method signature 3. to refactor massive chunks of code almost completely fearlessly 4. to fix crap code without any fear of breaking anything else 5. as long as you name your methods well, never having to annotate anything mundane (depending on your audience ofc) There are also other things like that tend to go hand-in-hand because they're usually explicit, like not worrying about implicit conversion (apart from VB with option explicit off). I've used both quite a lot over the last 10 odd years professionally programming and I've recently been thinking that I would actually prefer a mix, static typing on boundaries like method entry and new object declartion and dynamic everywhere else. I know little about compiler or language design, so I'm not sure it's even possible. C# kinda gets close with the var keyword, but the various disadvantages of static typing still rear their head quite a lot. As a slight aside, People on HN always seem to talk as if they only write new programs, not maintain old ones. Am I the weird one for frequently having to pick up code that was written by someone else? Who often had coded themselves into a corner and then made up some excuse as to why they couldn't keep the client anymore?
- k__ 13y agoI had to do some stuff in Java at university, it felt too clunky most of the time. :\ When using libraries, their functions always wanted their arguments to be some strange classes or implement some of their interfaces, which always seemed like big overhead to me. Stuff like Smalltalk, PHP and JavaScript felt much faster in development speed.