4 ms·
when I read an article like this and come to different conclusions, it makes me question if I understood it correctly. I have been bitten more than most by the
by willvarfar 7y ago
when I read an article like this and come to different conclusions, it makes me question if I understood it correctly.
I have been bitten more than most by the 16-bit char. I completely agree with the modern popular opinion that strings should be made from grapheme clusters, or failing that, codepoints.
But I get confused when the author uses the example of int, and then we run into problems. One confusion I have is how the author says that a method naming scheme is not operator overloading, when actually that's how it is always done in the languages I can name. Another confusion I have is that if primitive int and Integer merge into Int, then we have problems with null?
I've been a bit involved with the Mill CPU effort, and lets not go off on a tangent about that, but one thing in there that is a thing of beauty is the Not-A-Result/None approach. Values have special meta-data to say if they are an error or not. So, say, dividing by zero returns a value, but that value is tagged as an error, rather than an exception being thrown. If you use this value in subsequent computation, then the error propagates. Only if you then try and do something externally visible will the error throw. 'None' is a special type of error that doesn't throw when it becomes invisible, but instead becomes a no-store. This model is excellent for the speculation inside CPUs, but I posit that it would also be a really awesome model for higher level languages too.
Imagine modelling null as 'None'; a function returns a number, except it returns None instead. This None is then used in subsequent math, and the Noneness propogates. When you try and do something with it, it just silently does nothing. Another time a function returns an overflow error, or something like that, and when you eventually try and write that to a member variable where it becomes visible to other code, there's an error thrown. I know first hand that when you internalize this, lots of error handling and checking evaporates and its a nice zen.
Personally, I wish I had a faster and statically typed Python. I love Python's infinite integers and its string handling (which I had no problem with in python2 either, so ymmv). My biggest gripe with Python in production is that it isn't statically typed.
- chrisseaton 7y ago> Another confusion I have is that if primitive int and Integer merge into Int, then we have problems with null? The author isn’t suggesting that this would be a design change that would be compatible with the current semantics of Java, so behaviour for null would change.
- willvarfar 7y agoYeap. I can think of two main uses for Integer: when you have type polymorphism (e.g. my own code often has maps of Object) or nullness. I go on to describe a different approach to nullness that suites ints, for example.
- voice_of_reason 7y ago> My biggest gripe with Python in production is that it isn't statically typed. With mypy (http://mypy-lang.org/ http://mypy-lang.org/), it could be.
- lmm 7y ago> One confusion I have is how the author says that a method naming scheme is not operator overloading, when actually that's how it is always done in the languages I can name. I think the author is drawing a distinction between allowing custom operators with custom precedence, versus allowing custom implementation of a fixed set of operators with fixed precedence. I'd agree that it's a poor choice of terminology, since we would generally call the latter "operator overloading". > Personally, I wish I had a faster and statically typed Python. I love Python's infinite integers and its string handling (which I had no problem with in python2 either, so ymmv). My biggest gripe with Python in production is that it isn't statically typed. Yeah, I loved Python until my codebases became too large to refactor safely. I've found Scala gives the best of both worlds - the mixed object/functional style is quite Python-like and the low-ceremony syntax can be used to look quite Python-like (if you avoid libraries that use a bunch of symbolic method names) - though I wish infinite integers were the default there too. (I can write literals as e.g. bi"123789890897094790" and use normal operators on them, so it's not the worst).
- yxhuvud 7y ago> Personally, I wish I had a faster and statically typed Python. Ever tried Crystal? It is more a statically type Ruby, but perhaps it would be close enough.. It don't have integers that automatically expand to bigger sizes though - it is in the process of at least getting errors on overflow on the other hand. It also don't follow your idea for the None type, but instead have union typing, meaning that a nilable integer has a type Int32 | Nil (assuming 32bit size of the integer).