3 ms·
I would say that Java has ~50% more code than Python due to types and braces. But I agree with you that it's worth it, because the compiler can check that a pro
by nayuki 8y ago
I would say that Java has ~50% more code than Python due to types and braces. But I agree with you that it's worth it, because the compiler can check that a programmer satisfied a constraint, instead of relying on informal conventions or comments.
You can have a statically typed language without verbosity, via type inference (Haskell, newer Java, etc.). I wouldn't say I enjoy Java's verbosity, but I would take this over shooting myself in the foot because Python does little to protect me from my own silly type/name mistakes.
I do lament that Java falls short on being able to declare tuples, lists, and dictionaries easily.
- ilovecaching 8y agoMost Haskellers write out the types even though they can be inferred. In a pure language, signatures are extremely close to documentation (you know exactly what a function will do by its signature). Java requires more code than Python or Haskell because it's extremely imperative and statement based. Python on the other hand includes a lot of functional, more expressive idioms like concise list comprehensions.
- omaranto 8y ago> Most Haskellers write out the types even though they can be inferred. I don't think that's true. Idiomatic Haskell has explicit declarations only for top level functions and uses type inference for everything else.
- jose_zap 8y agoI often copy paste the inferred type to top level declarations, so I’m a sense it is true
- FranzFerdiNaN 8y agoTypes aren’t documentation, no matter how many Haskell users delude themselves thinking it is. Documentation is more than a function definition. Types don’t explain rationales and how to use functions and programs. Types don’t give proper examples.
- hasahmed 8y agoIt's better documentation than no documentation
- chowells 8y agoTypes are really good documentation. I can tell I'm not deluded by thinking so because I can sit down with a Haskell library containing zero examples and write code that uses it. If your assertion was correct, that would be impossible. But it's not only possible, it's easy. Perhaps there is more to types than you realize.
- pmoriarty 8y agoAlice: Hey Bob, want to try my nifty new function? Bob: Sure, Alice, what does it do? Alice: It takes an object and it returns an object. Bob: But what does it actually do? Alice: I told you. It takes an object and it returns an object. Bob: But what does it do with the object? What's it for? Why should I use it? Alice: Hey, I just gave you the full documentation for my function. You have everything you need. Now go use it. Bob: Um, no thanks. I like to know more about what I'm getting myself in to.
- xboxnolifes 8y agoThankfully, Haskell supports much nicer types than only `Object`
- pvorb 8y agoAlice: Hey Bob, want to try my nifty new function? Bob: Sure, Alice, what does it do? Alice: It takes a string and it returns an integer. Bob: But what does it actually do? Alice: I told you. It takes a string and it returns an integer. Bob: But what does it do with the string? What's it for? Why should I use it? Alice: Hey, I just gave you the full documentation for my function. You have everything you need. Now go use it. Bob: Um, no thanks. I like to know more about what I'm getting myself in to.
- pytester 8y ago>In a pure language, signatures are extremely close to documentation (you know exactly what a function will do by its signature). The same can be true of tests. I've started generating API documentation from mine: e.g. https://hitchdev.com/strictyaml/using/alpha/scalar/email-and-url/ https://hitchdev.com/strictyaml/using/alpha/scalar/email-and... I tend to think of types and tests as attacking the same problem from opposite directions.
- sethammons 8y ago> StrictYAML can validate emails (using a simplified regex) Public Service Announcement: don't validate emails with regex. Every time you do, god kills a kitten.
- pytester 8y agoJust checking for the @ symbol is fair game. Anything beyond that is a bad idea.
- sethammons 8y agoAgreed :)
- YouAreGreat 8y ago> Most Haskellers write out the types Maybe that's partly because Haskell can easily become a bit too elegant. Between all the currying and combinators, the type helps to understand code "top down", i.e. when you don't have studied and memorized all "bottom up" component parts.
- m_mueller 8y agoTuples especially, and more specifically how the language supports their unwrapping. for idx, entry in enumerate(list) vs. list iterators in Java where you have to repeat complex types at least 3 times and get about 5-10 times more code when it would only have to be about 2 times to achieve static type safety. Lack of typedef and the resulting drive towards dummy classes is exacerbating this problem further.