Comments on: My two cents on Static Typing http://blog.madarco.net/72/my-two-cents-on-static-typing/ on Flash, Java, Webdesign Tue, 18 Nov 2008 20:22:36 +0000 http://wordpress.org/?v=2.6.2 By: Antonio http://blog.madarco.net/72/my-two-cents-on-static-typing/#comment-6092 Antonio Fri, 18 May 2007 16:59:38 +0000 http://blog.madarco.net/72/my-two-cents-on-static-typing/#comment-6092 For me, the difference between static and dynamic typing is relatively simple: trust or don't trust the programmer. Dynamic typing trusts the programmer to make the right choice, and by consequence allows more flexibility (as with any relationship based on trust). Static typing does not trust the programmer to know more than the compiler, and by consequence is less flexible (as with any relationship based on distrust). Certain situations call for each. In a friendship, you want trust -- similarly, in a project where you know the programmers are good, you want trust, so you can use a dynamically typed language. In a business relationship, a healthy measure of distrust is reasonable -- similarly, in a project where maybe you don't think all of the programmers are as good, a healthy measure of distrust is reasonable, so a statically typed language can provide that distrust. That aside, I'm not sure why you couldn't have open classes in a statically typed language, provided there was a directive that told the compiler to consider files where class extensions/redefinitions occurred before considering other files. It would complicate things, yes, but I still think it would be doable. For me, the difference between static and dynamic typing is relatively simple: trust or don’t trust the programmer. Dynamic typing trusts the programmer to make the right choice, and by consequence allows more flexibility (as with any relationship based on trust). Static typing does not trust the programmer to know more than the compiler, and by consequence is less flexible (as with any relationship based on distrust). Certain situations call for each. In a friendship, you want trust — similarly, in a project where you know the programmers are good, you want trust, so you can use a dynamically typed language. In a business relationship, a healthy measure of distrust is reasonable — similarly, in a project where maybe you don’t think all of the programmers are as good, a healthy measure of distrust is reasonable, so a statically typed language can provide that distrust.

That aside, I’m not sure why you couldn’t have open classes in a statically typed language, provided there was a directive that told the compiler to consider files where class extensions/redefinitions occurred before considering other files. It would complicate things, yes, but I still think it would be doable.

]]>
By: Georgi http://blog.madarco.net/72/my-two-cents-on-static-typing/#comment-6091 Georgi Fri, 18 May 2007 15:57:19 +0000 http://blog.madarco.net/72/my-two-cents-on-static-typing/#comment-6091 Static typing definitely is superior in one point: It allows a compiler (or even a smart "pre-compiling" interpreter) to find an error before the program has to be executed. I once programmed in a language called "SML" which checked the type without static typing which was pretty cool, but (to find an example) the average scripting language does not work that way. I am not sure if Haskell and/or Smalltalk do work in a comparable manor, but I think they do (Haskell is a kind of ancestor to the research done in SML). I, personally, want the compiler to check my errors wherever applicable. Therefore I do accept to type more code, even if it is more work at the moment. I, too, like to have it (the type of a program, definition of a method etc.) in black and white, written in code, so that I can follow my own thoughts more simple later on. And I do not like "dynamic code", i.e. trusting on methods never written in first place. I did things like "programs that write programs/extensions" in the early 80s (in Assembler, every clockcycle counted, so you poked your own machine code from other machine code to be faster) - this cannot be the way to write code for nowaday applications, no one can maintain that for long. Conclusion (for me): There are, in my opinion, two ways: Use dynamic typing for prototyping (get results done fast) or "small" projects, use static typing for structured (more manpower where you want to rely on your compiler) or "larger" projects. Just my 2 cents, Georgi Static typing definitely is superior in one point: It allows a compiler (or even a smart “pre-compiling” interpreter) to find an error before the program has to be executed. I once programmed in a language called “SML” which checked the type without static typing which was pretty cool, but (to find an example) the average scripting language does not work that way. I am not sure if Haskell and/or Smalltalk do work in a comparable manor, but I think they do (Haskell is a kind of ancestor to the research done in SML).

I, personally, want the compiler to check my errors wherever applicable. Therefore I do accept to type more code, even if it is more work at the moment. I, too, like to have it (the type of a program, definition of a method etc.) in black and white, written in code, so that I can follow my own thoughts more simple later on.

And I do not like “dynamic code”, i.e. trusting on methods never written in first place. I did things like “programs that write programs/extensions” in the early 80s (in Assembler, every clockcycle counted, so you poked your own machine code from other machine code to be faster) - this cannot be the way to write code for nowaday applications, no one can maintain that for long.

Conclusion (for me): There are, in my opinion, two ways: Use dynamic typing for prototyping (get results done fast) or “small” projects, use static typing for structured (more manpower where you want to rely on your compiler) or “larger” projects.

