4 ms·
I don't really feel like this is an argument against constructors but perhaps an argument that some language designs are better than others... For example Go d
by meddlepal 7y ago
I don't really feel like this is an argument against constructors but perhaps an argument that some language designs are better than others...
For example Go does not have constructors and it's very easy to get a nil deref error if you aren't careful.
- stinos 7y agoI don't think the author's intent was to argue completely against cnstructors. At least to me this reads more like: here are some pros, here are some cons. But you're right: in some languages some aspects are better than in others. Take the vector constructor example for instance: that's not really just a case against constructors. The exact same, i.e. not knowing which argument does what, can be a problem in any language with no named arguments, and not just for constructors but for anything which takes arguments. But is that a problem? Do I really need to know the order of arguments of everything? Nope, it's 2019, my editor and internet know the answer.
- Sharlin 7y agoThe point is that with (unnamed) constructors the problem is exacerbated. There’s a reason functions are named descriptively.
- skybrian 7y agoAlthough it doesn't have constructors, Go has zero values. I can't find a reference, but I believe this is so that you can create arrays with any element type and they can be automatically initialized? Naturally, if pointers must have a zero value (like any other type), nil is a logical choice. The pervasive support for zero values (or not) seems like a pretty fundamental design choice with far-reaching consequences. It works okay when there is a logical use for a zero value (as encouraged in Go) and is awkward otherwise. If you don't have zero values, you end up with something like Rust's array initialization syntax: https://www.joshmcguigan.com/blog/array-initialization-rust/ https://www.joshmcguigan.com/blog/array-initialization-rust/