Live data from Hacker News

I stopped everything and started writing C again

kmx.io

81–90 of 475 posts

Re: I stopped everything and started writing C again

#81

Earlier quoted context omitted.

Sounds like they know what they are doing. How is using c++ with only data classes different from using c with struct

Slightly better ergonomics I suppose. Member functions versus function pointers come to mind, as do references vs pointers (so you get to use . instead of ->)

Yeah, slightly better ergonomics. Although we could, we simply did not use function pointers, we used member functions from the data class the data sat inside. We really tried to not focus on the language and tools, but to focus on the application's needs in the context of the problem it solves. Basically, treat the tech as a means to an end, not as a goal in itself.

Re: I stopped everything and started writing C again

#82
post #72

Despite what some people religiously think about programming languages, imo C was so successful because it is practical. Yes it is unsafe and you can do absurd things. But it also doesn't get in the way of just doing what you want to do.

No, it's because of Unix and AT&T monopoly.

How was AT&T’s monopoly a driver? It’s not like they forced anyone to use UNIX.

Re: I stopped everything and started writing C again

#83
Going from mid-90s assembly to full stack dev/sec/ops, getting back to just a simple Borland editor with C or assembly code sounds like a lovely dream.

Your brain works a certain way, but you're forced to evolve into the nightmare half-done complex stacks we run these days, and it's just not the same job any more.

Re: I stopped everything and started writing C again

#84
post #4

[flagged]

completely not! (And yes, I was considering if I should shout in capslock ;) ) I have seen so many fresh starts in Rust that went great during week 1 and 2 and then they collided with the lifetime annotations and then things very quickly got very messy. Let's store a texture pointer created from an OpenGL context based on in-memory data into a HashMap... impl GlyphCache { Yay? And then your hashmap .or_insert_with fa…

You don’t need to work through that, you can follow https://doc.rust-lang.org/cargo/reference/build-script-examp... and it shows you how.

Re: I stopped everything and started writing C again

#85
post #11

I fully understand that sentiment. For several years now, I have also felt the strong urge to develop something in pure C. My main language is C++, but I have noticed over and over again that I really enjoy using the old C libraries - the interfaces are just so simple and basic, there is no fluff. When I develop methods in pure C, I always enjoy that I can concentrate 100% on algorithmic aspects instead of architectu…

> A typical example I have encountered several times now is people using elaborate setups with std::string_view to avoid string copying, while exactly the same functionality could've been achieved by fewer code, using just a simple raw const char* pointer.

C++ can avoid string copies by passing `const string&` instead of by value. Presumably you're also passing around a subset of the string, and you're doing bounds and null checks, e.g.

    const char* Buf = "Hello World" ;
    print_hello(Buf, 6);

string_view is just a char* + len; which is what you should be passing around anyway.

Funnily enough, the problem with string view is actually C api's, and this problem exists in C. Here's a perfect example: (I'm using fopen, but pretty much every C api has this problem).

    FILE* open_file_from_substr(const char* start, int len)
    {
        return fopen(start);
    }

    void open_files()
    {
        const char* buf = "file1.txt file2.txt file3.txt";

        for (int i = 0; i += 10; ++i) // my math might be off here, apologies
        {

            open_file_from_substr(buf + i, buf + i + 10); // nope.
        }
    }

> When I develop methods in pure C, I always enjoy that I can concentrate 100% on algorithmic aspects instead of architectural decisions which I only have to decide on because of the complexity of the language

I agree this is true when you develop _methods_, but I think this falls apart when you design programs. I find that you spend as much time thinking about memory management and pointer safety as you do algorithmic aspects, and not in a good way. Meanwhile, with C++, go and Rust, I think about lifetimes, ownership and data flow.

Re: I stopped everything and started writing C again

#86
post #4

[flagged]

I would use Mojo - you get the type and memory safety of Rust, the simplicity of Python and the performance of C/C++.

> simplicity of Python

Python isn’t simple, it’s a very complex language. And Mojo aims to be a superset of Python - if it’s simple, that’s only because it’s incomplete.

Re: I stopped everything and started writing C again

#89
post #4

[flagged]

completely not! (And yes, I was considering if I should shout in capslock ;) ) I have seen so many fresh starts in Rust that went great during week 1 and 2 and then they collided with the lifetime annotations and then things very quickly got very messy. Let's store a texture pointer created from an OpenGL context based on in-memory data into a HashMap... impl GlyphCache { Yay? And then your hashmap .or_insert_with fa…

Adding `foo = "*"` to Cargo.toml is as easy as adding `-l foo` to Makefile.

Re: I stopped everything and started writing C again

#90
post #4

[flagged]

The best feature of C is the inconvenience of managing dependencies. This encourages a healthy mistrust of third-party code. Rust is unfortunately bundled with an excellent package manager, so it's already well on its way to NPM-style dependency hell.
Post reply on HN