Live data from Hacker News

Beej's Guide to C Programming (2007)

beej.us

41–50 of 81 posts

Re: Beej's Guide to C Programming (2007)

#41
post #28
post #24

As someone who currently works with C# - is there much of a point to learning C? I've always found it interesting, but never had a reason to jump into it.

While C remains the single most important programming languages of all time, its share of popularity is shrinking, giving way to C++, C#, Java, and Swift (from Objective-C). Nevertheless, I don't think anyone should call themselves a (true) programmer unless they know C. C is easy to learn, because it's a small language. If you are not new to programming, pretty much all there is to know is in the second edition of t…

> C is easy to learn, because it's a small language.

I'm no great c or c++ programmer - but I really like Bjarne Stroustrup's "Learning Standard C++ as a New Language" (C/C++ Users Journal. pp 43-54. May 1999):

http://www.stroustrup.com/new_learning.pdf

Even if it is somewhat dated now - I think it makes a great case for c++ (or d, maybe rust) over C - and it doesn't even touch on Unicode - simply memory management, error checking and buffered I/O.

I agree everyone should know some C - and some assembler (if for nothing other than looking at compiler output) - but I'm not sure I agree that C is "simple". And learning from k&r might not be the best approach today - rather read sources of something like some of the openbsd utilities, redis, spiped...

Re: Beej's Guide to C Programming (2007)

#42
post #20

Very good. A pet peeve is that it consistently says "sizeof()", like this: You can use the sizeof() operator to determine how many bytes of memory a certain type uses. (I know, sizeof() looks more like a function than an operator, but there we are.) BUT: sizeof does not in fact need the parentheses always! Syntactically they are part of the argument, and only needed when the argument is a type name, i.e. the argument…

Simply referring to it as the 'sizeof operator' would be preferable. Otherwise ignoring the ability to drop the parentheses seems fine though.

That way the author presents a simple, useful conceptual model and hints that it's actually a little more complicated than they described. Seems like a good trade-off, as there's lots of stuff to learn, and sizeof's hidden weirdness is unlikely to bite any students. When writing code, there's basically no drawbacks to just following the simpler rule of always using parentheses and it makes expressions a little easier to follow [1].

[1]: https://lkml.org/lkml/2012/7/11/103

Re: Beej's Guide to C Programming (2007)

#43
post #28

Earlier quoted context omitted.

While C remains the single most important programming languages of all time, its share of popularity is shrinking, giving way to C++, C#, Java, and Swift (from Objective-C). Nevertheless, I don't think anyone should call themselves a (true) programmer unless they know C. C is easy to learn, because it's a small language. If you are not new to programming, pretty much all there is to know is in the second edition of t…

> "Nevertheless, I don't think anyone should call themselves a (true) programmer unless they know C." You could make an even stronger claim about knowing an assembly language. The point being that understanding how a computing device works is helpful in getting the best out of it. If that wasn't your point, then C is no more special than any other popular programming language. Also, whilst I only know the basics of C…

> If that wasn't your point

It wasn't; it is perfectly possible and normal to use C as one would any other programming language, i.e. without knowing much about the computer architecture. Even the pointers, often seen as something low-level, aren't really: the rules of their behavior and use are very simple, and they are easy to describe at a high level.

C is special in that, as I said, it has been, and remains, a very important programming language in its ubiquity and sheer power.

Re: Beej's Guide to C Programming (2007)

#44
post #32

Earlier quoted context omitted.

I'm assuming you wrote this comment as a C programmer (or have used C in a professional setting?) If so - how did you get into that? I'm really looking to _build_ something rather than just going through a book or tutorial (although they have a place and time). ' I suppose my objectives are learning as much as I can, and (ideally) having a day job working with that technology. All of this is more or less driven by in…

It will be a frustrating experience to learn C with a mindset of career. The mindset of career is about results, C is often not a shortcut to most superficial (visible) results. (It is a shortcut to real programming skill though, but a real skill without paper career record doesn't mean much for your career.) But if you can afford a hobby and have the luxury of certain time at disposal, then I would suggest you to ap…

Thanks for your interesting perspective :)

