6 ms·
I think static typing (10+ years ago) got a bad rap not because of static typing as such, but everything that came with it (and didn't necessarily need to). I'm
by cletus 14y ago
I think static typing (10+ years ago) got a bad rap not because of static typing as such, but everything that came with it (and didn't necessarily need to). I'm talking about the languages of the time (C, C++, Java primarily).
C is a bit of the one out here in that its static typing is a really thin veneer as you can cast things to whatever you want them to.
Python and Ruby (in particular these two) more than anything else allowed you to write really terse, expressive code. The canonical Python example of this is defining a tree data structure:
def tree(): return defaultdict(tree)
or solving the N-queens problem in ~6 lines of code [1].
Java and C++ OTOH were (and are) much more verbose but only some of this has anything to do with static typing.
All of this is one reason I'm incredibly bullish on the future of Go for such reasons as:
- no interfaces. If an object implements the methods expected by a consumer then it compiles otherwise it doesn't;
- incredibly simple OO system;
- no exceptions as such (particularly checked exceptions in the case of Java, which IMHO are just horrible). Some consider this a minus. I tend to think that exceptions tend to get abused for flow control and aren't the panacea they're made out to be;
- simple semantics for function returns and the ability to return multiple items;
- opinionated formatting (I'm not one of those people who has almost religious zeal for the placement of curly braces and indenting so I'd rather just have a standard and stick to it, whatever it is);
- compiles to a binary rather than running on a VM;
- simple grammar with fast compilation. This last point is contrasted particularly well with C++;
- coroutines (or rather goroutines) as a first-class language citizen for solving concurrency problems;
- the "defer" mechanism for resource cleanup. I find this much easier to read than tortured try-finally semantics and nesting.
Another way to put it is this: a lot of vim/emacs users judge IDEs as horrible based on having (often briefly) used Eclipse, which is a bit like judging the car by having once driven a 1975 Trabant.
Don't judge static typing by Java or even C++. Judge it by Go.
[1]: http://rosettacode.org/wiki/N-queens_problem#Python http://rosettacode.org/wiki/N-queens_problem#Python
[2]: http://www.time.com/time/specials/2007/article/0,28804,1658545_1658533_1658030,00.html http://www.time.com/time/specials/2007/article/0,28804,16585...
- laureny 14y ago> - compiles to a binary rather than running on a VM; To me, this is one the many reasons why Go will fail.
- kgabis 14y agoCould you elaborate on this?
- coldtea 14y agoI'm not the parent, but one reason could be that the feature is more about collaboration of different languages for different purposes on a shared ecosystem (JVM, CLR, JS as bytecode, etc). Which Go doesn't play well with.
- laureny 14y agoThese days, there are more advantages than drawbacks to running in a VM. The performance advantage of native over byte code has shrunk considerably to the point of being only relevant for a tiny portion of applications (e.g. games). On the other hand, there are considerable advantages to JVM's, as Java and the generation of language it kickstarted has shown.
- kgabis 14y agoHaving a VM also adds a whole lot of security concerns and in case of jvm - dependency on sun/oracle. VMs are not the only way to kickstart language generation, there are other options, such as llvm (yeah, that name is confusing in this context).
- pjmlp 14y agoVM is just a conceptual model. Most languages that usually have a VM, also tend to have native code compilers available, it is just that most HN folks tend to be unaware of them.
- gnosis 14y ago"Python and Ruby (in particular these two) more than anything else allowed you to write really terse, expressive code." If you like being able to write terse, expressive code, you'll love APL,[1] where Conway's Game of Life[2] can be written in one line as: life←{↑1 ⍵∨.∧3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵} [1] - https://en.wikipedia.org/wiki/APL_(programming_language) https://en.wikipedia.org/wiki/APL_(programming_language) [2] - https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
- vidarh 14y agoWe also want our code to be readable.
- jjore 14y agoI can't read APL but perhaps that is readable. I'm unsure that other common dynamic languages like Ruby or Python are readable purely in comparison purely for using http://en.wikipedia.org/wiki/COBOL#Verbose_syntax http://en.wikipedia.org/wiki/COBOL#Verbose_syntax.
- _ZeD_ 14y agoI think a really simple rule-of-thumb for code is: "can you dictate it through the phone?"
- vorg 14y agoCode has nested structures which are commonly shown with indentation, which it's difficult to communicate vocally with say, intonation. E.g. think about how differently you'd dictate this variation on your reply... I think a really simple rule of thumb-for-code is "can you dictate it?" through the phone.
- saryant 14y agoshudder My first introduction to functional programming was with J (APL but using ASCII) during my sophomore year of college and I definitely didn't have the chops to understand it at that point. I was scared of functional languages for another year until a different professor introduced me to Haskell.
- dons 14y ago> The canonical Python example of this is defining a tree data structure: def tree(): return defaultdict(tree) But you're not defining a data structure -- you're just reusing the builtin dictionary type. Try defining say a RB tree without using builtin container types, and you quickly see how poor these languages' support for new data structures is.
- sanderjd 14y agoI think you're willfully missing the point - you don't have to implement an rb tree without the built in containers because the language comes with built in containers. Python doesn't need to be optimized for doing such things from scratch because hardly anybody ever needs to do such things from scratch.
- Chris_Newton 14y agoThe language comes with a small number of simple but widely applicable containers. That doesn’t negate dons’ point that if you need something other than those containers there is relatively poor support for defining your own.
- ComputerGuru 14y agoI don't get your point. In C++ "return std::set<int>" - there's your tree.
- aaronblohowiak 14y agoWhy don't MLs get enough credit?
- mseepgood 14y agoML is actually the poster child of static typing with its Hindley-Milner type inference.
- more_original 14y agoYes exactly! I always find it really impressive that ML and its type inference were developed in the 70s, only just a few years after C had been defined.
- pjmlp 14y agoC only got ubiquitous due to being UNIX's system programming language. Who knows how it would have turned out if UNIX did not became as it turned out to be.
- mafribe 14y ago“Being right too soon is socially unacceptable.” ML was an improvement on most of its successors, and if you trace the development of mainstream languages, you see that they are more and more becoming ML.
- pjmlp 14y agoFor me static typing actually was learned by using ML, Modula-2, Pascal, Ada with C showing a more weak typing kind of thing. Java and C# also have native code compilers available to them.