Earlier quoted context omitted.
I still don't see why it would be a problem merging then down even when used like an either. If there is no value then there is no value.
How about a situation where the inner Optional is acquired from another system or database, and the outer Optional > is a local cache of the value. If the outer Optional is null, then you need to query the other system. If the outer Optional is filled and the inner Optional is null, then you know that the other system explicitly has no value for the data item, and can skip the query. Seems like using nested optionals…
Traps to Developers
101–110 of 113 posts
Re: Traps to Developers
#102> A method that returns Optional may return null. projects that do this drive me bananas If I had the emotional energy, I'd open a JEP for a new @java.lang.NonNullReference and any type annotated with it would be a compiler error to assign null to it public interface Alpha {} @java.lang.NonNullReference public interface Beta {} Alpha a = null; // ok Beta b = null; // compiler error javac will tolerate this Beta b; if…
I question the wisdom of even having Optional in a language with nulls. It would raise some eyebrows if a function in Python returned an Optional type object rather than T | None. You have to do a check either way unless you're doing some cute monad-y stuff.
Re: Traps to Developers
#103> Blur does not consider ambient things.
Need to make that backdrop blur.
> Whitespace collapse. HTML Whitespace is Broken
I always hated that article title. It’s not broken, it’s just different from what you occasionally expected, mostly for very good reasons that let it do what you expected most of the time. I also disagreed with some significant other parts of it: https://news.ycombinator.com/item?id=42971415.
> Two concepts: code point (rune), grapheme cluster:
I have problems with this lot.
Firstly: add code units. When dealing with UTF-8 and you can access individual bytes, they’re UTF-8 code units. When dealing with UTF-16 and you can access 16-bit values, including surrogates, they’re UTF-16 code units.
Secondly: don’t talk about code points in general, talk about scalar values, which are what code points would have been were it not for that accursèd abomination UTF-16. Specifically, scalar values excludes the surrogate code points.
Sensible things work with scalar values. Python is the only thing I can think of that gets this wrong: its strings are sequences of code points, so you can represent lone surrogates (representable in neither UTF-8 nor UTF-16). This is so stupid.
Thirdly: ditch the alias “rune”, Go invented it and it never caught on. I don’t know of anything else that uses the term (though maybe a few things do), and the term rune gets used for other unrelated things (e.g. in Svelte 5).
> Some text files have byte order mark (BOM) at the beginning. For example, EF BB BF is a BOM that denotes the file is in UTF-8 encoding. It's mainly used in Windows. Some non-Windows software does not handle BOM.
BOM was about endianness, and U+FEFF. Link to https://en.wikipedia.org/wiki/Byte_order_mark. It made sense in UTF-16 and UTF-32: for UTF-16, if the file starts with FE FF it’s UTF-16BE, if FF FE it’s UTF-16LE. UTF-8 application of it was always a mess, never really caught on, and I think can fairly be considered completely obsolete now: the typical person or software will never encounter it. Very little software will actually handle it any more. Fortunately, it doesn’t tend to matter much: U+FEFF is the BOM for a reason, it’s ZERO WIDTH NO-BREAK SPACE.
> YAML:
I’d add “disallows Tab indentation”. It’s the only thing I can immediately think of that’s like that. (Make is roughly the opposite, recipe lines having to start with a single Tab. Python doesn’t let you mix spaces and tabs. These are all I can immediately think of.)
Re: Traps to Developers
#104https://gekk.info/articles/traceroute.htm
(If it's outdated I'm curious if anyone knows relevant updates?)
Re: Traps to Developers
#105Earlier quoted context omitted.
Maybe this is cute monady stuff, but there isn't an equivalent to Optional > with only null/None. You usually don't directly write that, but you might incidentally instantiate that type when composing generic code, or a container/function won't allow nulls.
In what context would you not want to treat Optional.of(null) and null as the same? It shouldn't be a big deal.
Re: Traps to Developers
#106Largely a good listicle. Some feedback: > Unicode unification. Different characters in different language use the same code point. Different languages' font variants render the same code point differently. 語 This isn't a trap. The given example character means the same thing in Chinese and Japanese, and the Japanese version was imported from China. People from both languages recognize both font variants as the same c…
A character that carries the same concept yes. A mere "font variant" no. It's absolutely a trap to think that you can safely replace one character with another just because they have the same unicode codepoint; Japanese people will avoid your product if you do this.
Re: Traps to Developers
#107> Some routers and firewall silently kill idle TCP connections without telling application. Some code (like HTTP client libraries, database clients) keep a pool of TCP connections for reuse, which can be silently invalidated. To solve it you can configure system TCP keepalive. For HTTP you can use Connection: keep-alive Keep-Alive: timeout=30, max=1000 header. Once a TCP connection has been established there is no st…
Mobile operating systems can use application-level keep-alive packets, because those can be easily attributed to individual applications: an applications receives a TCP/UDP packet during low-power CPU sleep mode, asks system to wake up (by e.g. taking a wake-lock), and the system takes note who caused the wake-up. TCP Keep-Alive happens below application level, so it may be disabled, even when application can still be reached.
Re: Traps to Developers
#108The biggest trap of all: building things that no one, including yourself, wants
I would agree on the self part. But otherwise this point of view is distinctly in contrast with the recently republished "work on things that don't scale" article from pg. Also as a corollary, I was thinking about games from the 90s I spent hundreds of hours playing back then earlier today. Bolo and Escape Velocity in particular come to mind. They were "simple" games with immense depth. But after some fruitless searc…
Re: Traps to Developers
#109> Python: - Default argument is a stored value that will not be re-created on every call. PSA for anyone working with datetime variables!
Re: Traps to Developers
#110Earlier quoted context omitted.
In what context would you not want to treat Optional.of(null) and null as the same? It shouldn't be a big deal.
In any context where you're combining two things that have different kinds of absence. E.g. if you have a cache around an expensive API call, you want to be able to cache null results from that API call, so you need a distinction between "not in the cache" and "cache entry where the API returned null".