3 ms·
In the web industry, which is the biggest part of the software industry by people employed, most developers use dynamically typed languages and very happily nev
by onion2k 12y ago
In the web industry, which is the biggest part of the software industry by people employed, most developers use dynamically typed languages and very happily never make this "fundamental" choice. Should they all resign?
- markokrajnc 12y agoNot only web industry: in Smalltalk every integer can have unlimited number of bits. On 32-bit systems internally 31 bit is used first and with overflow it automatically starts using variable size integers... There is no need to make a choice on the number of bits... Just use integers as they are in the nature...
- danbruc 12y agoDynamically typed does not mean that you don't have to think about number types - 3/2 and 3/2.0 may yield different results in dynamically typed languages. And how many web developers don't know about or are unable to decide between different number types? JavaScript type coercion is such a mess, how could you get away without thinking about types, even though number types are usually not an issue?
- benaston 12y ago"JavaScript type coercion is such a mess" - in what way? Seriously.
- danbruc 12y agoIn what way it isn't? Just look at this beauty [1] and its consequences. But probably nobody uses the equality operator anymore because it is such a mess. Less than is even more messed up [2]. [1] http://people.mozilla.org/~jorendorff/es5.html#sec-11.9.3 http://people.mozilla.org/~jorendorff/es5.html#sec-11.9.3 [2] http://strilanc.com/visualization/2014/03/27/Better-JS-Equality-Table.html http://strilanc.com/visualization/2014/03/27/Better-JS-Equal...
- nfm 12y ago`" " == 0 == false`, and `"" == 0 == false`, but `" " != ""`. `"Infinity" == Infinity`, but `"true" != true`. I could go on for a while like this.
- coldtea 12y agoAnd which of those persist if you use ===?
- tragic 12y agoNone - because === does not coerce types. Type coercion, not double-equal weirdness as such, is the gripe of the GGP. Non-transitive, inconsistent equality is nothing more than a symptom of JS's rules for implicit conversions. Language-war disclaimer: I love javascript and everything, it's a very expressive language; but a good wodge of the tooling around it nowadays is to help people avoid things like implicit type-coercion 'surprises'.
- benaston 12y agoThat is not specifically type coercion, but the behavior of the equality (==) operator in JavaScript. Type coercion in JavaScript can be very useful, for example !!('foo') is coercive and easily understood (and has an unsurprising result). Thankfully the == operator is completely optional and has a more easily understood === (identity) correspondent, making your point less about a language and more about a specific operator within a language.
- nfm 12y agoIt is type coercion. The runtime converts both operands to the same type before making the comparison (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...). This is also true of !, <, and friends. Other operators in JavaScript may behave more intuitively than ==, but I don't think you can really make a good case for JavaScript's type coercion being 'unsurprising'.
- berdario 12y agoThankfully Python fixed that discrepancy about 3/2 Anyhow, I don't agree with you: I think that getting a bug years down the road due to a too small numeric type is something that the programming language itself should avoid.... not because "developers don't ought to know it", but because mistakes happen Anyhow, even with a dynamically typed programming language like Python or Javascript you can care about the size of your numbers. Just import the array module (in Python) or use the Int32Array/Int8Array/etc. types (in Javascript)