Live data from Hacker News

Why Learn to Program in C?

philipbuuck.com

81–90 of 123 posts

Re: Why Learn to Program in C?

#81

Ugh, while I 100% agree that learning C (or similar lower level language) should be a prereq for any programming job, the use of the K&R C book is idiomatic of what is wrong with C. To many people pick up that book and try to emulate what they read. I firmly believe that book will teach you every bad habit you should never use in actual practice. 30 years ago, many of those "tricks" made sense given the compilers and…

What book (or other method) would recommend instead of K&R? (I agree with your point, I'm just curious)

Re: Why Learn to Program in C?

#82
post #78
post #57

Earlier quoted context omitted.

I have no idea what you're talking about. Are you interested in finding such a book? Do you try to refute any of my points? If so, which one?

I am not refuting. I was actually asking if there are CS books written in Lisp. Almost any CS book I've seen relies on C, C++ or something along those lines. > Are you interested in finding such a book? Yes.

Ah, okay.

Off the top of my head, only Structure and Interpretation of Computer Programs. But that's... different.

And Paradigms of Artificial Intelligence Programming.

Re: Why Learn to Program in C?

#83
post #78
post #57

Earlier quoted context omitted.

I have no idea what you're talking about. Are you interested in finding such a book? Do you try to refute any of my points? If so, which one?

I am not refuting. I was actually asking if there are CS books written in Lisp. Almost any CS book I've seen relies on C, C++ or something along those lines. > Are you interested in finding such a book? Yes.

Start with "Structure and Interpretation of Computer Programs".

Google it -- it's freely available on-line, along with a video lecture series.

It's different, in that it doesn't teach Scheme (Lisp). It teaches computation (aka CS).

Go from there.

Re: Why Learn to Program in C?

#84

Ugh, while I 100% agree that learning C (or similar lower level language) should be a prereq for any programming job, the use of the K&R C book is idiomatic of what is wrong with C. To many people pick up that book and try to emulate what they read. I firmly believe that book will teach you every bad habit you should never use in actual practice. 30 years ago, many of those "tricks" made sense given the compilers and…

> hardware support for base+displacement addressing

Not sure exactly what you mean by the "hardware support" part, unless it is machine instruction support of some kind for C syntax. (But I thought that a basic level of support for that was present in most processors - things like base + offset addressing mode, indirect addressing via the value in a register, etc.)

But:

a[i] is equivalent to star(a + i) in C. (The K&R book says so somewhere, in either the original or the ANSI C edition.)

And star(a + i) is equivalent to star(i + a), by commutativity (a mathematical property) which is equivalent to i[a]. [1]

So you can write any of the above 4 expressions equivalently. I verified it by writing and compiling such code after reading this in the K&R book years ago; still remember being surprised until I saw the logic made sense.

[1] Or at least, it was so, some years ago, not sure about in C99 and such.

I used "star" instead of the asterisk symbol in code above because the actual asterisk turned following text to italics - HN markup.

Re: Why Learn to Program in C?

#85
post #75

C is an abstraction. Assembly is an abstraction. Even physical transistors are abstractions. You can go down the ladder as deep as you wish, there is no bottom. (Sure, you can delude yourself you that X is the fundamental level of Y... as long as you define Y properly.) In this grand scheme of things, C is not better than Python. I don't mean the we should avoid going deeper. I mean that each level of abstraction has…

>How many of you started learning natural numbers not from counting fruits/blocks/candies, but from the ZF set theory axioms

Ha ha, good one. I don't even know what the ZF set theory is. Not putting down theory either in general or in this case, of course.

Re: Why Learn to Program in C?

#86
post #2

I'm surprised that people have managed to get through a CS program without learning C (or, at least, C++)! It seems to me that programming should be taught simultaneously in Haskell (or Lisp?) and C. - C teaches you how computers work. - Haskell teaches you how programming logic works.

> - C teaches you how computers work. Except it doesn't. If any language "teaches you how computers work", its assembly. While a lot of the quirks of C's design compared to more "pure" structured programming languages (e.g., Pascal) reflect a desire to provide more direct access to common low-level features of systems of the time when C was introduced, it doesn't really teach you how computers work except insofar as…

Agreed. I would say that C teaches you how the OS API works. That doesn't map well to how even a simple computer works, let alone one with multiple processors, complex memory hierarchies, north and south bridges, various I/O adapters, etc. Don't even get me started on anything virtual or distributed. Knowing C might help, to the extent that code which might be useful to gain such understanding tends to be written in C, but the language itself isn't going to impart those lessons.

Re: Why Learn to Program in C?

#87
post #28

Earlier quoted context omitted.

What language would you suggest is friendlier, and less rife with gotchas? I find the rules of C fairly reasonable, at least on the surface.

In no particular order any of the following as an introductory language. Ruby -- puts "Hello World" Python -- print "Hello World" Lua -- print("Hello World") Personally I wish every programmer would eventually learn C. Getting down to that low level and really understanding how things work is important, but if it is the first language I think we would end up with a whole lot less programmers as many would give up ear…

Ruby is written in C

Python is written in C

Lua is written in C

Re: Why Learn to Program in C?

#88

Earlier quoted context omitted.

Yes, but interpreted is slow, and garbage collection causes pauses at essentially random times. These things are fine for one off sorts of problems where it doesn't matter much if it takes a little longer. If you are writing an application that is meant to be run thousands or millions of times, I start to wonder why people don't care more about these trade-offs (the answer is, of course, they do . . . if they are, fo…

The main language at Amazon is Java. Lots of Java code is being run millions and millions of times there. Java isn't as slow as you think it is.

I didn't say Java is slow. I said that garbage collection introduces unpredictable pauses. This is potentially an issue with Java, but it all depends on the problem you are trying to solve. In many cases, it won't matter, but in some, it will.

How is this relevant to the idea that C is an important and relevant language?

Re: Why Learn to Program in C?

#89

Earlier quoted context omitted.

In no particular order any of the following as an introductory language. Ruby -- puts "Hello World" Python -- print "Hello World" Lua -- print("Hello World") Personally I wish every programmer would eventually learn C. Getting down to that low level and really understanding how things work is important, but if it is the first language I think we would end up with a whole lot less programmers as many would give up ear…

Ruby is written in C Python is written in C Lua is written in C

I'm not sure how that is pertinent. Programming languages as a general rule are initially implemented in some other programming language and then potentially later bootstrapped with their own language.

Ruby has also been implemented in Java (JRuby), Ruby (Rubinius), .NET (IronRuby), JavaScript (Opal).

Python in Java (Jython) and .NET (IronPython)

Lua has been implemented in too many language for me to list them all here (C, C++, Lua, JavaScript, Erlang, OCaml, Go, etc...)

It seems C itself was initially bootstrapped from B which was bootstrapped from BCPL. If we were to follow this to it's logical conclusion I'm guessing we end up at some version of Assembly. Are you suggesting we should start budding programmers on Assembly?

Re: Why Learn to Program in C?

#90

Earlier quoted context omitted.

Ruby is written in C Python is written in C Lua is written in C

I'm not sure how that is pertinent. Programming languages as a general rule are initially implemented in some other programming language and then potentially later bootstrapped with their own language. Ruby has also been implemented in Java (JRuby), Ruby (Rubinius), .NET (IronRuby), JavaScript (Opal). Python in Java (Jython) and .NET (IronPython) Lua has been implemented in too many language for me to list them all h…

No. Just stick with C so that it's portable and fast.
Post reply on HN