Earlier quoted context omitted.
so, interface{}
Can you iterate through methods and fields with interface{}? I find great value in being able to go to untyped style code at will.
Typing Is Hard
121–130 of 134 posts
Re: Typing Is Hard
#122Earlier quoted context omitted.
On the contrary, I find myself more productive in languages that do not have pervasive null because then I don't have to manually reason about which values might be null.
People build huge programs in untyped languages, reasoning about null is trivial in comparison. The cost of not having null is that all initialization and generic code gets much harder to write and work with, the benefit is that once in a blue moon you get a hard to debug null pointer error. I've worked as a software engineer at large companies for years and never had a hard to debug null pointer error, so at least t…
So? People build huge programs in typed languages as well. Whether people do something one way says nothing about how that approach compares to others.
> The cost of not having null is that all initialization and generic code gets much harder to write and work with
Could you provide examples of how lack of a null value makes these so much harder?
> the benefit is that once in a blue moon you get a hard to debug null pointer error
This is like saying that the only drawback to not having smart pointers in C++ is that once in a blue moon you get a hard to debug segfault. Sure, segfaults may be more common when working with raw pointers, but there are also substantial drawbacks in terms of mental overhead due to potential uncertainties about ownership/lifetimes.
In that vein, NPE/NREs are not the only drawback to a type system with null; the additional state space means mental overhead for the programmer and an increased risk of mistakes.
In addition, introducing universal nullability into a type system entails performance penalties. Null increases the state space of a given type, so if a type uses all of its bits (e.g., int) you need to introduce indirections (java.lang.Integer) or increase the size of the type (C# Nullable/int?) to shoehorn in a null value.
> Instead of just cleanly solving a few key issues they recreate a programming language in their types and even worse they force you to use said programming language if you want to code.
I'm not sure what you're trying to get at here. This seems to be a criticism of generics/similar mechanisms, but you seem to be fine with C#/similar type systems, which has generics and makes use of them?
What's especially confusing is that type systems with generics and null are precisely equivalent to type systems with generics without null, as all instances of nullable types can be replaced with Option/Optional/Nullable/etc. (with appropriate sugar for other operations, of course). So I'm a little lost as to what the problem is.
Re: Typing Is Hard
#123Earlier quoted context omitted.
> reasoning about null is trivial in comparison So trivial that its creator called it the "billion dollar mistake" and if I had $1 for every NPE I saw in production I'd be a rich man.
When you have a hammer everything looks like a nail. A language theorist trying to fix issues will of course look at changing the language first, doesn't mean he is right.
Re: Typing Is Hard
#124Earlier quoted context omitted.
> infloop I had never seen this word before, and while I assume it's probably short for "infinite loop", I initially parsed it as "in-floop", as opposed to "out-floop".
Yep, correct! Thanks :-) Btw i love "out-floop" and I'm going to try to find applications for it.
EDIT: though, in that context, I would parse "out-floop" as a transitive verb meaning "to FlooP more, to a greater extent, or faster, than ", rendering its opposite actually "under-floop".
Re: Typing Is Hard
#125Earlier quoted context omitted.
And yet medical mistakes occur pretty frequently. "We removed the wrong kidney" and the like.
Off-by-one errors occur frequently in programming, and static typing does nothing to prevent them, since n and n+1 are always of the same type.
Re: Typing Is Hard
#126Earlier quoted context omitted.
Off-by-one errors occur frequently in programming, and static typing does nothing to prevent them, since n and n+1 are always of the same type.
That's correct, but seems irrelevant?
In fact, I would argue that static typing encourages developers to define more complex function interfaces which creates stronger coupling between components in the code and this leads to instances being passed around/shared between more different files and this is more likely to lead to unpredictable mutations of those instances' state. It makes it easier for developers to neglect good separation of concerns.
Dynamic languages make it more difficult to keep track of complex instances between different functions and files so they encourage developers to pass more primitive 'pass by value' arguments; this results in looser coupling between the components.
Dynamic languages encourage more modular, more interchangeable code. This is why the most popular package managers of all time are based on dynamic languages like JavaScript (npm) or Ruby (RubyGems) and not on statically typed languages; it's not a coincidence.
Re: Typing Is Hard
#127Static typing is a learning tool for junior level developers. Like training wheels on a bike. After 10 years or so of programming experience, the training wheels need to come off. People's attitude towards static vs dynamic typing would make a great topic for interview questions to weed out junior devs. Senior recruiter: "How do you feel about TypeScript?" Candidate: "I like it. It helps ensure that I don't accidenta…
that's the dumbest thing i've read today, grats
Re: Typing Is Hard
#128Earlier quoted context omitted.
Why do you think protective equipment is required in some professions? Is it because workers don't know their job? Anyway, explicit static typing 1. detects errors at compile time 2. provides documentation 3. makes programs run faster.
Protective equipment is typically used to protect people, not products. 1. Tests detect errors at runtime. Typing is completely redundant when you have even half-decent tests. 2. Comments, good variable and function names provides documentation too. 3. Not really. TypeScript is not faster than JavaScript for example. Even in certain cases where they are faster (e.g. comparing C/C++ with JavaScript), the max speedup i…
Re: Typing Is Hard
#129Earlier quoted context omitted.
What you use the word “type” for is a nominal type and your shapes are structural types. The utility and different trade offs between nominal and structural types were explored a lot back in the 90s.
Nominal types are on Typescript's roadmap: https://github.com/Microsoft/TypeScript/wiki/Roadmap Side note: An Introduction to Nominal TypeScript: What are nominal types and why should I use them? : https://medium.com/better-programming/nominal-typescript-eee...
Re: Typing Is Hard
#130Earlier quoted context omitted.
Typescript taught me that I actually don’t care about types and all I care about is the shape of data. In most cases I think of types/interfaces in Typescript as strict data definitions. A function takes in a collection of data; as long as the data matches the shape I expect, don’t care what the data represents.
What you use the word “type” for is a nominal type and your shapes are structural types. The utility and different trade offs between nominal and structural types were explored a lot back in the 90s.