1

Been working with Javascript for a couple of years, and recently I've been using lua quite a lot.

My only big beef with these languages are that they use weak typing. And I'm wondering if someone has good answer to; why?

The way I personally see it, there are no advantages what so ever. My colleague suggested that it might be because strong typing would require a lot of type checks, so it would hurt performance quite a lot. But as someone who's a bit oblivious as to how compilers work, I struggle to accept this explanation.

(Sorry if this is a dumb question, I've seen a similar discussion here but I disagree with the both the question and the answer. Prototyping is just as easy to do with a language that uses strong typing.)

Community
  • 1
  • 1
birgersp
  • 3,909
  • 8
  • 39
  • 79
  • 1
    As about JavaScript, the reason could be that it was [written in 10 days](https://www.w3.org/community/webed/wiki/A_Short_History_of_JavaScript). – GOTO 0 Jan 25 '17 at 15:14
  • This question cannot be answered without a precise definition of what you mean by "weak typing" and what you mean by "scripting language". Neither one of those two terms has a agreed-upon definition. For example: I consider Ruby to be a scripting language, and I consider it to be strongly typed, according to *my* personal definition of "scripting language" and *my* personal definition of "strong typing". But I have no idea whether or not *you* consider Ruby to be a scripting language according to *your* definition, and whether or not *you* consider Ruby to be strongly typed according to *your* – Jörg W Mittag May 01 '17 at 11:37
  • … definition of those terms. – Jörg W Mittag May 01 '17 at 11:37

2 Answers2

0

Dynamic (runtime) type-checking does result in a performance hit. Keep in mind that compiled languages like C++, Java, and C# can enforce the type system at compile time (i.e. if you write code that violates the type system it won't even compile, far less run), which allows you to skip a lot of the runtime type checking you would've had to do otherwise. There is no such mechanism in scripting languages, so you'd have to do extra checking.

0

Quite apart from the performance implications, type checking requires a fairly complex set of rules which both the implementor and (to some extent) the user has to understand. Strict type checking also gets in the way of convenience even for advanced users who know what they are doing and might generally be able to put up with and even appreciate type checking for some of their variables. Indeed, some modern script languages now offer optional type checking for users who want it.

tripleee
  • 175,061
  • 34
  • 275
  • 318