I rewrote the ai slop cli utility "tldr" in C, it's 20 times faster.

https://forgejo.zeromedia.vip/girlnamedzero/cldr

Seriously! According to the time command in fish, cldr (my program) takes around 4-5 ms to print files, tldr takes 80-100ms. (PS, on my server, cldr actually takes less than 1 ms to fetch the file, while tldr takes closer to 150 ms. That's 150 times faster!!!)

This started a couple days ago when a friend of mine alerted me to the fact that the official tldr repo now takes ai contributions for their pages (aka the cheat sheet files that are printed) and for the actual program code. She then showed me a repo called ethical-tldr which does not allow for the use of ai contributions in the pages or program code.

However, their even though their client doesn't allow vibe coding, it is still written in Python, which itself takes ai contributions.

So, I decided to learn C from scratch and make my own tldr client that's faster and better than theirs in *every way! Introducing cldr! I am especially proud of the list and search functionality because the interface is just gorgeous.

Note, ABSOLUTELY NO AI was used in the making of this, I learned and wrote everything on my own in just the past 3 days, I don't think I even copied much or any code from websites.

*There's still like two things I haven't implemented that the official client does, but they're very minor and I'd be willing to bet that 99% of you won't know the difference.

image

image

184 points · 65 comments · view on lemmy.world

65 Comments

logi@lemmy.world · 74 pts · 2d (4 replies)

What your project desperately needs is a description of what it does. I had to follow the links to ethical-tldr back to the original tldr to see what it's supposed to do.

girlnamedzero@piefed.zeromedia.vip · 51 pts · 2d (1 reply)

Ohh! That's a good point! Thanks! I just updated the README to provide an actual description.

bookmeat@fedinsfw.app · 37 pts · 1d

The irony of a tldr missing from tldr...

moldy_rice@piefed.keyboardvagabond.com · 1 pts · 1d (1 reply)

And yet, you haven't said it either

Ephera@lemmy.ml · 13 pts · 1d

It's basically short-form manpages, so it gives you a one-liner to describe what a CLI utility does, and then just lists a few concrete invocations to show off different use-cases for it.

One other big difference to manpages, though, is that the actual texts aren't packaged by your distro, but rather downloaded from a server.

inari@piefed.zip · 51 pts · 2d

This is an instance of that recurring trope of coding something better out of pure spite

tomenzgg@midwest.social · 38 pts · 1d

I could only wish to be this cool.

eleijeep@piefed.social · 29 pts · 2d (11 replies)

So, I decided to learn C from scratch
...
on my own in just the past 3 days

Really impressive, great job! What resources did you use for learning?

girlnamedzero@piefed.zeromedia.vip · 22 pts · 2d (10 replies)

Mostly just w3. Occasionally I had to look up some stuff for more “niche” use cases, but for the most part I just learned from w3.

I already have experience with programming in general, so the hardest part was learning the syntax, and strings… oh god strings are so bad in C, I had to make a new function called strfmt that works like printf but just for returning a formatted string.

Gobbel2000@programming.dev · 12 pts · 2d (2 replies)

Do you know about the sprintf function?

girlnamedzero@piefed.zeromedia.vip · 3 pts · 2d (1 reply)

yes! However, I found it very frustrating to use and it kept leading to ludicrous errors beyond my wildest dreams. So I made my own function that works better and easier.

for_some_delta@beehaw.org · 4 pts · 1d

Glad you are enjoying C. As one of my proffesor's espoused, "It is God's language". As a C++ developer, I cannot recommend {fmt} enough.

potustheplant@feddit.nl · 3 pts · 1d (6 replies)

Are you allergic to vowels?

Septimaeus@infosec.pub · 5 pts · 1d (5 replies)

Those are method names in C, so I’m afraid you’ll have to take it up with a guy named Dennis who isn’t very talkative these days.

potustheplant@feddit.nl · 4 pts · 1d (4 replies)

Not sure what you mean. You said that you had to make a new function and decided to call it "strfrm". The standard is actually the opposite afaik. You should be more verbose and not use contractions. Something like "string_format" is far easier to read.

Septimaeus@infosec.pub · 2 pts · 1d (3 replies)

Ah I didn’t see OP’s strfmt you’re right I’m wrong

potustheplant@feddit.nl · 2 pts · 1d (2 replies)

And I didn't notice that you weren't OP. I guess we're even? Haha

girlnamedzero@piefed.zeromedia.vip · 3 pts · 1d

I was just following the naming convention as other string methods, like strlen, strcmp, strcat, (string length, string compare, and string concatenate, respectively), mine is string format, so I did strfmt!

logi@lemmy.world · 25 pts · 2d (14 replies)

So... C code is faster than python. We knew that. Thanks for the better performing rewrite. Now do it in rust 🤓

inari@piefed.zip · 27 pts · 2d (5 replies)

Looks like someone did that https://github.com/tldr-pages/tlrc

syklemil@discuss.tchncs.de · 27 pts · 2d (3 replies)
Creat@discuss.tchncs.de · 20 pts · 2d (2 replies)

In all distros I've recently used this is what gets installed when you install the "tldr" package with the package manager. And for good reason.

syklemil@discuss.tchncs.de · 4 pts · 1d

I'll admit I have no idea what makes one of the Rust implementations preferable over the other. Nor can I go looking at the code myself now that GitHub has hosed itself again

sem@piefed.blahaj.zone · 4 pts · 1d

What is the reason?

RedSnt@feddit.dk · 1 pts · 1d

Gotta love projects with a properly commented config file that makes it easy to modify its defaults.

AceSLS@ani.social · 12 pts · 2d (1 reply)

Already exists and isn't vibecoded https://github.com/tealdeer-rs/tealdeer

kieron115@startrek.website · 3 pts · 1d

I was gonna post this as well, this comes with CachyOS by default.

Valmond@lemmy.dbzer0.com · 2 pts · 1d (5 replies)

Why in rust? I mean it would be less faster, right? If speed is of the essence ofc.

communism@lemmy.ml · 4 pts · 1d (1 reply)

Performance of compiled Rust and compiled C are comparable. Of course, compiling Rust is slower though.

Kangae_Hishiryo@scribe.disroot.org · 3 pts · 1d

Yeah, but it's slower because it has compile-time safeguards and guardrails that eliminate some families of really dangerous memory and IPC errors.

logi@lemmy.world · 4 pts · 1d

Because "rewrite it in rust" is its own meme and needs no particular reasoning.

endless_nameless@lemmy.world · 3 pts · 1d

The performance metrics are cool (though unscientific) but speed is definitely NOT of the essence lmfao

TLDR is not a high throughput real time application. You run it like once per use, probably at a rate of less than once per day. Then you spend a minute reading the output. We're talking about minutes-per-year time savings here.

Kangae_Hishiryo@scribe.disroot.org · 2 pts · 1d

Actually not. Rust can be even faster than C, although it's generally similar in performance to C. The point is that it's more secure because of the way it handles memory.

Dumhuvud@programming.dev · 22 pts · 2d (4 replies)

Consider using a different name for the project if you care for searchability. There's already Unicode CLDR Project.

girlnamedzero@piefed.zeromedia.vip · 10 pts · 2d (2 replies)

damn! I guess I should have looked it up before going with the name. I just liked the play on tldr, cldr.

muzzle@lemmy.zip · 8 pts · 2d (1 reply)

Just go with tlcr!

girlnamedzero@piefed.zeromedia.vip · 5 pts · 2d

Ohh, not bad! If I feel like I need to change it, tlcr is probably the best option

kibiz0r@midwest.social · 2 pts · 1d

We use CLDR quite a bit — and coincidentally, we often jokingly call it TLDR.

syklemil@discuss.tchncs.de · 18 pts · 2d (2 replies)

You might want to have a glance at the OpenSSF compiler hardening guide, and maybe try out ASAN (-fsanitize=address).

E.g. I get

[nobody@bb14e99a9c8e cldr]$ ./build/cldr --update --language C.
caution: filename not matched:  ethical-tldr/pages.C./*/*.md

=================================================================
==454==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 4 byte(s) in 1 object(s) allocated from:
    #0 0x7fa48a32c0c1 in malloc (/usr/lib/libasan.so.8+0x12c0c1) (BuildId: b8a4241051a1621937fdc46e867ba7ecb56d96ea)
    #1 0x7fa489e8be0f  (/usr/lib/libc.so.6+0x8be0f) (BuildId: 503200d7fda94a5dc6058d7e0694e5d1dcb2e372)
    #2 0x7fa48a2f2761 in vasprintf (/usr/lib/libasan.so.8+0xf2761) (BuildId: b8a4241051a1621937fdc46e867ba7ecb56d96ea)
    #3 0x561d84213d8c in strfmt (/home/nobody/cldr/build/cldr+0x6d8c) (BuildId: 2a0f13efc2c9b12a67e7dd810a2cbdfd1866e53d)

SUMMARY: AddressSanitizer: 4 byte(s) leaked in 1 allocation(s).
girlnamedzero@piefed.zeromedia.vip · 17 pts · 2d

Ah damn! That's one of the things I had told myself I needed to make sure I checked, but I forgot! Thanks! I'll look into this tomorrow. Like I said, I literally learned C over the last 3 days to make this, so I'm always happy to learn more!

girlnamedzero@piefed.zeromedia.vip · 16 pts · 2d

Update to this, ~~I actually just fixed that bug, and ~~I went through the first section of the hardening guide. Changes are now pushed to main and I released v1.2.1

shittydwarf@piefed.ca · 18 pts · 1d

kieron115@startrek.website · 17 pts · 1d
fruitcantfly@programming.dev · 17 pts · 1d (5 replies)

This looks like a colossally bad idea:

  if (!strcmp(platform, "windows") && !isSpecificPlatform) {
    debugLog("Falling back to rm -rf", 2);
    debugLog(strfmt("rm -rf exited with code %d",system(strfmt("rm -rf %s", path))), 3);
  }

In addition,

However, their even though their client doesn’t allow vibe coding, it is still written in Python, which itself takes ai contributions.

Per the Makefile, this project is built using GCC. GCC itself accepts AI contributions, provided that the code is "legally insignificant" (meaning less than around 15 lines of code) or is part of test cases: https://gcc.gnu.org/ai-policy.html

girlnamedzero@piefed.zeromedia.vip · 2 pts · 1d (3 replies)

For the first part: You're probably right! I'm not sure of a safer way to do it though. This specific part is an artifact of the original method I used, which I don't think would have worked on windows (according to some stack overflow post), but the current code might actually work fine, I just don't have access to anything running windows and would rather not set up a VM.

Second: That's highly disappointing! I think their policy is fairly well thought out, in a way that allows for accountability and auditability, so I might be okay with continuing to use it, I'll have to think about it. If you know of an alternative I could use, I will happily take suggestions!

fruitcantfly@programming.dev · 5 pts · 1d

To add to the last comment, I'd also suggest not mixing logging and business code. That is to say that you should put the system call on its own line, so that it is clear that it's not just a logging call:

  if (!strcmp(platform, "windows") && !isSpecificPlatform) {
    debugLog("Falling back to rm -rf", 2);
    int result = system(strfmt("rm -rf %s", path)); 
    debugLog(strfmt("rm -rf exited with code %d", result), 3);
  }

It may just be a me problem, but I have a tendency to skim over the logging lines unless I'm intentionally reading code carefully, in which case the system call may get overlooked

fruitcantfly@programming.dev · 3 pts · 1d (1 reply)

You can call rm safer manner, but you'll need to fork and use one of the execl functions directly. That way you don't have to worry about escaping the path. The old implement would potentially delete unrelated data if the path contained whitespace, and could even execute arbitrary commands, since it essentially runs bash -c "rm -rf $path"

girlnamedzero@piefed.zeromedia.vip · 1 pts · 23h

Those are really good points! I've been sanitizing other inputs for shell breakage, but never considered checking this. Either way, I have since removed the rm -rf part of the code, instead opting to only use my "good" method of traversing the directory

girlnamedzero@piefed.zeromedia.vip · 1 pts · 1d

Update to my comment: I changed it up a little bit to remove that bit of code. You can optionally uncomment part of the code to re-enable it, in case the current implementation doesn't work on windows

axx@slrpnk.net · 9 pts · 1d (1 reply)

I'm not sure why you did this when Tealdeer exists and has for years? https://github.com/tealdeer-rs/tealdeer

girlnamedzero@piefed.zeromedia.vip · 9 pts · 1d

My reasoning is simple: I had never heard of it.

But also, this is an incredibly simple program and a really good way to help me learn C. Additionally, it seems like tealdeer accepts ai generated submissions, though generally discourages it. I aim to make my project as free of ai as I possibly can.

chunes@lemmy.world · 6 pts · 1d (3 replies)

I wish people still had shame.

Python isn't for command line utilities that you intend to distribute to others. It's for personal one-off scripts.

I mean, FFS, if you're gonna vibecode something, why not pick a fast language? The fact that they can't even tell the LLM to use the right technology shows that they are a complete imbecile

bort@sopuli.xyz · 12 pts · 1d

Python isn’t for command line utilities that you intend to distribute to others

wat

darklamer@feddit.org · 3 pts · 1d (1 reply)

Python isn't for command line utilities that you intend to distribute to others.

Sorry, but you're wrong about this. Python can be an excellent choice for many command line utilities intended for distribution to others.

chunes@lemmy.world · 1 pts · 1d

I don't enjoy making my computer work 20 times harder than it has to

Colloidal@programming.dev · 5 pts · 1d (3 replies)

Dependancies

[Optional] wget can be installed for less reliance on other projects using ai, if wget is not found, curl will be used instead

  1. Small typo: dependencies.
  2. Is curl using AI in its code now?

Thanks for your work!

girlnamedzero@piefed.zeromedia.vip · 6 pts · 1d (1 reply)

Update to my previous comment:

1: Fixed!

2: Yes, it seems like it is! According to the open-slopware repository curl does take ai submissions.

Colloidal@programming.dev · 6 pts · 1d

Dang, looks like they went all-in on it.

girlnamedzero@piefed.zeromedia.vip · 2 pts · 1d

1: thanks! I’ll fix that soon.

2: this is according to the same friend I talked about, but it would be good to double check her knowledge

MasterBlaster@lemmy.world · 4 pts · 1d

excellent. however if you are making a point about AI not being as good s a quality developer, you are missing the point.

CEOs don't give a shit about quality and effectiveness. it is all about getting rid of labor costs. once all he few remaining providers of service are absorbed, we take what they give and pay through the nose. monthly.

milk@discuss.tchncs.de · 3 pts · 1d (1 reply)

Oh yeah this is bound to be maintained

girlnamedzero@piefed.zeromedia.vip · 4 pts · 1d

I intend on maintaining this for as long as I'm able to program

Jankatarch@lemmy.world · 2 pts · 1d

Hell yeah!

Artemis_Mystique@lemmy.ml · 0 pts · 2d

C ftw, but seriously, calling an entire language(python) AI slop is going too far, though I will admit python has been responsible for slop code even before LLMs. My opinion on the matter is, efficient use of LLMs will usher a push to go back to hardware level languages like C, as all the benefits of python(except the awesome collection of libraries it has unfortunately accumulated) are kind of moot when you have a machine capable of outputting any boilerplate you ask of it; beyond that I do not trust LLMs to write logic unless its a well known and named algorithm like reversing an array or a linked list.