HNHacker News
TopNewBestAskShowJobs

planede

2,063 karma · joined April 21, 2022

submissionscomments
planede··on How to unit test code that depends on time
I thinks mocks are better in C++ than in dynamic languages. In C++ you need to expose a public interface for the customization point so it can be mocked. Mocks therefore test a public interface and not implementation details. Granted, if that "public interface" is not used outside of tests then it's not much different, but I think it adds the correct amount of friction for mocking.

In dynamic languages you can mock anything, even parts that are not designed to be customizable. This indeed has the effect of calcifying implementation details, as mocks don't test a public interface. I think it's harder in this environment to stay disciplined and use mocking in moderation, as the friction to only mock public interfaces is not there.

I definitely saw this in C++ vs Python mocking, mocking tends to be way overused in Python testing.

planede··on So you want custom allocator support in your C library
Sure, that's what I was getting at. Being able to pass stateful allocators as function arguments is very flexible.
planede··on Tracking Java native memory with JDK flight recorder
If we are talking replacing the libc allocator, then something like heaptrack is worth mentioning.

https://github.com/KDE/heaptrack

planede··on So you want custom allocator support in your C library
What if the function does more than a single allocation? Imagine a library like libxml2 that can parse a whole XML document into a DOM tree. In many cases you it would be nice to just pass an arena allocator and throw away the whole DOM in one go. Unfortunately libxml2's allocator customization kinda sucks and it's not easy to do.
planede··on Trains were designed to break down after third-party repairs, hackers find
As a lone developer there is absolutely no motivation to do this and hide this decision from management.

Having said that a lone developer can come up with the idea, propose it to management with the expectation of some fat bonus. But why do this in secret?

There is just no possibility where upper management is not involved in this.

planede··on Lessons from building GitHub code search [video]
Yeah, Debian code search often works better for this purpose.
planede··on Cog: Use Python in your source files to generate pieces of code (2021)
At least with preprocessor and templates the compiler errors point to your actual source files, not to some auto-generated mess.
planede··on Cog: Use Python in your source files to generate pieces of code (2021)
Committed generated code can also be a pain. Now you invite manual changes to the generated code, which is probably a pain to maintain if you also want to maintain and reuse the generation script in parallel.
planede··on What is a zero refractive index material?
A pulse of wave is a superposition of steady-state waves. Group velocity, phase velocity and dispersion relation have one-to-one correspondence.

I agree that the phase-kick classical model is a very simplified material model, which probably breaks down in certain ways. But it does yield a dispersion relation, therefore both phase and group velocities.

planede··on What is a zero refractive index material?
> Phase kicks don't change the speed of a wave.

"Phase kicks" explain the phase velocity. The speed of a wave is the group velocity. Phase velocity is omega(k)/k, group velocity is omega'(k). So if "phase kicks" explain phase velocity sufficiently so it's valid for a range of frequencies, then it also explains group velocity by taking the derivative of the dispersion relation.

planede··on Fairphone 5: Keeping it 10/10?
It works everywhere. There is not much to do with delay on interactive content though.
planede··on Making noisy SVGs
> To reduce banding, the idea is that for each pixel, you choose between the rounded up or rounded down value semi-randomly, with a probability depending on how close you are to each value.

This oversimplifies it a bit. Most dithering algorithms are deterministic. They are based on choosing a value for a pixel, remembering the difference between the ideal and the chosen value and then spreading out that difference to surrounding pixels.

Random dithering is more commonly used in audio signals, AFAIK, not much in image processing.

planede··on Untrusted Device Encryption

  > The untrusted device will be able to observe:
  >   File sizes
  >   Which parts of files are changed by the other devices and when
I know that cryfs[1] is resilient to at least the first of these, and possibly the second as well. I don't know if cryfs allows to modify the base directory while the filesystem is online, if it does then it might already be a better solution for syncthing, if you only care about Linux.

On the flip side syncthing could incorporate cryfs's base directory format instead of their home-grown one.

[1] https://www.cryfs.org/

edit:

https://www.cryfs.org/tutorial says the following about concurrent access to the basedir:

