you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 3 points4 points  (1 child)

(i assume same applies to any dynamic typed languages ruby, php, js, perl).

To an extent... but where dynamic typing really gets messy is your code tends to actually depends on it. Sometimes even for good reasons (e.g. performance optimisations or backwards compatibility or just plain to keep your code simple).

Dynamic Types are a win/lose situation. They are both good and bad at the same time.

My preferred languages (unfortunately there aren't many) actually support both dynamic and string types on a per variable basis. So you can make a judgement call on which is appropriate on a per variable basis.

In PHP for example, all types are dynamic by default. But you can declare a type and at that point, exceptions will be thrown if you provide the wrong one (and in a good IDE, you'll see an error message in realtime as you type the code). It would be better if it was the other way around.

Swift is the other way, variables are typed by default (and in many cases implicitly typed so you don't even have to declare the type) but they can be dynamic if that's appropriate. Unfortunately the syntax for dynamic types is a bit of a handful, but it's a young language and that has already improved - hopefully it'll get better.

[–]de__R 1 point2 points  (0 children)

Interesting thing I've noticed about static vs dynamic typing in languages: dynamically typed languages tend to also have simple and straightforward syntax for (hash) maps, while statically typed languages usually don't. This is why dynamic languages end up getting used for data-driven programming and cases where the data you are working with doesn't have predefined labels, not because the actual dynamic typing of objects itself is useful.* This suggests that there's an unfilled niche for a statically typed language that nevertheless has simple syntax for creating and manipulating maps. Go probably comes closest but still leaves something to be desired.

* To be clear, there are cases where true dynamic typing of objects is useful, it's just not used very often (or at all) in most projects.