News for hackers. Stuff that matters.
Re:The comeback of static typing by cletus on Sunday February 24, 2013 @01:00PM (#5275146)
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

[2]: http://www.time.com/time/specials/2007/article/0,28804,16585...

Re:The comeback of static typing by dons on Sunday February 24, 2013 @01:28PM (#5275261)
> 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.

Re:The comeback of static typing by sanderjd on Sunday February 24, 2013 @01:36PM (#5275292)
I 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.
Re:The comeback of static typing by Chris_Newton on Sunday February 24, 2013 @01:43PM (#5275319)
The 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.

Re:The comeback of static typing by ComputerGuru on Sunday February 24, 2013 @03:21PM (#5275738)
I don't get your point.

In C++ "return std::set<int>" - there's your tree.

Re:The comeback of static typing by gnosis on Sunday February 24, 2013 @01:26PM (#5275252)
"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)

[2] - https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life

Re:The comeback of static typing by vidarh on Sunday February 24, 2013 @01:35PM (#5275287)
We also want our code to be readable.
Re:The comeback of static typing by jjore on Sunday February 24, 2013 @01:57PM (#5275380)
I 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.
Re:The comeback of static typing by _ZeD_ on Sunday February 24, 2013 @03:12PM (#5275714)
I think a really simple rule-of-thumb for code is: "can you dictate it through the phone?"
Re:The comeback of static typing by vorg on Monday February 25, 2013 @04:45AM (#5278097)
Code 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.

Re:The comeback of static typing by saryant on Sunday February 24, 2013 @01:43PM (#5275317)
shudder

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.

Re:The comeback of static typing by vorg on Monday February 25, 2013 @04:49AM (#5278103)
APL is far more readable than J in my opinion, perhaps because APL keeps the brackets and curlies balanced, while J doesn't. All operators in APL are one token long, while J uses multi-token operators. The extended character set of APL has many benefits.
Re:The comeback of static typing by coldtea on Sunday February 24, 2013 @01:46PM (#5275326)
This is terse but not expressive.
Re:The comeback of static typing by mseepgood on Sunday February 24, 2013 @01:59PM (#5275386)
It is highly expressive.
Re:The comeback of static typing by pjmlp on Sunday February 24, 2013 @02:58PM (#5275662)
For 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.

Re:The comeback of static typing by aaronblohowiak on Sunday February 24, 2013 @01:49PM (#5275335)
Why don't MLs get enough credit?
Re:The comeback of static typing by mafribe on Sunday February 24, 2013 @03:14PM (#5275717)
“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.

Re:The comeback of static typing by mseepgood on Sunday February 24, 2013 @01:56PM (#5275372)
ML is actually the poster child of static typing with its Hindley-Milner type inference.
Re:The comeback of static typing by more_original on Sunday February 24, 2013 @03:02PM (#5275673)
Yes 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.
Re:The comeback of static typing by pjmlp on Monday February 25, 2013 @07:48AM (#5278662)
C 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.

Re:The comeback of static typing by laureny on Sunday February 24, 2013 @01:25PM (#5275246)
> - compiles to a binary rather than running on a VM;

To me, this is one the many reasons why Go will fail.

Re:The comeback of static typing by pjmlp on Sunday February 24, 2013 @02:42PM (#5275597)
VM 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.

Re:The comeback of static typing by kgabis on Sunday February 24, 2013 @01:32PM (#5275276)
Could you elaborate on this?
Re:The comeback of static typing by laureny on Sunday February 24, 2013 @03:27PM (#5275760)
These 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.
Re:The comeback of static typing by kgabis on Monday February 25, 2013 @06:57AM (#5278497)
Having 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).
Re:The comeback of static typing by pjmlp on Monday February 25, 2013 @07:50AM (#5278672)
> ... case of jvm - dependency on sun/oracle ...

Why the dependency on Oracle?

There are other many other JVM available, even not certified ones, and you can also use compilers to native code if you wish to do so.

Re:The comeback of static typing by eru on Monday March 04, 2013 @04:59AM (#5317521)
Wouldn't a vm help with security?
Re:The comeback of static typing by coldtea on Sunday February 24, 2013 @01:47PM (#5275331)
I'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.