"Warning! Never access the file system from two devices at the same time. This can corrupt your file system. When switching devices, always make sure to stop CryFS on the first device, let Dropbox finish synchronization, and then start CryFS on the second device. There are some ideas on how future versions of CryFS could allow for concurrent access, but in the current version this is not safe."

Too bad.

planede··on For processing strings, streams in C++ can be slow
I hear you, however something like streambuf is kinda necessary for a type-erased interface for input/output of trivial objects. The C alternative is FILE*, which isn't much better and isn't as customizable either.

I agree that the formatting could have been done better, and that part is indeed handled much better in fmt, although personally I dislike format strings. It's much better than printf, granted.

planede··on LogoFAIL: Secure Boot bypass with manipulated boot logos
Does UEFI have any mechanism to run some firmware code with reduced privileges? For example an image parser?
planede··on LogoFAIL: Secure Boot bypass with manipulated boot logos
The attack defeats the whole premise of security in "secure boot". It's high impact in relation to that.

As a user I don't care too much about "secure boot" and its threat model, and I assume you don't either.

planede··on A Brainfuck interpreter written in PostScript
Postscript is actually surprisingly approachable. It's quite easy to implement logo-like "turtle graphics" and draw fractals in it.
planede··on Polish trains lock up when serviced in third-party workshops
How would copyright be in-scope at all? At worst this infringes EULA.
planede··on Windows users report appearance of unwanted HP app
They renamed "My Computer" a while ago.
planede··on How to ripen and store avocados
I guess the indentation only interacts with the little oxygen that is trapped there, which might not be enough to substantially brown it.
planede··on GIMP 3.0 has a release schedule
https://developer.gimp.org/core/roadmap/#gimp-30-development...

work in progress

planede··on Ubuntu squeezes more performance than Windows 11 on new AMD Zen 4 Threadripper
Nvidia cards being unreliable on Linux make me choose an other card instead.
planede··on Ubuntu squeezes more performance than Windows 11 on new AMD Zen 4 Threadripper
Which Wayland compositor? Does it matter? I recently got an Intel iGPU + Nvidia dGPU machine.
planede··on Ubuntu squeezes more performance than Windows 11 on new AMD Zen 4 Threadripper
I find Debian unstable to be a perfectly stable rolling release distro. Unfortunate naming.
planede··on Ubuntu squeezes more performance than Windows 11 on new AMD Zen 4 Threadripper
Apart from Nvidia, this feels like a non-issue for me nowadays.
planede··on Setenv Is Not Thread Safe and C Doesn't Want to Fix It
So you make it thread-safe. Now what? Just because you don't get a data-race or undefined behavior, it doesn't make setenv/getenv usable across threads without any synchronization anyway.

My take on it is that global mutable state is owned by the application, library code should never ever mutate it. Applies to the environment variables, stdout/stderr, locale.

The application must ensure that when these are mutated they are not read concurrently by an other thread. As external libraries rarely document the exact conditions when they read environment variables, the best is to only update the environment when no other thread is running. The absolute best is to avoid mutating it altogether.

planede··on Setenv Is Not Thread Safe and C Doesn't Want to Fix It
Maybe the dlopen issue could be hacked around by dlmopen and injecting getenv and setenv symbols that access a different environment variable list than the application's.
planede··on Google News is shutting down purchased magazine content, offering refunds
You can destroy information with noise. Accurate information about the conflicts (or anything) is also available in the digits of pi.
planede··on Curves and L-Systems
There is this variation of the dragon curve:

  order: 10
  axiom: FX
  angle: 90
  
  X -> X+FYF-
  Y -> +FXF-Y
This avoids the self-intersections (like a similar depiction of the Hilbert and Gosper curves), yet it remains relatively simple, and reveals more of the structure inside the bulk of the curve.

It's especially pretty when completed into a twin-dragon with the axiom: FX+F+FX+F+ and same rules as above.

planede··on i386 Assembly Language trick for storing data in .text
My impression was that pipelined processors pipeline across CALL instructions. They even speculate across indirect calls. How you describe this is as if there was a significant penalty to reading EIP or calling a function on a pipelined processor, but I don't think that's true.
← PreviousPage 7 of 24Next →