Hacker News new | past | comments | ask | show | jobs | submit | davidwf's comments login

The last time I was writing C professionally I used ceedling (https://www.throwtheswitch.org/ceedling) and I highly recommend it. I hate cmake too. :-)


I highly recommend Zed Shaw's "Learn C the Hard Way": https://learncodethehardway.org/c/

I worked through this and felt well-prepared to actually use C in anger when I had to.


Terrible overall and entirely wrong in multiple places. If you learn C from this book, you should't be writing C.

The last bit is also true for K&R The C Programming Language (avoid at all costs).

You're better off with:

- Modern C (whatever edition is current)

- Seacord's Effective C: Introduction to professional C programming

- C Programming: Modern Approach 2nd edition (bible)


Really really love Antora. I've been pushing hard for it for internal docs -- one very nice attribute is that it can collate docs from multiple Git repos. This way, you can have documentation close to the code, like I want as a developer, while having a single "documentation site" like most management and non-technical users want.


It's a very common pattern for C memory allocation checking. A public example I know off the top of my head can be seen here: https://github.com/zedshaw/learn-c-the-hard-way-lectures/blo... (the implementation of the CHECK macro). That's in a C tutorial but I've implemented a version of that macro frequently.

Let's say you need to dynamically allocate two buffers in a function and want to make sure they are freed at the end of your call. You can use this macro like so:

  int two_bufs(int n, int m) {
    int *buf_1 = NULL;
    int *buf_2 = NULL;
    buf_1 = calloc(n, sizeof(int));
    CHECK(buf_1);
    buf_2 = calloc(m, sizeof(int));
    CHECK(buf_2);
 
    // ... lots of cool things with buf_1 and buf_2

  error:
    free(buf_1);
    free(buf_2); // Safe if null

  }


You have "free(buf_2); // Safe if null", but if CHECK(buf_1) turns into a "goto error", won't buf_2 be uninitialized? And so can take on any value?


You are correct, will edit. C is hard, writing C in the browser sans coffee is harder. :-)


I do think this illustrates one of the issues with goto: normally the compiler would be able to warn that you were using buf2 potentially uninitialized, but I think you wouldn't get a warning in this case.


One of the examples in the linked article showed the compiler emitting a warning when a variable wasn't initialized because the goto skipped past that line, it's in 31.7. I don't know what compilers will or will not give you that warning, but at least the one used for the article does. So it ought to catch the problem with the initial version of the example above as well.


The Clang Static Analyzer could probably find this, if the compiler itself doesn't notice.


This is very situational, but I have recently been part of a project that does a lot of C server-side development and we have found that static linking our non-glibc dependencies has really improved our developer experience. Using ceedling's dependency plugin[1] and producing a single "statically" linked library has made our C development much closer to using a language with a more modern package manager. Don't get me wrong, if I was trying to distribute binaries to machines I didn't control I'd definitely be willing to invest in the Linux packaging "fun", but for a server-side application it's been a good choice for our team overall.

[1] https://github.com/ThrowTheSwitch/Ceedling/tree/master/plugi...


Yes and no. In Ardour, which has a substantial dependency tree (80+ libraries), if we statically link, the edit/compile/debug cycle becomes incredibly bogged down by static linkage. It takes a long time (even with lld) to complete the link step. If we use shared libraries/dynamic linkage, the edit/compile/debug cycle is nice and fast, but application startup is a bit slower (not by as much as static linkage is slower, however).

For users, it would be better if the application was statically linked, at least in terms of startup cost. But because developers do the edit/compile/debug cycle much, much more often than users start the application, we opt for dynamic linkage.


You can dynamically link during development, and then ship statically linked binary (with LTO etc). That’s what Chrome does, for example.


It's not that simple for us (we have tried this).


You aren't! I'm a state-school bachelor's-only don't-even-have-a-CS-degree person; neither of my parents have a 4-year-degree. I had a FAANG job, left it for a better one, own a house in 2/5 of the most expensive cities of the world, etc., etc.

Elitist assholes definitely exist everywhere, but in my experience a lot of what I viewed as "showing off" when I was younger was really just "being normal" for a different "normal". When a 25-year-old software developer talks all the time about Stanford and Lambos, he's not trying to show off, he's just talking about what he knows, just like the guy talking about tail-gating at <insert SEC school here> and then going four-wheeling all the time.

I don't want to devalue experience and education in any way; those things have value! But time is linear and the past has happened -- you just have to move forward with what you have and go after what you want, and don't get distracted by the fact that others started out with a lot more than you. I double-pinky-promise you that if you are good at something, keep getting better at it, and aren't an asshole yourself, you can work at any company you want. :-)


I'm reluctant to even mention it, but I'll bite. :-)

I found the first half of "Prometheus Rising" by Robert Anton Wilson to be incredibly useful for understanding human dynamics -- I use the framework presented there every day. The core of this is in my opinion just a very straightforward computer-focused analogy that gives me insight into the behaviour of other people and myself that I haven't found elsewhere.

