Live data from Hacker News

Traps to Developers

qouteall.fun

21–30 of 113 posts

Re: Traps to Developers

#21
post #16

The part about C# volatile accesses using release-acquire ordering seems to be wrong if I read the C# docs correctly. "There is no guarantee of a single total ordering of volatile writes as seen from all threads of execution" https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...

>A volatile write operation prevents earlier memory operations on the thread from being reordered to occur after the volatile write. A volatile read operation prevents later memory operations on the thread from being reordered to occur before the volatile read Looks like release/acquire to me? A total ordering would be sequential consistency.

I think you are quoting from https://learn.microsoft.com/en-us/dotnet/api/system.threadin...

"In C#, using the volatile modifier on a field guarantees that every access to that field is a volatile memory operation"

This makes it sound like you are right and the volatile keyword has the same behaviour as the Volatile class which explicitly says it has acquire-release ordering.

But that seems to contradict "The volatile keyword doesn't provide atomicity for operations other than assignment, doesn't prevent race conditions, and doesn't provide ordering guarantees for other memory operations." from the volatile keyword documentation?

Re: Traps to Developers

#22
post #18
post #8

The first "trap" on the page says "min-width: auto makes min width determined by content", but this is false outside of flex/grid. From MDN: "For block boxes, inline boxes, inline blocks, and all table layout boxes auto resolves to 0." https://developer.mozilla.org/en-US/docs/Web/CSS/min-width

CSS cascade for text properties more or less makes sense. I have been unable to comprehend CSS layout from any perspective: page designer, implementer, user, anything. It must have someone in mind but I have no idea who I that is.

https://every-layout.dev has by far the best explanations and coherent usage of CSS I've encountered since I started doing webdev for a living in 1998.

Re: Traps to Developers

#23
post #18
post #8

The first "trap" on the page says "min-width: auto makes min width determined by content", but this is false outside of flex/grid. From MDN: "For block boxes, inline boxes, inline blocks, and all table layout boxes auto resolves to 0." https://developer.mozilla.org/en-US/docs/Web/CSS/min-width

CSS cascade for text properties more or less makes sense. I have been unable to comprehend CSS layout from any perspective: page designer, implementer, user, anything. It must have someone in mind but I have no idea who I that is.

Layout is more bazaar than cathedral. It has had many ideas mixed in by different contributors over decades.

Re: Traps to Developers

#24

Earlier quoted context omitted.

Honorable mention to [a-z], gotta be my favorite trap

What's the trap for this one? I can't think of any engine that parses this to mean anything other than the letters a through z.

It depends on its use, ultimately, but if your goal is to find a string of letters (a common use IMO), you'll want to use something like \p{L} to ensure you don't miss non-ASCII characters.

eta: fixed regex, I had typed \L, shared from my faulty memory.

Re: Traps to Developers

#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 operations and through it, effectively proscribe implementation details. Having a foreign function interface also often means implementation details cannot be changed because doing that would break backwards compatibility.

> JS use floating point for all numbers. The max accurate integer is 2⁵³−1

That is incorrect. Much larger integers can be represented exactly, for example 2¹⁰⁰.

What is true is that 2⁵³−1 is the largest integer n such that n-1, n, and n+1 can be represented exactly in an IEEE double. That, in turn, means n == n-1 and n == n+1 both will evaluate to false, as expected in ‘normal’ arithmetic.

Re: Traps to Developers

#27

Earlier quoted context omitted.

Honorable mention to [a-z], gotta be my favorite trap

What's the trap for this one? I can't think of any engine that parses this to mean anything other than the letters a through z.

In some common implementations if $LANG is set to certain values, it will fail to match some ASCII letters. This is because not all latin character using languages put Z last in the alphabet.

Try this (you probably need to enable and generate the locale first)

    echo y | LANG=lv_LV.UTF-8 grep '[a-z]'
Locales in general should be considered a "trap", just look at Windows CSV separator handling, etc.

Re: Traps to Developers

#28
This looks like not so much traps, but a list of things the author has learned.

Much of it would only apply in certain relatively narrow contexts, but the contexts aren't necessarily mentioned.

Some of it appears to be just wrong.

I guess I'm saying: I would not take this literally, but as something almost like a stream-of-consciousness.

Re: Traps to Developers

#29

Earlier quoted context omitted.

Honorable mention to [a-z], gotta be my favorite trap

What's the trap for this one? I can't think of any engine that parses this to mean anything other than the letters a through z.

[A-z] though is a fun one though as it includes a few extra symbols between upper and lowercase.

Re: Traps to Developers

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

> possibly also for C# and JS

The representation for C# is very much fixed, as it allows, and very commonly uses, direct access into the string buffer as a ReadOnlySpan or a raw char pointer, where char is the type of UTF-16 codepoints.

JS could maybe get away with it.

Post reply on HN