Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Doesn't seem like the author knows C. The C example of codecs is riddled with syntax errors. When he writes

    struct Codec
    {
        *int (*encode)(*int);
        *int (*decode)(*int);
    };
he probably meant to swap the int and the asterisk to mean a pointer to int. But no one would use a pointer to int to mean bytes; we have pointer to char or pointer to unsigned char for that:

    struct Codec {
        uint8_t* (*encode)(uint8_t*);
        uint8_t* (*decode)(uint8_t*);
    };
And that doesn't exactly deal with ownership issues.

But besides those nitpicking, I struggle to see what his point is. His point is to extract common features of components and build interfaces for them? I mean isn't that something we've been doing for a long time?



I think the author has not yet encountered C++ vtables, they should take a read of https://en.m.wikipedia.org/wiki/Virtual_method_table


The use cases are basically static, final methods in OO-speak. The article simply shows a straight forward way how to implement that.


I feel that he may be a Go programmer.


> But no one would use a pointer to int to mean bytes; we have pointer to char or pointer to unsigned char for that

Or just use void*, then the caller doesn't have to cast when they want to pass arbitrary data.


It's not like Linux invented the VFS either --- that was already there in the early Unices from which Linux got its inspiration.


"Everything is a file" concept, comes from Plan 9


It comes from unix. Plan9 applyed it further.


And then there was Inferno


He’s probably been doing a lot of go. I always struggle with this when I’m switching between the two.


yes, maybe for you it's clear but perhaps for many other developers, it's not! I don't think he claimed something new, just that you can promote abstractions and use them regardless of the language.

we often, as developers, see something as useful or not only from our point of view, which is fair since you're reading and you want to learn more, but we can't forget that there are many developers out there being formed/mentored that might benefit from this kind of post.


Are you the author of this post? Your HN user name matches the poster, and the username in the URL in the author page of the site at https://leandromoreira.com.br/author/dreampeppers99/

In any case I just don't think the author has made the case in a very clear way. Unifying all the codecs in a codec library through an interface is something whose novelty is lesser than that of everything-is-a-file. It takes more ingenuity to consider objects like pipes and sockets as files, and I hope the author didn't really lump them together. I just hoped the author would cover more things about this design pattern and explain his thesis more clearly in an article with such a grandiose title.


Yes, I'm and I do agree with you with some of your arguments. The lack of details might be a problem for you but it can transform the post easier for someone fresh.

It's always hard to know whether you're going too deep or too shallow, what are the target people?! I'm afraid, in this case, I didn't put as many details as I planned because every time I read it, it started to become be too difficult for newcomers and my idea was to show to anyone this idea of "we should try to do good code design despite the language since it works for many giant projects such as Linux"

I appreciate the time you took to read it and for the issues pointed: clarity and cover more thins, I'll pay more attention to the future posts and I'm open to suggestions, thanks. Maybe I miss the balance and I should put more details/examples into it.


Seems like a beginner dev. It can be a nice experience to learn by teaching. Just a bit confusing for the readers.


I struggled a lot with the title for this post =/ (I crossed like 6 titles) but I also wanted something to call attention (not from lead/principal/kernel devs expectations) to the value of good code design, again naming is hard =)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: