Live data from Hacker News

Why I Chose to Learn C

viget.com

31–40 of 78 posts

Re: Why I Chose to Learn C

#31
post #4

C really is fantastic language to learn. When I learned it, I also came from the scripting language world (Python, PHP). Having that as a base, then learning C, lead to revelations about how those scripting languages are created, and how the data structures I took for granted in a scripting language are actually implemented. From what I understand in formal CS courses, you learn from the bottom up, but learning from…

> I took for granted in a scripting language are actually implemented.

Exactly. Not only that you but I had started to appreciate the scripting language (Python) more because I see much it does for you. I knew that before but actually seeing how one would have to handle reference counting, error handling it is nice to go back to Python.

Re: Why I Chose to Learn C

#32
post #17

Earlier quoted context omitted.

Here's another surprising (but fully understandable) perspective given in the OP: "Function pointers — It was interesting to me to see that such a low-level language contained functional programming concepts." If you started from assembly and worked up, this looks very different, because at that very low level, functions and data look the same too. (Just like Lisp).

How is that assembly has code as data just like Lisp? Is it possible to create executable code during runtime, change the language's syntax, and stuff like that, using assembly?

Assembly language is just a high level description of machine code: each assembler statement maps to one machine instruction. Those machine instructions are nothing but sequences of bytes. It is certainly possible to create executable code during runtime; you just write the appropriate bytes into a buffer, mark the buffer as executable, and jump in.

Back in the old days, before memory protection, we used to do all kinds of code-as-data-as-code tricks. I remember dynamically generating trampoline functions that effectively did partial application. I'd write a little stub of assembly code that would push a bunch of literal zeros onto a stack and then jump to zero; when I wanted to use it, I'd copy it, poke actual values into the literals, and then pass it along as a zero-parameters function pointer.

You don't change the language syntax; that doesn't really make sense in assembly world. It's more that assembly code lives in a world of bytes and pointers, and is itself very directly composed of bytes and pointers, and so it's as easy to use the same bytes-and-pointers concepts on code as it is on data.

This style still exists on microcontrollers, where there is generally no operating system. Instead, your compiler produces an image which you flash onto the controller chip. The controller has some startup sequence which jumps to some address in flash and runs. The chip's subsystems are controlled by registers located at specific addresses; in order to drive such a device you have to know how its address space is laid out, where your code is placed in it, and how your code interacts with the different types of memory and registers located in the address space.

Re: Why I Chose to Learn C

#33
post #23

Earlier quoted context omitted.

I dual booted for about a year, and then I used virtual machines instead for the last year. Using virtual machines has been a LOT easier. I use Lubuntu on Virtualbox, and I don't plan on going back. Things that annoy me about Ubuntu dual boot * My Wacom tablet is terribly hard to configure on Ubuntu. * Flash support seems to be hit or miss in terms of out of the box functionality. Sometimes it works right when you in…

Whatever works with your hardware and use cases! I was thinking more of a group of people meeting to work through the Learn C the hard way book, perhaps in a coffee bar or something, bringing their own laptops. A bootable stick might make a C environment more accessible to them. The puredyne project produced a bootable linux specifically to provide a common environment for training in audio production. Seemed to work…

If you bring a copy of the ISO you can have them all on starting from the same Virtualbox install (takes 5 minutes to set up without knowing the software + Ubuntu installation time).

But I've heard Vagrant is good for use cases like yours, though I haven't personally used it.

That sounds like a fun activity by the way, have fun with that :)

Re: Why I Chose to Learn C

#34
post #17

Earlier quoted context omitted.

Here's another surprising (but fully understandable) perspective given in the OP: "Function pointers — It was interesting to me to see that such a low-level language contained functional programming concepts." If you started from assembly and worked up, this looks very different, because at that very low level, functions and data look the same too. (Just like Lisp).

How is that assembly has code as data just like Lisp? Is it possible to create executable code during runtime, change the language's syntax, and stuff like that, using assembly?

Of course, I did not say assembly is just like Lisp in every respect.

But as long as we're picking nits --