Just my 2 cents, Georgi

]]>
By: Matt Giuca http://blog.madarco.net/72/my-two-cents-on-static-typing/#comment-6090 Matt Giuca Fri, 18 May 2007 15:04:03 +0000 http://blog.madarco.net/72/my-two-cents-on-static-typing/#comment-6090 IMHO, you can't get enough static typing. I am aware that dynamic languages let you do things like add methods at runtime and so on - but as far as I'm concerned YOU SHOULD NOT BE ABLE TO DO THAT. If you add methods at runtime, how can you be sure, when you call a method, that it exists? Any feature which takes a runtime exception and converts it into a compiler error is, in my opinion, a good feature. Compiler errors mean that if you manage to compile your code, THAT ERROR CAN'T POSSIBLY HAPPEN. Runtime exceptions mean that no matter how hard you test, there's still a chance it can happen. Dynamic languages basically take the compiler error "invalid typecast" from static typed languages, and turn it into a runtime exception, therefore making no guarantees that it won't blow up in your face at runtime. To follow on from what Jon Harrop said, look at modern static languages - in particular my favourite Haskell. I say there should be NO DOWNCASTING. Consider the "Object" type in Java or .NET. You can downcast this to whatever you like - giving a runtime exception if you downcast to the wrong type. This is equivalent to a dynamic typed language, except it only happens when you explicitly downcast. Haskell has no downcasting at all - everything is done using generics. A no-downcasting type system (maybe not Haskell's, but the concept of a no-downcast system) still lets you do everything required by an inheritance hierarchy, albiet sometimes in a more roundabout way, but importantly, the programmer is forced to ensure that all "downcasts" (their equivalents) are successful, thereby eliminating the downcast exception altogether. For more information, check out Haskell's bizarrely super-safe static type system. IMHO, you can’t get enough static typing. I am aware that dynamic languages let you do things like add methods at runtime and so on - but as far as I’m concerned YOU SHOULD NOT BE ABLE TO DO THAT. If you add methods at runtime, how can you be sure, when you call a method, that it exists?

Any feature which takes a runtime exception and converts it into a compiler error is, in my opinion, a good feature. Compiler errors mean that if you manage to compile your code, THAT ERROR CAN’T POSSIBLY HAPPEN. Runtime exceptions mean that no matter how hard you test, there’s still a chance it can happen.

Dynamic languages basically take the compiler error “invalid typecast” from static typed languages, and turn it into a runtime exception, therefore making no guarantees that it won’t blow up in your face at runtime.

To follow on from what Jon Harrop said, look at modern static languages - in particular my favourite Haskell. I say there should be NO DOWNCASTING. Consider the “Object” type in Java or .NET. You can downcast this to whatever you like - giving a runtime exception if you downcast to the wrong type. This is equivalent to a dynamic typed language, except it only happens when you explicitly downcast.

Haskell has no downcasting at all - everything is done using generics. A no-downcasting type system (maybe not Haskell’s, but the concept of a no-downcast system) still lets you do everything required by an inheritance hierarchy, albiet sometimes in a more roundabout way, but importantly, the programmer is forced to ensure that all “downcasts” (their equivalents) are successful, thereby eliminating the downcast exception altogether. For more information, check out Haskell’s bizarrely super-safe static type system.

]]>
By: Norfy http://blog.madarco.net/72/my-two-cents-on-static-typing/#comment-6089 Norfy Fri, 18 May 2007 10:33:02 +0000 http://blog.madarco.net/72/my-two-cents-on-static-typing/#comment-6089 Some variants of Smalltalk I believe have type inference for code completion. I typically use runtime type information rather than try to infer types for code I am not familar with. ie. The Smalltalk debugger has full REPL support and once a method has been edited and saved, the program can be resumed from anyway on the stack. ie. There is never a compile/link stage to Smalltalk development. This fact alone saves so much time for a large project. Some variants of Smalltalk I believe have type inference for code completion.

