News for hackers. Stuff that matters.
Re:Learn C programming and the rest will come by alew1 on Wednesday November 29, 2017 @10:00AM (#15807231)
Meh. Learn any language and “the rest will come” if you then learn other languages. Some of these points don’t lead to C’s being a better first language or pedagogical language — like, why should a learner care that C is so fast? I teach HS computer science and we do use C, in our Data Structures course, after students have used Racket, Python, and Go. Using those other languages lets us cover interesting and important topics like recursion, data abstraction, concurrency, and more, all while doing projects that hold kids’ attention (sometimes using outside libraries for image or sound processing, e.g.). C is well-suited to the data structures course where students have to think carefully about memory and efficiency.

I can certainly imagine a different sequence, where students learn logic gates, hardware, assembly, then C, working their way up to higher levels of abstraction. Even in this case though, the goal isn’t to jump in and start writing big programs in C right away.

Re:Learn C programming and the rest will come by maxxxxx on Wednesday November 29, 2017 @10:06AM (#15807290)
I think people should understand pointers, heap vs. stack and other things. even in higher level languages a lot of performance problems can easily be explained if you understand how memory works. I often see people allocating and copying huge arrays back and forth and then thinking they need bigger machines.
Re:Learn C programming and the rest will come by cloudster314 on Wednesday November 29, 2017 @10:11AM (#15807327)
I agree that people should understand pointers, heap and stack. However, there's going to be drop outs from the class if these things are focused on too early. Of course, this is open to debate, which is why we have this type of healthy discussion. You might be right in your assumption that it's better to introduce these concepts earlier. In know that when I was in high school, these concepts were taught and served as a foundation for further learning. It's out of vogue now to teach these concepts to kids. But, you might be right. I need to think about this more. Thank you for your posts.
Re:Learn C programming and the rest will come by agoodthrowaway on Wednesday November 29, 2017 @11:08AM (#15807857)
Dropouts are ok and honestly a good thing. Not everyone is cut out to be an engineer.

I think the commenter is correct. C makes you learn how a computer works. As your code gets more sophisticated you'll eventually have to know this or you can't take your work to the next level. I don't know C all that well and I'm currently facing gaps in my knowledge that would be filled in had I spent some time with a C compiler.

Re:Learn C programming and the rest will come by ralmidani on Wednesday November 29, 2017 @06:52PM (#15812037)
That's like saying everyone should be introduced to Math via integration rather than counting because not everyone is cut out to be a Mathematician.

I accept your premise that we don't want to push people into professions they are not capable of doing well in. But basic knowledge of programming is becoming important enough that I think providing a gentle intro is wise. Like Math and Physics, you can ramp up the difficulty in later classes.

Re:Learn C programming and the rest will come by maxxxxx on Wednesday November 29, 2017 @11:29AM (#15808049)
"Dropouts are ok and honestly a good thing. Not everyone is cut out to be an engineer."

Agreed. Unfortunately the job market pushes people into professions they are not suited for. I bet 90% of lawyers do it for the career prospects and not because they like law.

Re:Learn C programming and the rest will come by alew1 on Wednesday November 29, 2017 @01:51PM (#15809625)
Agreed! It's a question of how you introduce them to these ideas. One option is to start at the bottom (hardware) and go up, so that pointers feel like a welcome abstraction when students encounter them in C. (They will already be used to thinking about memory addresses in assembly.)

The other option, and the one I choose, is to go from high-level languages down. What I'm not so sure about is just throwing people in in the middle, so that they are trying to grasp abstractions like functions and variables at the same time as they are trying to understand pointer arithmetic.

In the subset of Racket we use, all values are immutable, so an understanding of memory (stack vs. heap) is less necessary. We do still talk about "frames" to understand lexical scope, though, and students get used to thinking of each function call using up a new "frame" of memory to store its local variables. This allows them to understand the memory efficiency of recursive functions.

We then move onto Python, and _do_ talk about an "environment" (stack) and a "heap" (I call the heap "object-land" because objects live there). This enables us to talk about garbage collection. More importantly, students get used to thinking about variables as being bound to either primitives or pointers to shared memory.

In Go, there _are_ pointers, and students get used to thinking about memory addresses as values. They learn that pointers are useful both for sharing mutable references, and for avoiding expensive copies. (In Go, arrays are values, and passing a large array to a function copies it.) But none of the sharp edges of C's pointers are present. Go does "escape analysis" so that if you return a pointer to a local variable, that local variable is allocated on the heap; it is safe to point to anything and if you do, it won't be garbage collected. There's no pointer arithmetic.

By the time they see C, in the third-year course, a lot of the pieces are in place to have a good understanding of how the stack and heap (and manual memory allocation) really work. And along the way, because they were using higher-level languages, the students have been creating cross-platform, complex programs (web servers, games, etc.) that they're proud of. :-)

Re: sibling's comment that "some people aren't cut out to be engineers," I think that's a somewhat dangerous attitude. I think the study of computation is profound & rewarding and should be part of a liberal arts education for everyone; even apart from that, programming is also a useful skill for people who won't get a job as an engineer.

Re:Learn C programming and the rest will come by maxxxxx on Wednesday November 29, 2017 @02:34PM (#15810071)
"Re: sibling's comment that "some people aren't cut out to be engineers," I think that's a somewhat dangerous attitude. I think the study of computation is profound & rewarding and should be part of a liberal arts education for everyone; even apart from that, programming is also a useful skill for people who won't get a job as an engineer. "

Agreed that some basic skills are a good thing. But in the same sense that I have some grasp of writing but never will be a good writer or enjoy it, a lot of people are just not cut out to be software engineers. It would be a sad world if everybody had the same talents.

Re:Learn C programming and the rest will come by pjmlp on Wednesday November 29, 2017 @10:31AM (#15807507)
I learned all those concepts in Pascal, BASIC and Z80, about 4 years before seeing C for the first time.

C isn't the only language with such features.

Re:Learn C programming and the rest will come by mcguire on Wednesday November 29, 2017 @10:40AM (#15807586)
Anyone seen Pascal, BASIC, or Z80s in the wild recently?
Re:Learn C programming and the rest will come by maxxxxx on Wednesday November 29, 2017 @10:41AM (#15807606)
Good. What other languages are still being used that teach these concepts?
Re:Learn C programming and the rest will come by pjmlp on Wednesday November 29, 2017 @11:02AM (#15807807)
D, Go, Ada, Rust, C#, Swift, Common Lisp, Eiffel, C++
Re:Learn C programming and the rest will come by maxxxxx on Wednesday November 29, 2017 @11:05AM (#15807833)
C# doesn't really. C++ definitely does. The others I don't know.
Re:Learn C programming and the rest will come by pjmlp on Wednesday November 29, 2017 @12:24PM (#15808739)
Sure it does.

- compiles to native code via ngen, mono, .NET Native, MDIL, IL2CPP

- has pointers in unsafe code

- has value types

- structs allow for layout control

- value types can be stack allocated, it also allows for alloca in unsafe code

- memory can be allocated outside GC via safe handles or marshaling services

- latest versions have support for zero allocation memory references

The only thing it doesn't do properly is to have global statics, but it can be worked around via a singleton.

Re:Learn C programming and the rest will come by maxxxxx on Wednesday November 29, 2017 @12:34PM (#15808873)
I wouldn't recommend using C# for learning these concepts. Unsafe mode exists but it's not very straightforward in my view. I don't think I could understand unsafe mode without prior knowledge of C.
Re:Learn C programming and the rest will come by pjmlp on Wednesday November 29, 2017 @12:43PM (#15808985)
It is all a matter of who teaches it and how.
Re:Learn C programming and the rest will come by moron4hire on Wednesday November 29, 2017 @10:08AM (#15807302)
I whole-heartedly agree. A lot of C-purists will say things like, "you can't understand programming until you understand pointers". I think it's the other way around. I think one will have quite a difficult time trying to understand how pointers work if your very first language is C where their usage is so prominent and in many cases arbitrary due to a systemic aversion to copying data for no other reason than micro-optimization.
Re:Learn C programming and the rest will come by fapjacks on Wednesday November 29, 2017 @10:14AM (#15807349)
My first language was C, back in the early 90s -- from nothing but the K&R book -- and I did learn pointers before I learned my next language (like truly grok them, have the ability to visualize the concept viscerally). When people in interviews ask me to tell them about the most technically challenging thing I've ever done, I tell them about learning pointers in C as a teenager. Taking everything in its context, nothing else in technology has gone that far in pushing my intellect.
Re:Learn C programming and the rest will come by moron4hire on Wednesday November 29, 2017 @10:26AM (#15807468)
I agree, it's extremely difficult to go from zero to "understands pointers". I think it's a hurdle that a lot of people have failed to clear and have quit programming to go into other, less-lucrative fields. I don't think it has to be that way, and I don't think there is any virtue in it, either.
Re:Learn C programming and the rest will come by nurettin on Wednesday November 29, 2017 @10:32AM (#15807524)
I was a C64 kid. Basic had peek/poke to read/write memory addresses directly. I still remember 53280 and 53281 as bytes to flip to change screen colors. So it came to me naturally when I saw assembler and Pascal pointers later on. It just depends on how you grew up.
Re:Learn C programming and the rest will come by jackhack on Wednesday November 29, 2017 @10:49AM (#15807680)
I agree - you can present a topic before the student is ready and confuse. That happens quite often, in fact. But it's not the fault of the language. And the student must have that background to be prepared.

C was the "universal assembly language." In its day, it was unimaginable that one would learn to program a computer without an understanding of the hardware underneath, or computer architecture in general.

>>a systemic aversion to copying data But this isn't an issue with the C language or pointers, per se; an "aversion" to unnecessarily moving data is the very essence of optimization. [As part of choosing the right algorithm to begin with, of course.] As Michael Abrash wrote: "the fastest code is the code that never runs." So eliminating work (such as moving bits across a bus) is key.

Re:Learn C programming and the rest will come by moron4hire on Wednesday November 29, 2017 @10:58AM (#15807765)
I never claimed it was the fault of the language. It's the fault of advocates pushing it as a viable first language. My point on premature optimization was precisely because of that: optimization should not be a concern for raw beginners, and C programmers as a culture value optimization in all things, even to the point of error (fast code is not necessarily secure code).
Re:Learn C programming and the rest will come by jackhack on Wednesday November 29, 2017 @11:09AM (#15807875)
Agree with you there & appreciate the clarification.

I would only add that many of those who obsess with optimization and "clever" programming, have never had to go back and maintain that code. I've looked at far too many modules and said "what was this idiot thinking?" before realizing it was my own work from years' prior.

With a bit of that perspective I now write code favoring clarity over cleverness/performance. And if it is unavoidable to write something dense, I document the hell out of it.

But you're right, there is a definitely a culture of writing impenetrable code full of clever & cute little tricks of the sort that come back and bite the author later. Prevalent in the C world, and I see it also in equal measure in Perl.

Re:Learn C programming and the rest will come by JoeAltmaier on Wednesday November 29, 2017 @10:19AM (#15807397)
If you don't understand when you're working on a mutable version of a data structure vs a copy, you can't get very far. So at least that part of 'understanding pointers' is crucial in any language?
Re:Learn C programming and the rest will come by moron4hire on Wednesday November 29, 2017 @10:23AM (#15807439)
I don't know what companies you've worked at, but you can clearly get pretty far without having that sort of mastery over a particular language. I'm not saying it's good to stay in that state of ignorance, but it's definitely a thing, and I think the more gentle introduction to learning the topics that dynamic languages provide makes it more likely people will stick with programming at all, rather than quitting and changing their major to History or something.
Re:Learn C programming and the rest will come by jackhack on Wednesday November 29, 2017 @10:59AM (#15807774)
>>but you can clearly get pretty far without having that sort of mastery over a particular language.

Completely agree. If this weren't true, the fizzbuzz test wouldn't exist.

The 90s were filled with businessmen creating Access databases that wouldn't scale, and Visual Basic's drag-and-drop capabilities created a cottage industry for controls consumed by non-programmers.

That's both good and bad. Bad for the obvious reasons (lots of crap software) but good in that for the most part people were able to build what they needed to solve problems and move on.

Re:Learn C programming and the rest will come by meredydd on Wednesday November 29, 2017 @11:11AM (#15807889)
The trick is to benchmark that "crap software", not against the architectural marvel you would build, but against the Byzantine Excel spreadsheet (or worse, binder of paper forms) that would have been used otherwise.

Nowhere is "worse is better" more true than line-of-business software.

Re:Learn C programming and the rest will come by alew1 on Wednesday November 29, 2017 @01:59PM (#15809694)
I'd agree, and even in Python, we end up talking about how some variables store "memory addresses," to explain the sometimes confusing behavior of variables bound to mutable objects. What's less essential is understanding all the ways that (C's) pointers can bite you: pointer arithmetic that results in invalid addresses, use after free, dereferencing uninitialized pointers, returning a pointer to a local variable from a function, and so on.
Re:Learn C programming and the rest will come by cloudster314 on Wednesday November 29, 2017 @10:07AM (#15807297)
Thank you for posting this reply as I agree with many of your points. Also, I didn't know about Racket, which looks like a good tool for teaching. I would like to learn more about how you use Racket. Many years ago, my high school taught fortran first and then assembly as the AP course. This was later changed to Pascal. I believe that assembly was used for some of the same reasons the author is suggesting C. However, I also think that learning Python and Go is a better starting point. Learning about pointers is going to cause a significant portion of the class to drop out or tune out. At some, they will need to learn more about memory addresses, but I think that it can come later when performance becomes more of a concern.
Re:Learn C programming and the rest will come by alew1 on Wednesday November 29, 2017 @01:57PM (#15809677)
For our first semester, we use a modified version of "How to Design Programs": http://www.ccs.neu.edu/home/matthias/HtDP2e/ Highly recommended for teaching! I do teach pointers, but in stages — so that students can understand the mutability behavior of Python lists and other objects, we talk about how a Python list variable, for instance, is _really_ storing a memory address of a list. When we move to Go, they actually use pointers, but unlike C's, it's hard to shoot yourself in the foot with Go's pointers. When we finally get to C, pointers seem natural.