HNHacker News
TopNewBestAskShowJobs

Panzerschrek

465 karma · joined September 10, 2025

submissionscomments
Panzerschrek··on Type Safe Generic Data Structures in C (2025)
> For anything more demanding it's horrifically bloated and bad

C++ containers are designed for average demands. If you need something more specific, you can always use an alternative implementation. And it's better than messing with macros in pure C.

> you have to deal with RAII

What's problematic with it?

> implicit allocations

Allocations aren't implicit. It's usually clear from the documentation where allocation takes place (like in concatenating strings or copying strings).

> unexpected mutation (invalidation)

It's not the case with standard library containers. Mutating methods aren't const-qualified, so that it's clear where mutation can take place. And in C++ it's strictly recommended to mark as const everything in regular user code which shouldn't be mutated.

Panzerschrek··on Type Safe Generic Data Structures in C (2025)
> the mess in C++ is way worse

What is mess in C++? Yes, it has some shady parts and is more complex than C, but this complexity provides expressiveness and type safety. And you can always use only features from C++ you find useful.

> also contribute to projects that introduce C++ into a C code base, and I really wish they hadn't done this.

What is problematic in these projects other than unfamiliarity of C++ for developers previously used only C?

Panzerschrek··on Type Safe Generic Data Structures in C (2025)
I don't understand people reinventing macro-based hacks in C to achieve what was achieved in other languages many years ago. Why not using C++, for example? It's available almost everywhere, introducing its usage in an existing C codebase is pretty simple. Sure, C++ has its own downsides, but is it better to create mess with macros in C rather then using exiting language facilities and standard library containers provided by C++?
Panzerschrek··on TurboPython – A Python-to-C++ Compiler
This example looks interesting:

  def first(items: list[Reading]) -> Reading:    
      return items[0]          # a reference into the caller's list
How the compiler knows and checks if the returning reference is derived from one of arguments? What if a function returning a reference has more than one parameter? I my language I needed to implement a whole notation to allow describing relations between parameters and returned references, has TurboPython something similar?
Panzerschrek··on TurboPython – A Python-to-C++ Compiler
Nice approach for memory safety! I have my own memory-safe programming language (see my submissions), but it has syntax similar to C++. Doing so with Python-like syntax and other Python-like elements seems for me to be a little bit unusual.
Panzerschrek··on Why didn't we get GPT-2 in 2005?
Running GPT-2 after it's trained wasn't as computationally-easy as nowadays. So, you not only need the best supercomputer in the world to train it, but also a datacenter with similar computational power to run enough instances to make it useful.
Panzerschrek··on Strange Parodies of Atari 2600 Video Game Box Cover Art (2008)
Was it allowed to use such cover art having nothing to do with in-game (pretty-limited) graphics?
Panzerschrek··on I thought I was building a C replacement. I was wrong
> methods first

I agree, that sometimes doing things OOP-style with methods isn't the right choice and using plain structs and free functions is a better way of doing things. But there are cases where using methods is inevitable - when internals must be hidden in order to prevent incorrect usage. Also it's needed if one needs runtime polymorphism, in such cases (in C++) inheritance and virtual methods come to rescue. Doing so in C way (with void pointers and structs containing function pointers) is less ergonomic and bug-prone.

Panzerschrek··on Profit Margins of the Largest Companies
It's no longer capitalistic profit, it's more like feudal rent. Meta/Amazon are effectively taxing all the society.
Panzerschrek··on C's Flexible Integer Sizes Were Not a Design Mistake
There can't be easy portability if such fundamental thing as integer size differs from target to target. It's unlikely that a non-trivial program designed for one target can run on another with simple recompilation, because a lot of code is typically written with implicit size assumptions. Almost always porting a C program to a new platform requires some debugging and fixing necessary due to different type sizes and other differences. A good example of this are issues found in 32-bit programs for PC being ported to newer 64-bit processer.
Panzerschrek··on Real-time feedback: My closing move in every interview
> If you were an animal, what animal would you be?

The only right answer is to leave such an interview immediately.