I typically use runtime type information rather than try to infer types for code I am not familar with. ie. The Smalltalk debugger has full REPL support and once a method has been edited and saved, the program can be resumed from anyway on the stack. ie. There is never a compile/link stage to Smalltalk development. This fact alone saves so much time for a large project.

]]>
By: Jon Harrop http://blog.madarco.net/72/my-two-cents-on-static-typing/#comment-6088 Jon Harrop Fri, 18 May 2007 10:27:43 +0000 http://blog.madarco.net/72/my-two-cents-on-static-typing/#comment-6088 Anyone wanting to write about static typing in general would do well to look at modern statically typed languages like Haskell, OCaml and F#. These languages offer many benefits over Java, for example. Anyone wanting to write about static typing in general would do well to look at modern statically typed languages like Haskell, OCaml and F#. These languages offer many benefits over Java, for example.

]]>
By: Madarco http://blog.madarco.net/72/my-two-cents-on-static-typing/#comment-6087 Madarco Fri, 18 May 2007 09:57:28 +0000 http://blog.madarco.net/72/my-two-cents-on-static-typing/#comment-6087 I don't know Smalltalk enough, does it or the IDE parser support type inference? I see type inference as the best (and secure) way to drop type declarations: often we declare the type and populate the field at the same time. However, I can do something similar and with the same number of keystrokes in Java pressing a shortcut (Eclipse). I don’t know Smalltalk enough, does it or the IDE parser support type inference?
I see type inference as the best (and secure) way to drop type declarations: often we declare the type and populate the field at the same time.
However, I can do something similar and with the same number of keystrokes in Java pressing a shortcut (Eclipse).

]]>
By: Norfy http://blog.madarco.net/72/my-two-cents-on-static-typing/#comment-6086 Norfy Fri, 18 May 2007 09:11:44 +0000 http://blog.madarco.net/72/my-two-cents-on-static-typing/#comment-6086 Having gone from static to dynamic languages a number of times I have come to the conclusion that (my) productivity has more to do with the tools that come with them, and so far I prefer the (VisualWorks) Smalltalk IDE. The simplicity and consistency of the Smalltalk syntax is also nice when compared to the "keyword" list one needs to remember when switching between static languages. Where I have found the Smalltalk IDE to be particularly beneficial is in the maintenance and further development phase of a project. Exploring and debugging code seems so much easier than what I have found with Eclipse/Websphere and Visual Studio. In a production multi million dollar environment (investment banking) where our Smalltalk project is competing against or is integrated with static language projects, our project is *always* the first to market. The dev team is also the smallest. Having gone from static to dynamic languages a number of times I have come to the conclusion that (my) productivity has more to do with the tools that come with them, and so far I prefer the (VisualWorks) Smalltalk IDE.

The simplicity and consistency of the Smalltalk syntax is also nice when compared to the “keyword” list one needs to remember when switching between static languages.

Where I have found the Smalltalk IDE to be particularly beneficial is in the maintenance and further development phase of a project. Exploring and debugging code seems so much easier than what I have found with Eclipse/Websphere and Visual Studio.

In a production multi million dollar environment (investment banking) where our Smalltalk project is competing against or is integrated with static language projects, our project is *always* the first to market. The dev team is also the smallest.

]]>
By: Ivan http://blog.madarco.net/72/my-two-cents-on-static-typing/#comment-6085 Ivan Fri, 18 May 2007 09:11:43 +0000 http://blog.madarco.net/72/my-two-cents-on-static-typing/#comment-6085 The point about migration to a static typing system is dead-on btw. All languages that start nice and easy eventually hit the design limits and get really ugly as they attempt to add restrictions where there previously were none. Aren't there already community calls for Ruby static typing? That makes me laugh. Unfortunately, by the time they need it, the community has already settled on the "easy" way and won't pick up the new features (looking at you Php). Going the other way is a lot easier, since you just have to relax, thus the various forms of Java expressions (OGNL, JexL etc). The point about migration to a static typing system is dead-on btw. All languages that start nice and easy eventually hit the design limits and get really ugly as they attempt to add restrictions where there previously were none. Aren’t there already community calls for Ruby static typing? That makes me laugh.

Unfortunately, by the time they need it, the community has already settled on the “easy” way and won’t pick up the new features (looking at you Php). Going the other way is a lot easier, since you just have to relax, thus the various forms of Java expressions (OGNL, JexL etc).

]]>
By: Anonymous http://blog.madarco.net/72/my-two-cents-on-static-typing/#comment-6084 Anonymous Fri, 18 May 2007 09:11:01 +0000 http://blog.madarco.net/72/my-two-cents-on-static-typing/#comment-6084 See: http://en.wikipedia.org/wiki/Static_typing#Static_typing See: http://en.wikipedia.org/wiki/Static_typing#Static_typing

]]>
By: Madarco http://blog.madarco.net/72/my-two-cents-on-static-typing/#comment-6082 Madarco Fri, 18 May 2007 07:35:46 +0000 http://blog.madarco.net/72/my-two-cents-on-static-typing/#comment-6082 Magpie you have take exactly the point, with Dynamic typing there can be two points of view: you say: we can call a method if we know for sure it exists without bother to explain it to the compiler I say: every time we call a method we hope it exists (and that we had spell it correctly), the best way is to lose some keystroke to instrument the compiler so we can be sure. The fact that you can mix static and dynamic types in some languages is the proof that static is the Good Thing, especially because often it is a feature added in newer, more advanced, version of the language. An then hey, look at a well-written dynamic application, is full of types specified in the comments or worst in the variable names. Magpie you have take exactly the point, with Dynamic typing there can be two points of view:

you say: we can call a method if we know for sure it exists without bother to explain it to the compiler

I say: every time we call a method we hope it exists (and that we had spell it correctly), the best way is to lose some keystroke to instrument the compiler so we can be sure.

The fact that you can mix static and dynamic types in some languages is the proof that static is the Good Thing, especially because often it is a feature added in newer, more advanced, version of the language.

An then hey, look at a well-written dynamic application, is full of types specified in the comments or worst in the variable names.

]]>