4 ms·
The code you posted is incorrect and full of bugs. For example, if A is 9223372036854775807 and B is 10, then you will get the incorrect answer. Try it out if y
by ReflectedImage 3y ago
The code you posted is incorrect and full of bugs. For example, if A is 9223372036854775807 and B is 10, then you will get the incorrect answer. Try it out if you don't believe me.
Another example is A is -9223372036854775807 and B is -10. Again you will get an incorrect result.
Once you finish fixing these bugs it will be at least 100 lines long. The dynamically typed version of the code is just A + B.
"a lot of this debate just ends up being dynamic programmers who are unaccustomed to using static types at all"
Static typing is objectively the inferior approach. It's just that people are too lazy to learn how to code with two different typing systems.
Overall statically typed programmers only code at 1/3 of the speed as their dynamically typed counterparts. Of course, if you have only ever done statically typed programming, you are not going to understand how bad it is in comparsion.
- therealdrag0 3y agoThat doesn’t sound like it’s typings fault at all. That’s a language design choice. Typed languages have types that handle adding numbers of all sizes same as dynamic typing. In fact JavaScript numbers aren’t magic, they are 64bit doubles, which have their own strange behavior and special cases, many of which could be considered “incorrect”. You’re acting like dynamic typing solves problems that it doesn’t solve.
- ReflectedImage 3y agoYou have errors coming from using static types. Static typing blew up a space rocket, if you weren't aware. JavaScript is terrible because it was built over 3 decades by different competing browser vendors.
- ReflectedImage 3y agoI think we are at max reply depth but here is the trivial dynamically typed solution to the problem: https://pastebin.com/UZvB5YD1 https://pastebin.com/UZvB5YD1 It's a little bit simpler than anything you will get in an statically typed language. It works for integer and floats of any size. It even works for lists! You can't do that in a statically typed language without a ton of code.
- fennecfoxy 3y agohttps://pastebin.com/gcsNs6Sw https://pastebin.com/gcsNs6Sw Oh, look. Something that statically typed languages solves.
- ReflectedImage 3y agoThat problem is also solved by dynamically typed languages. Your IDE picks it up.
- fennecfoxy 3y agoTrue, but if I know devs and management's "last minute and underplanned" culture IDEs can be ignored.
- xorcist 3y agoIs that really a fair comparison? The dynamically typed language is also typed, probably a longint. Had the C++ example used long then these examples would be at least bug compatible. If we're discussing weakly typed languages then this argument is more valid, but that opens up to a new class of bugs strong dynamically typed languages don't have. Anyone who says the conclusion is obvious have probably not thought this through.
- ReflectedImage 3y agoNo the dynamically typed language is not typed, the variable grows in size indefinitely to fit the number. Dynamically typed languages are more powerful languages that can handle problems like this correctly.
- xorcist 3y agoThat's not something inherent to dynamic typing. If we take a specific language such as Python, that specific behaviour has changed between versions. Much too often, any discussion of typing systems often boils down to specific traits around someone's favourite language. These specifics are obviously important enough to warrant a lot of skepticism around too general conclusions from studies. Bascially we're all recounting anecdotes, so let's be honest about that. I don't doubt yours, I just don't think they necessarily reflect fundamental truths about programming.
- tome 3y agoIt's really hard to understand what you mean. Could you clarify, taking into account these two results, firstly a correct calculation from a statically typed language, Haskell, and secondly an incorrect calculation from a dynamically typed language, Python > 9223372036854775807 + 10 :: Integer 9223372036854775817 >>> numpy.int_(9223372036854775807) + 10 <stdin>:1: RuntimeWarning: overflow encountered in long_scalars -9223372036854775799