Panzerschrek··on Modern Object Pascal Introduction for Programmers
COW-strings aren't free. In a multithreaded environment they require atomic operations for use counter, which isn't cheap. Some time ago some implementations of C++ did use COW-strings too, but this approach was rejected due to such performance concerns.
Panzerschrek··on Ideas on modernizing the open-source desktop
> Which you can't get without modernization

What kind of "modernisation" do you think is necessary for that? XFCE like 12 years ago was already pretty customizable and it remains customizable. Themes, colors, button layouts, some behavior and effects can be changed. XFCE panel allows full customization - I can choose its position, start button logo and text, shortcuts and other elements. It's as flexible as it can be.

Panzerschrek··on UK military jamming other nations' satellites to defend itself, BBC told
> reunite the USSR of which Poland was a member state

It wasn't. Poland was formally independent country, but practically under control of Moscow.

Panzerschrek··on Ideas on modernizing the open-source desktop
No, thanks, I require no modernization. I just need stable, but customizable UI, so that I can customize it once and use it my entire life without needing to adopt to new stuff constantly.
Panzerschrek··on More floating point alternatives
In some cases I use binary fixed-point numbers. In certain aspects they are much better than floats - no precision loss happens in addition/subtraction (if no overflow/underflow takes place), additions and subtractions are typically faster (since it's just an integer operation internally), casting from and to integers is also cheap (requires only bit-shift).

Multiplications are a little bit tricky. Multiplication by an integer is trivial. Multiplication of two fixed point numbers produces the result with the number of fractional binary digits equal to sum of the number of fractional digits in source numbers. The result may be stored in an extended type, truncated down or rounded.

Divisions work fine too, but sometimes may be slower compared to float types, because CPUs can for some reason do much faster floating-point divisions compared to integer divisions.

The only disadvantage of fixed-point numbers is that it's required to keep a balance between range and precision carefully. One can't just use some specific precision in the entire codebase, typically precision should be selected for each individual operation.

Panzerschrek··on What Zig felt like, coming from Rust
It's technically possible to perform arena-based allocation and still have compiler checks. The compiler just need to track objects allocated with an allocator and prevent destructing the allocator itself as long as there is at least one object using it.

It's like view span objects in rust. The compiler knowns that a span is logically connected to the parent object and don't allow destroying it when such span exists.

Panzerschrek··on What Zig felt like, coming from Rust
But with static analysis it's still possible to miss some leaks or to have false-positives. That's why an integrated language mechanism preventing such leaks is much better.
Panzerschrek··on What Zig felt like, coming from Rust
> Rust: Drop runs automatically at scope end, so this specific bug simply doesn’t exist.

That's why having no auto-destructors is a dead-end. This is the greatest mistake of such languages like Zig or Odin.

Panzerschrek··on Measure internet censorship
Pretty strong censorship. That's why I can't even open this link in my country.
Panzerschrek··on Why building a Rust LSP is hard
> recover from common syntax errors

It's a dead-end. Sure, it can work in simple cases, but there will be always a case where such syntax recovery isn't possible. That's why relying only on syntax recovery isn't an option.

Because of that I use a different approach. I do parse on each document editing, but such parsing is guaranteed to produce valid results only up to the point with broken syntax, where editing usually takes place. Such parsing is enough to reconstruct location of the point where editing takes place (namespace/class/function) and to reconstruct local context (local variables declared prior to editing place). This allows to perform almost perfect autocompletion by suggesting global and local names available at the editing point. In order to provide proper suggestion of non-local names declared after the editing point, I do keep a structure for the most recent document state with valid syntax.

With features like "go to definition" I do the same. I store a hash-table with location to definition point mapping, but it's updated only from time to time and only if document syntax is valid. In order to be usable for cases with edits made after building such hash-table I just perform text-based position mapping using accumulated edit events.

Panzerschrek··on Why building a Rust LSP is hard
TCP isn't really necessary. Usually a language server just uses stdin/stdout, which are just pipes.

And overall overhead for running a language server in a separate process isn't that big. LSP is designed in such a way that only minimal amount of information is needed to be passed, like edits or short responses. Packing/unpacking JSONs isn't a bottleneck, the heaviest job like program analysis is done in the language server itself without interprocess communication overhead involved.

Panzerschrek··on Why building a Rust LSP is hard
A lot of things described in this article applicable not only for Rust, but for almost any language. Like it's obvious that requests should be handled asynchronously and that conversions from/to UTF-16 are needed. But it's actually not so hard.

I have written a language server for my language too. The hardest thing was to find a way allowing providing useful autocompletion for a document in edited state, when it's not syntactically-correct. This is the trickiest part how to deal with such incorrectness without missing all the context necessary.

Panzerschrek··on C++26: Trivial infinite loops are no longer undefined behaviour
> the simplest infinite loop

An infinite loop which does nothing is practically useless. So, compilers optimize it out. That's the whole philosophy of modern compilers - to reduce execution time by preserving semantics. In case of an infinite loop elimination it's an optimization making code infinite times faster.

Panzerschrek··on C++26: Trivial infinite loops are no longer undefined behaviour
I don't see how it can be useful. It's almost always an error to write such a loop. The only reason for it to exist is in very low-level code to do nothing, but for such cases using something like an external function written in assembly is perfectly fine, no C++ standard changes are necessary. It's even makes things harder by complicating the standard with little to no benefits in exchange.
Panzerschrek··on Recreating Voodoo Graphics and a Late-1990s Gaming PC on an FPGA
Am I right that Voodoo had no early depth test and thus triangles are textured even if they are completely obstructed?
Panzerschrek··on Trying to Make a Loop Auto-Vectorize
For a couple of days I experimented with auto-vectorization in my language which uses LLVM as its backend. In my example I had a simple function multiplying elements from two arrays and writing them in the third one. And it worked as expected, I did see autovectorization in the result code. But I also noticed something strange - there were a couple of pointer difference calculations and jumps prior to the unrolled/vectorized loop. Then I realized, what this means. LLVM isn't sure that it can use autovectorization, since input and output arrays may overlap. So, it just performs a runtime overlapping check and if no overlap is detected, a vectorized version of the loop is executed, otherwise it jumps to a non-vectorized loop version.

That's why C has restrict keyword. If it's provided, LLVM is sure that no runtime overlapping check is needed and can autovecrorize, sometimes even in places where such vectorization without restrict isn't possible at all.

Panzerschrek··on A few good ideas in programming languages
> If you didn't have that guarantee, at worst your mutex's guard object would be immediately dropped

For named local variables it's a different story. They should remain alive until the end of their lexical scope. But for unnamed temporaries created in expressions different rules should apply - as soon as there is no reference to such temporary, it should be destroyed.

Panzerschrek··on A few good ideas in programming languages
> In Rust variables are not destroyed after the last borrow ends but instead when it goes out of scope

That's the problem. Once I had a tricky case, where I locked a mutex in a match expression only to read a single field to match from the mutex contents. In one of branches of the match expression I locked this mutex once again and got a deadlock. Rust compiler wasn't smart enough to realize that the temporary variable for the mutex lock object should be destroyed earlier (it's no longer needed). So, I needed manually reading the field I need into a named variable to eliminate this deadlock.

A more advanced temporaries lifetime analysis would solve problems like described above, but it means basically duplicating a lot of stuff which is already done in the borrow checker (which runs as an afterpass).

Panzerschrek··on A few good ideas in programming languages
> Exactly the way you suggest, as an optional add-in

No, I don't suggest it, but criticize it. Rust performs its checking as a separate step after actual compilation, which sometimes leads to strange behavior (like borrow errors are shown only after actual compilation errors). I prefer an approach which is integrated with other language mechanisms.

> It's still WIP but in my side project I haven't found cases that can't be handled yet.

It's generally a good idea to write such an analyzer, but I doubt it can be useful without proper integration with the language itself (with huge semantics changes). If it's too strict, it will reject perfectly fine code, but otherwise it will catch only the most obvious errors and approve code having more complex memory bugs.

← PreviousPage 3 of 16Next →