• 0 Posts
  • 74 Comments
Joined 2 years ago
cake
Cake day: July 24th, 2023

help-circle
  • Memory-safe since decades.

    It’s just reference counting with some common sense optimisations. From the website I can’t quite make out wether they disallow cyclic data structures or just leek them, but I’m guessing it’s the latter.

    Also the only thing worse than one-indexed arrays (the default) is allowing user defined array start.

    I feel embarrased to admit that I had been totally unaware of Seed7 until mere two months ago.

    Don’t be, there are so many out there, no need to be embarrassed for not knowing a language that prides itself on lot having fortran style line length limit.
    After slogging through vhdl, I personally will not voluntarily use a language that forces me to write out stuff like

          end if;
        end for;
      end func;
    

    when three } would work just as well.
    Similar deal with

    const proc: main is func
      local
        # local variables go here 
      begin
        # finally, the actual code can begin
    

    where proc means func void so essentially const func void main is func begin. Just default to const, remove the redundant funcs and allow locals to go where they are used, not all up front, even when they are only used in one branch.



  • I came up with a kind of clever data type for storing short strings in a fixed size struct so they can be stored on the stack or inline without any allocations.

    C++ already does that for short strings while seamlessly switching to allocation for long strings.

    It’s always null-terminated so it can be passed directly as a C-style string, but it also stores the string length without using any additional data (Getting the length would normally have to iterate to find the end).

    Also the case in the standard library

    The trick is to store the number of unused bytes in the last character of the buffer. When the string is full, there are 0 unused bytes and the size byte overlaps the null terminator.

    Iirc, that trick was used in one implementation but discontinued because it was against the standard.

    (Only works for strings < 256 chars excluding null byte)

    If you need a niche for allocated string you can get to 254 but the typical choice seem to be around 16.