It is of course completely possible to create executable code during runtime, using assembler. Often not advisable. (Recall the punch line of: http://www.cs.utah.edu/~elb/folklore/mel.html)

Re: Why I Chose to Learn C

#35
For those who hit a wall with C when it came time to learn pointers, I'd like to plug a YouTube video I made that people seem to really like.

https://www.youtube.com/watch?v=IkyWCOUY8V4

The terminology may not be completely accurate (although I did try very hard to not say anything incorrect), but I honestly think it does a good job of showing you how to actually use pointers. I know the resident C experts will probably find something wrong, but I've received tons of comments and emails from people saying they finally "get it". It's something I'm proud of.

Re: Why I Chose to Learn C

#36
Re Valgrind: Last time I worked through CTHW, I couldn't use Valgrind because of missing OS X 10.8 support and I felt like I was missing a lot by not using it. I'm tempted to go back and work through it again, this time with a VM.

Re: Why I Chose to Learn C

#37
post #28
post #4

C really is fantastic language to learn. When I learned it, I also came from the scripting language world (Python, PHP). Having that as a base, then learning C, lead to revelations about how those scripting languages are created, and how the data structures I took for granted in a scripting language are actually implemented. From what I understand in formal CS courses, you learn from the bottom up, but learning from…

I too started with scripting languages, and also learn in a similar way. Hearing the value that learning C provided you makes the decision to learn it myself a simple one. To those versed in C, is the tutorial linked in the original article a recommended one?

I would enthusiastically recommend Learn C the Hard Way, even over K&R (which hasn't aged well, for reasons LCtHW explains (http://c.learncodethehardway.org/book/krcritique.html)).

Re: Why I Chose to Learn C

#38
post #28
post #4

C really is fantastic language to learn. When I learned it, I also came from the scripting language world (Python, PHP). Having that as a base, then learning C, lead to revelations about how those scripting languages are created, and how the data structures I took for granted in a scripting language are actually implemented. From what I understand in formal CS courses, you learn from the bottom up, but learning from…

I too started with scripting languages, and also learn in a similar way. Hearing the value that learning C provided you makes the decision to learn it myself a simple one. To those versed in C, is the tutorial linked in the original article a recommended one?

I personally didn't like Learn C the Hard Way at all. I can see the approach for Learn {language} the Hard Way (mostly examples and exercises) working well for languages like Python or Ruby but I felt that for C it was too vague and each exercise didn't really give me an idea of what I was learning/accomplishing. With the other languages you can get away with focusing on functionality but I think you really need a more indepth understanding in C to avoid headaches involved with the language. While C Programming Language by K&R is a little dated, I still think it gives you a better idea of learning the language or at the very least, how to navigate the code and find your answers better.

Disclaimer: I already knew C fairly well and decided to go through LCTHW to see if I could pick up any hidden gems; might differ for someone with little to no experience.

Re: Why I Chose to Learn C

#39

Re Valgrind: Last time I worked through CTHW, I couldn't use Valgrind because of missing OS X 10.8 support and I felt like I was missing a lot by not using it. I'm tempted to go back and work through it again, this time with a VM.

This is the kind of thing which makes OS X generally less productive for (non-Apple) development than it could be.

Re: Why I Chose to Learn C

#40
post #23

Quote below from Learning C the Hard Way " For Windows users I'll show you how to get a basic Ubuntu Linux system up and running in a virtual machine so that you can still do all of my exercises, but avoid all the painful Windows installation problems. " A bootable Ubuntu USB stick with persistent storage might be easier to get started with? Can be created from a Live CD. Interesting idea.

I dual booted for about a year, and then I used virtual machines instead for the last year. Using virtual machines has been a LOT easier. I use Lubuntu on Virtualbox, and I don't plan on going back. Things that annoy me about Ubuntu dual boot * My Wacom tablet is terribly hard to configure on Ubuntu. * Flash support seems to be hit or miss in terms of out of the box functionality. Sometimes it works right when you in…

That's strange, I've never had a problem with Wacom on Ubuntu
Post reply on HN