4 ms·
>Ok, you checked your pointer to see it isn't null. Then you passed it to function foo. Which passes it to function bar. Do foo and bar have to check it again?
by blablabla123 14y ago
>Ok, you checked your pointer to see it isn't null. Then you passed it to function foo. Which passes it to function bar. Do foo and bar have to check it again?
I guess not, what I'm saying is therefore: if you use a language that does a lot of stuff, you need to find a convention for your project. One may be: check for nil after assigning variables.
>costs runtime
By all means, no.
Anyway, looks like in need to try Scala and see for myself. (Scala installed: check, Hello World: check)
- Peaker 14y agoChecking nil after assigning variables is not helpful for the reason you mentioned earlier: If you check for it and it is nil where it shouldn't be -- you're merely converting one runtime error (null exception) to another (different exception). If however you use types to distinguish whether it can be nil or not, you simply eliminate the error completely at compile-time. Glad you're checking it out! I don't know Scala, I'm a Haskeller myself, but I believe it does get nulls more correctly. It might have bad old null in there too though because of Java interop.