I always think of people who use C professionally as people who have been doing it for a _very_ long time and know a lot about it. In that situation it would be exceptionally hard to find any employment working with C.

I've always been hesitant at many Project Euler problems since some of the math is off putting to me. That's why I consider building something (like a side project or something of use).

Using C as a learning tool to better understand programming would be a great idea and I'll likely venture into that- hopefully something comes of it though! :)

Re: Beej's Guide to C Programming (2007)

#45
Are there any good tutorials for cross platform development with C++ on windows.

I just want to avoid MSVC compilers and use clang or gcc.

Also, C++ module/package/library management is very very confusing. You have to configure multiple files in multiple folders and multiple configuration entries.

I tried it almost a dozen times and just left it out of frustration.

Compared to development with python, it's just mind numbing.

Re: Beej's Guide to C Programming (2007)

#46
post #44

Earlier quoted context omitted.

It will be a frustrating experience to learn C with a mindset of career. The mindset of career is about results, C is often not a shortcut to most superficial (visible) results. (It is a shortcut to real programming skill though, but a real skill without paper career record doesn't mean much for your career.) But if you can afford a hobby and have the luxury of certain time at disposal, then I would suggest you to ap…

Thanks for your interesting perspective :) I always think of people who use C professionally as people who have been doing it for a _very_ long time and know a lot about it. In that situation it would be exceptionally hard to find any employment working with C. I've always been hesitant at many Project Euler problems since some of the math is off putting to me. That's why I consider building something (like a side pr…

>> I've always been hesitant at many Project Euler problems since some of the math is off putting to me. That's why I consider building something (like a side project or something of use).

Math has the nature of simplicity -- well defined and little complication, but abstract (or useless).

If you like building things, I would suggest a text editor or a GUI layout engine. For the latter, think about an intuitive declarative way of describing layout (like HTML/CSS or TeX or Tk) then implement it on native win32 API or GTK. Focus on the simplicity and in-control aspect; do not get distracted by feature completeness.

Re: Beej's Guide to C Programming (2007)

#48
post #24

As someone who currently works with C# - is there much of a point to learning C? I've always found it interesting, but never had a reason to jump into it.

Keep in mind that C and C#, in practice, aren't especially related. C is a low level, close to the machine, minimal systems language, while the latter is a modern, advanced, managed language.

Re: Beej's Guide to C Programming (2007)

#49
post #43

Earlier quoted context omitted.

> "Nevertheless, I don't think anyone should call themselves a (true) programmer unless they know C." You could make an even stronger claim about knowing an assembly language. The point being that understanding how a computing device works is helpful in getting the best out of it. If that wasn't your point, then C is no more special than any other popular programming language. Also, whilst I only know the basics of C…

> If that wasn't your point It wasn't; it is perfectly possible and normal to use C as one would any other programming language, i.e. without knowing much about the computer architecture. Even the pointers, often seen as something low-level, aren't really: the rules of their behavior and use are very simple, and they are easy to describe at a high level. C is special in that, as I said, it has been, and remains, a ve…

> "C is special in that, as I said, it has been, and remains, a very important programming language in its ubiquity and sheer power."

In that case, you could say the same about Java, Python, C#, etc... If being a "true" programmer is just about getting the job done, any of those languages will suffice. C may be a useful tool for certain performance critical code, but that's a very small fraction of what's required in most day-to-day programming activities. I would say the following list describes the key qualities of good code (in the order described, from most to least important, for most cases):

Correctness, clarity, conciseness, performance.

As for pointers, you can describe them at a high-level but to understand why they're a low-cost abstraction it's helpful to understand how computers work. That's the type of knowledge that C can help expose you to.

Re: Beej's Guide to C Programming (2007)

#50

Are there any good tutorials for cross platform development with C++ on windows. I just want to avoid MSVC compilers and use clang or gcc. Also, C++ module/package/library management is very very confusing. You have to configure multiple files in multiple folders and multiple configuration entries. I tried it almost a dozen times and just left it out of frustration. Compared to development with python, it's just mind…

You can now use clang as an alternative compiler in Visual Studio. Other option is to install bash on windows and install gcc/clang and use that.
Post reply on HN