Lurker News

Comments (218) 56 threads

Earlier comments
koito173 replies#
The README gets straight to the point and I really like that.

Additionally, the .env file parser is quite clean.
https://github.com/ashtonjamesd/lavandula/blob/main/src/dote...
However, it doesn't seem that the parser supports comments. I guess a "good first issue" for anyone interested in contributing would be extending the `skipWhitespace` function to detect `#` tokens and skip the rest of the line when present.
Would also need to handle edge cases like env vars having values containing `#` tokens inside (but these will be quoted, so it's probably not too tricky to handle.)

koolba#
Why is there an env file parser at all?
jpc0#
So what happens when the env value happens to actually have a # in it?

So you then need to implement escaping which can go from a very simple implementation to an actual lookahead parser
EDIT:
Actually I agree, this parser is already very overbuilt and should be able to handle comments. Generally an env parser is a few lines a best… you need to read a line, look for the first instance of the separator, generally no reason to build a full parser for that, env is an absurdly simple format if you don’t want features like comments.
Hell even an ini format parser is simple to implement in the same style.

lelanthran#
> Additionally, the .env file parser is quite clean.

I didn't find it clean; it's so over-engineered that you won't easily be able to spot bugs in it.
What you want is (assuming you have a string-trimming function):

    while ((fgets (name, sizeof name, inputf)) {
        if (!(value = strchr (name, '='))) { continue; }
        *value++ = 0;
        strtrim(name);
        strtrim(value);
        if (!*name) { continue; }
        // Now store `name` and `value`
    }
> I guess a "good first issue" for anyone interested in contributing would be extending the `skipWhitespace` function to detect `#` tokens and skip the rest of the line when present.

Or do it before processing:

    // First statement of while loop
    char *comment = strchr (name, '#');
    if (comment) *comment = 0;
    // Continue with processing `name`

The way it's done in the linked code raises a ton of red flags.
elevation1 reply#
I have considered porting a couple production apps from python to C; at this stage in their lifecycle they would benefit more from C's execution speed than from python's development speed.

Your work is a nice reference, it is neat to see someone else working in this space!

jimbokun1 reply#
Would Go be a happy middle ground?

The translation should be much faster while giving a lot of the efficiency benefits of C (but by no means all).

EasyMark#
or rust/zig as well.
jll291 reply#
Thanks for sharing; small is beautiful. A couple of points of feedback:

- check return value from malloc();
- consider using your own arena allocator (which gets a larger block of memory with a one-time call of malloc, then calls an in-process allocator that assigns part of that block);
- use a library prefix e.g. Lavandula_ before API functions like get() or runApp() to avoid name collisions.
- The JSON function is not spec-compliant; why not use an existing library? (I understand external dependecies may introduce unwanted bloat, but in this case, there are many compact and efficient options.)

1718627440#
> consider using your own arena allocator (which gets a larger block of memory with a one-time call of malloc, then calls an in-process allocator that assigns part of that block);

This is what malloc already does. Unless you intend to have multiple different arenas in your program, this is just unnecessary complexity.

dboon1 reply#
C is really, really ripe for tooling and modern libraries. There are a lot of great ones already that don’t resemble what I’ll call university C in the slightest (i.e. the C most of us remember writing; awful, bug filled, segfaulting)

I’ve been building out my C standard library replacement in earnest for a little while. If you like this framework, check it out.
https://github.com/tspader/sp

le-mark#
That’s quite impressive, I love this c renaissance! I noticed your project requires c++ compiler as well, I didn’t study it to understand why? Do you plan to keep that requirement?

Load more comments