lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 23/10/2012 14:28, Enrico Tassi wrote:
I fully agree, and I've the same experience switching back and forth
between OCaml and Lua (and C sometimes).

Hence, the only true advantage I see of static typing is when you do
true research, i.e. you have no clear idea about the right data
structure (or the right approach) to solve your problem. In this case
you continuously refine your data structure, and a static type checker
is invaluable in driving you trough the code, pointing out all the
places where you actually make assumptions on the underlying data
representation.

This never happens if you know how to tackle your problem in the first
place, and you start with the right data structure from the very
beginning.

I see two problems with this approach:
- You are a good programmer. In a real team, there can be beginners, or not so good coders...
- Unless you document very well your data structure (I guess you do), and document well the type of your parameters, etc., it can be hard to use the API.

Java is verbose and rigid and all, but at least it safer for large teams of various levels of coders because it brings lot of safeguards, thanks to the type system.

Scala is a language with an even stricter type system (not far of Haskell), preventing even more errors but making it hard to use by beginners...

On the other end of the scale, PHP is a dynamic language that grown organically, with functions provided by various sources, and doc not always at the level wanted by strict users. At least, it has a system of comments of the doc helping to understand corner cases...

I don't say that a dynamic language prevents to make large softwares, but it is a bit harder: you need discipline and knowledge, to enforce conventions that are otherwise enforced by the language: document thoroughly each parameter and return value, write lot tests to ensure everything works as expected, etc.

Of course, you write lot of tests for statically typed languages like Java, but somehow you can skip some kind of tests needed by dynamic languages, like seeing what happens if you pass a parameter of the wrong type, etc. Of course, you need to document your statically typed program too, and actually having the types defined might push some coders to be lazy about documenting: I have seen rigorous Lua programs, and awful Java code!

Another point: I see that an IDE like Eclipse can benefit from static typing by auto-completion, database of types and functions, early error catching, thorough static analysis of code (eg. Findbugs and similar), accurate refactoring and some other advantages. It can make easier to explore a large code base, too, particularly when the documentation of types and functions is lacking, missing or obsolete...

These functionalities might be possible in dynamic languages (there are good tools for Lua), but require a bit more efforts, I think, and might be less thorough. On the other hand, a less verbose and less rigid syntax requires less typing (on keyboard!) anyway... :-)

Now, I mostly coded in statically typed languages for a living, and I don't have much experience in large programs written in dynamically typed languages, so my view is biased. But it is not a bashing of the dynamic languages, for sure! ;-)

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --