Live data from Hacker News

Traps to Developers

qouteall.fun

91–100 of 113 posts

Re: Traps to Developers

#91

> Division is much slower than multiplication (unless using approximation). Dividing many numbers with one number can be optimized by firstly computing reciprocal then multiply by reciprocal. Is this a general fact or specific to a language?

It's hardware-level - division requires more CPU cycles than multiplication on most processor architectures, making this optimization pattern relevant across virtually all programming languages.

Re: Traps to Developers

#92

The 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 searching, all I find is scattered questions and comments over the last few years looking for modern equivalents are a handful of recommendations for games that are no longer developed or are defunct.

There's clear prior evidence of both success and lack of modern supply. Want to have a minimally minor successful game with established nostalgic audience? Make a new version of EV that is that game at its core. Don't be fancy, just do the thing Ambrosia did. Expand from there.

The simple model is look forward, and also look back. The first itch is small. For yourself. Find some others with a similar itch.

The hard part is pushing your idea into something more people want. That's where pg's 2013 article comes in to play. That's the hard part.

But that leaves a huge space between 0 and 10 where someone can find a successful niche.

Hell I've thought about trying to make a modern EV. It's tantalizing. But I've never made a game in my life. Ok I've rewritten Game of Life a lot. Good concept to try new ideas with. But the amount of work for a solo dev trying to recapture that original magic with no background in game dev is daunting.

Re: Traps to Developers

#93
post #37

> 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…

In Kotlin this would already be a compile error, no need for another annotation.

Re: Traps to Developers

#94
post #73

Earlier quoted context omitted.

Often people use optional or nullable types as a convenient approximation to an Either type.

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 would be natural here, although of course alternative representations are possible.

Re: Traps to Developers

#95

Earlier 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.

The None branch of each level of a nested Optional has a different meaning.

But typically it boils down to either you have the data or you don't. It's a subtle difference which I argue you can live without.

Re: Traps to Developers

#96
post #73

Earlier quoted context omitted.

Often people use optional or nullable types as a convenient approximation to an Either type.

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.

In JSON/REST API bindings, where a deserializer maps JSON to language-native object/struct type, I'll often need to know the difference between:

    {}
and

    { "foo": null }
and

    { "foo": 42 }
So I'll represent that (in e.g. Rust) as:

    struct Whatever {
        foo: Option>,
    }
None means not present, Some(None) means present but null, and Some(Some(42)) means present with a value.

I'll often use this in PATCH endpoints, where not-present means to leave the current value alone, null means to unset it, and a value means to set to that value.

Re: Traps to Developers

#97
post #55
post #25

> Java, C# and JS use UTF-16-like encoding for in-memory string That’s incorrect for Java, possibly also for C# and JS. In any language where strings are opaque enough types [1], the in-memory representation is an implementation detail. Java has been such a language since release 9 ( https://openjdk.org/jeps/254 ) [1] The ‘enough’ is because some languages have fully opaque types, but specify efficiency of some opera…

> > Java, C# and JS use UTF-16-like encoding for in-memory string > > That’s incorrect for Java, Maybe so, technically, but if you Base64 encode a string in a language that uses UTF-8 (or another UTF-16 with another endian) and decode it in Java, Java's UTF-16 representation will be the problem you will be dealing with.

That's why when you are constructing a String with a byte array, you always, always, always use the constructor that also takes a character set.

Re: Traps to Developers

#98
post #44

Earlier quoted context omitted.

A mutex would be the most trivial example. I don't believe that is possible to implement, in the general case, with only acquire-release. Sequential consistency mostly become relevant when you have more than two threads interacting with both reads and writes. However, if you only have single-consumer (i.e. only one thread reading) or single-producer (i.e. only one thread writing) then the acquire-release semantics en…

> A mutex would be the most trivial example. I don't believe that is possible to implement, in the general case, with only acquire-release. Wait, what? So you're saying this spinlock is buggy? What's the bug? https://en.cppreference.com/w/cpp/atomic/atomic_flag.html

No, sorry. I was just remembering where I've typically seen sequential consistency being used. For instance, Peterson's algorithm was what I had in mind. Spinlock is indeed a good example (although a terrible algorithm which I hope you haven't seen used in practice) of a mutex algorithm which only requires acquire-release.

Re: Traps to Developers

#99
post #88
post #43

Earlier quoted context omitted.

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.

It works quite well in Scala, which still tolerates nulls due to being in the JVM and having Java interop. Realistically nothing in the language is going to return null, so the only time you might have to care is when you call Java classes, and all of the Java standard library comes scalaified into having no nulls. And yes, there are enough monadic behavior in the standard library to make Option and Either quite usef…

> because the language has such love for backwards compatibility

I still remember when Java 9 introduced modules. And I’m currently pulling my hair because Java 21 renamed all javax.* into jakarta.* because Javax was a trademark of Oracle, and all libs now require a “-jakartax” version for JDK 21.

But somehow I still have to deal with nulls everywhere and erased-at-runtime generics because Java loves backwards compatibility so much. The simple fact all libs released a “-jakartax” proves the entire ecosystem is fully maintained (plus CVEs means unmaintained libs aren’t allowed in production), so they could very well release a -jdk25 version with non-null types.

Re: Traps to Developers

#100
post #43
post #37

> 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.

You're far from alone, it does make it a tiny bit easier to see which functions are expected to return null, but that's about it and messing around with it always feels like wasted effort.
Post reply on HN