Of course, outside the core is a LOT of wild new age, Crowley-Leary-Regardie syncretism that provokes strong negative throw-the-book-across-the-room reactions in most people. A lot of very reasonable people would look at the wikipedia page or the cover of this book and not only think that the book is crap, but also that I'm a crazy hippie for even considering reading it.


RAW is such an underrated author and thinker. I don’t think there is a book of his that I have not read. I started reading him when I discovered Principia Discordia, Church of the Subgenius, etc. That whole scene of counter culture thinkers had a pretty major impact on me and my world view. Great to see others that appreciate the ideas just under the weirdness.


100% true for me as well -- I found the Illuminatus Trilogy via reading the Jargon File when I was an embryonic techie oh so long ago and that whole scene has been super-influential on me ever since.


i have to admit, as someone who dislikes new agey non rigorous stuff, that this book superficially gives off the vibe of being something Id absolutely hate.

Would you be willing to give an example or two of some topics the books discuss that might be counter to what that perception or that you just found really insightful?

Or is my perception that the focus is new age mysticism correct?


Sure! The "core" I mentioned above talks about the common psychological concepts of Id, Ego, and Superego (and more), and analogises them to separate processes running on your brain's processor, with a "layered approach". Lower-level processes have a higher interrupt priority. For example, fight-or-flight happens at a subrational level, and therefore "rational" thinking won't change the way you handle a fight-or-flight response, since the triggering of that response inherently interrupts your rational thought-loop.

I'm not saying that this is literally correct -- the brain is way more complicated than that! But I find it quite useful as a metaphor for processing and understanding social dynamics that I inherently find "irrational".


Interesting, yeah I like the analogy. I'll throw these on the reading list and give it a shot


I personally left my FAANG role behind for a role that had way more of what I wanted to do (coding) and way less of what I hated (paperwork), and it was one of the best decisions I've ever made in my life.

I think it's important to keep in mind "signal bias" -- I'm never on other social media, and I'm only on HN every weekday over my breakfast and morning coffee. I don't spend time building my brand or writing blog posts or shouting from the rooftops about how great my life is because I'm trying hard to stay busy actually enjoying how great my life is. In my experience, there really are a lot of folks who've made similar decisions, it's just that part of managing your life is also giving up on trying to convince strangers that you're awesome.


> part of managing your life is also giving up on trying to convince strangers that you're awesome.

Amen. I find that it’s easiest to just focus on being awesome and let others figure it out on their own. Some won’t—oh well!


> let others figure it out

I think that's what the GP is trying to avoid. Not caring whether others figure it out


Disclaimer: I'm an employee of ExpressVPN and work on this codebase.

The specific reason for the size disparity is that we require he_conn->{username,password} to be null-terminated, whereas we do NOT require he_msg_auth->{username,password} to be null-terminated. I remember raising the same point and being convinced that we had a good reason for doing so, but I also haven't had enough coffee to remember what the good reason was!

Regardless of whether this is a "bug" or not I do think that the disparity points to something that unnecessarily causes confusion, will have a think about making it more consistent.

Regarding style -- I also ~hate if(x==0) without the space after the if but we committed to consistency instead of arguing over it via clang-format. To quote Rob Pike, "Gofmt's style is no one's favorite, yet gofmt is everyone's favorite."


Sorry about the late reply, I didn't realize there was a reply to my message. I reviewed it once again and can attest that what you say is correct, so that's cool.

Thanks for taking the time to reply!


Hi! I've done work in Sydney from 2011-2013, India 2013-2014, and now Singapore from early 2020 up to today.

Overall, I would say that there's larger gaps between companies than there are internally to countries. Especially in India, I was consulting and definitely spent time on an Infosys campus in Bangalore where they had unscrewed half of the overhead lights to save money, but I also worked with some places that felt more or less like any other high-tech company anywhere else in the world.

Similarly, when I was looking for work here in Singapore, there were definitely folks that were looking to hire folks with 15 years of experience and pay them $80k/year, but there were also several companies that offered high-paying jobs with interesting work. There were definitely FEWER companies, but the flip side is that the hit rate was much higher -- I ended up getting at least a first interview with 70% of the companies I sent my resume to here, as opposed to the 20-25% I generally find in the US. In general, companies are very keen to hire "American" tech talent, especially if you have a "name-brand" on your resume.

In terms of compensation, if you are relocating, you really do have to look at the holistic quality-of-life. I ostensibly took a "paycut" in US$ terms from my Google NYC job for my role here in Singapore, but I also went from a tiny 2 bedroom apartment and a 45 minute subway ride to a 3 bedroom walking distance to work with a full-time nanny who works 6 days a week, cleans, and cooks in addition to watching our two kids.

Living "overseas" has been a great joy in my life -- I may end up back in America for some time but I also see myself living elsewhere for as much or more time. I can't recommend it enough -- the world is a pretty incredible place!


It might not just be American tech talent though. I'm "local" (with an Australian degree), minimal name-brand, and 10 years experience. I've gotten first interview offers from many of the top companies in the region. The senior to staff developer range is in very high demand.


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

Search: