3 ms·
> The reference of default(A) isn't something that's passed around - yes the method you dispatch to has access to `this`, but what's the point of A: declaring a
by lmm 9y ago
> The reference of default(A) isn't something that's passed around - yes the method you dispatch to has access to `this`, but what's the point of A: declaring a variable in a 'class instance' and B: using it when it's in an invalid state?
It's not something you'd deliberately do, but in any decent-sized codebase, everything the language permits will happen. If it's possible to exclude a given pitfall with a simple, local lint rule then you might be able to avoid it, but manual review of anything that can happen at a distance is doomed to failure.
> I don't call `((string)null).ToString()` because it's fucking stupid. But I assume in your world that means C# can't do method dispatch by reference?
Unless you can use a very simple set of local rules to avoid having that happen, yes. Fortunately, there is such a set of rules you can follow (namely never writing null, never using constructs that return null, and checking the return values of library calls for null immediately) and so null (barely) doesn't destroy the language completely.
> Just because somebody can do something stupid doesn't devalue any particular technique that requires you to not do the stupid thing.
If your technique makes it impossible to use simple rules to avoid doing the stupid thing, then yes, that does devalue the technique. Because at that point having the stupid thing happen in your codebase is just inevitable.
> Otherwise, you may as well delete C# as a language - because it's trivially easy to do stupid things.
I already did, thanks.
> In fact software engineering wouldn't even have gotten off the ground if that was a pre-requisite.
Nonsense. Typed lambda calculi predate mechanical computers and don't allow you to do anything stupid. We could've built software engineering on them.
> But clearly people do produce software in it - which proves your arguments wrong.
People produce software in C#, but it takes more effort and has higher defect rates than doing so in Haskell-like languages.
> Show me where it was mentioned in the original comment about safety? Not there is it.
It's implicit because a) Haskell is a safe-by-default language b) return type polymorphism without safety is completely trivial. In e.g. Python you can just have Concat return "", [], or something else; likewise you can do the same in C# if you're happy to cast. So clearly moomin can't miss just being able to have a function that returns "" or [], because what language could they possibly be working in where that would be impossible or even at all difficult?
> That is now safe in that `Concat` can't be implemented without the `struct` constraint, the code will fail to compile. Also the types that implement `Monoid<MA, A>` must be structs.
But a) I have to allow "default(MA)" expressions in my program, which means I have no way to ban the unsafe use of default() b) nothing stops an implementation of Monoid<MA, A> being a struct that contains a reference, in which case that reference will be null when the struct is initialized with default(). It doesn't solve the problem at all.