HNHacker News
TopNewBestAskShowJobs

david2ndaccount

1,196 karma · joined February 28, 2020

blog: https://www.davidpriver.com
submissionscomments
david2ndaccount··on I write type-safe generic data structures in C
The “typeof on old compilers” section contains the code:

         (list)->payload = (item); /* just for type checking */\
That is not a no-op. That is overwriting the list head with your (item). Did you mean to wrap it in an `if(0)`?
david2ndaccount··on Variadic Switch
In D, you can just do a static foreach over a sequence to generate case labels:

https://d.godbolt.org/z/PxWEW14K1

david2ndaccount··on DoorDash to acquire Deliveroo
Don’t ignore food addiction, the app turns into a button you can press on your phone and in a bit you’ll have a dopamine hit from the food. You don’t have to get dressed or confront the reality of your situation.
david2ndaccount··on Driving Compilers (2023)
That’s not the point of hello world. It’s not to be as small a valid program as possible. It’s to be a small program that also exercises the needed functionality for using the tool usefully. All of the exercises following that hello world need formatted text, so introducing puts would just add confusion and wouldn’t verify that you have a working printf.
david2ndaccount··on Converting a Git repo from tabs to spaces (2016)
Tabs are a control character and have no business being in a text file. Do you use ascii record separator characters too?
david2ndaccount··on An Introduction to Modern CMake
You’re switching to the build system of a different, pre 1.0 programming language that has frequent breaking changes?
david2ndaccount··on Better typography with text-wrap pretty
This does actually look a lot better. Using the inspector to toggle it on and off, “pretty” does look a lot prettier.
david2ndaccount··on WorstFit: Unveiling Hidden Transformers in Windows ANSI
Backslash is a valid path character (you can use / or \ as the path separator on windows) so if the backslash isn’t actually escaping anything it is left as-is.
david2ndaccount··on MacKenzie Scott donates over $2B in 2024 to 199 organizations
let not thy left hand know what thy right hand doeth
david2ndaccount··on Show HN: A portable hash map in C
If you’re interested in this, I wrote a blogpost on a simple c hash table without deletion.

https://www.davidpriver.com/c-hash-table.html

david2ndaccount··on OpenAI, Google and Anthropic are struggling to build more advanced AI
Without a non-linear activation function, chaining perceptrons together is equivalent to one large perceptron.
david2ndaccount··on Don't return named tuples in new APIs
You can have methods with NamedTuple
david2ndaccount··on Type-erased generic functions for C: A modest non-proposal
I wrote a blogpost describing this technique. https://www.davidpriver.com/ctemplates.html
david2ndaccount··on The 4-chan Go programmer
Somewhat a reference to https://wiki.c2.com/?ThreeStarProgrammer
david2ndaccount··on Tony Hawk's Pro Strcpy
Only msvc provides strcpy_s and they don’t conform to the standard. Other libcs don’t provide it. Ignore everything from Annex K and write your own wrappers around memcpy. You should always know the size of your buffers.
david2ndaccount··on Tony Hawk's Pro Strcpy
Use memcpy and do the size check yourself beforehand (taking the appropriate action if it doesn’t fit). Avoid any function starting with str except for strlen. Prefer pointer+length instead of relying on nul-terminated strings.
david2ndaccount··on Tony Hawk's Pro Strcpy
The correct thing to do is to use memcpy and to know the size of both the destination buffer and the source buffer. If the source buffer won’t fit, then you need to take an application-specific action (is truncation ok? do you have to abort the whole operation? Do you re-alloc the destination buffer? etc.) strncpy almost always does the wrong thing.
david2ndaccount··on Porffor: A from-scratch experimental ahead-of-time JS engine
With a string literal it works, with a dynamic string it just gives an undefined reference error to eval.
david2ndaccount··on C Macro Reflection in Zig
I wrote a blogpost showing how you could do a similar thing in D with ImportC.

https://www.davidpriver.com/C-macro-reflection-in-D.html

david2ndaccount··on How Conditional Breakpoints Work
Are there any compilers that insert nops between real instructions in debug builds to allow inserting a jump to code to evaluate the expression? Conditional breakpoints are so slow it’s usually faster to add an if with the condition and recompile.
david2ndaccount··on Reasons to use your shell's job control
If a program is not responding to ctrl-c, sometimes ctrl-\ (which sends sigquit instead of sigint) can kill it.
david2ndaccount··on Code reviews do find bugs
In my experience, code reviews catch a lot of bugs. However, if you find yourself catching the same kind of bugs over and over again in review you should be finding ways to catch them automatically without involving a reviewer (static analysis, tests, linters, etc.)
david2ndaccount··on Microfeatures I love in blogs and personal websites
Feels like many of these features should just be built into the browser. Why can’t the browser assemble a table of contents based on header hierarchy? Isn’t that the point of the number in h1-h6? Why aren’t elements with ids easy to link to by default? Add a “copy-link-to” to the standard context menu in the browser. Etc.
david2ndaccount··on Work begins on a $12B high-speed rail line between Las Vegas and Los Angeles
You could expand the number of lanes on I15 (like it is on the Nevada side) for a small fraction of what this project would cost.
david2ndaccount··on If Inheritance is so bad, why does everyone use it?
Python also has protocols: https://typing.readthedocs.io/en/latest/spec/protocol.html#p...
david2ndaccount··on Alexei Navalny has died
Ukraine is not part of NATO, so how has push come to shove?
david2ndaccount··on Physical cash is dying–and you don't need to be a conspiracist to worry
The issues with physical currency are almost entirely self-inflicted. Governments should retire the smallest denominations and introduce larger coins/bills. In the US, all of the coins are worth so little that the only practical coin is the rare half-dollar. Retire all of those worthless coins, require transactions be rounded to the nearest half-dollar or dollar, and issues with physical currency for the user will go away.

Now of course, the government won’t do this as they want physical currency to be inconvenient so they can track you and deny you access to your own money when they find it convenient. We’re in an era of growing authoritarianism. Hopefully we survive this one.

david2ndaccount··on Why Zig When There Is Already C++, D, and Rust?
Since you’re updating it anyway, the very first example says "D has @property functions, which are methods that you call with what looks like field access, so in the above example, c.d might call a function.”

It is true that `c.d` might call a function, but it’s not because of @property functions (which exist but are discouraged), it’s because the parens are optional to call a function/method if there are no arguments.

david2ndaccount··on Memory leak proof every C program
This is not thread safe.
david2ndaccount··on Hasbro laying off Wizards of the Coast staff is baffling
I regret to inform you that was released in 2014, almost a decade ago.
← PreviousPage 2 of 10Next →