News for hackers. Stuff that matters.
Re:Why Learn to Program in C? by bluedino on Monday February 01, 2016 @11:58AM (#11013022)
C is great. I wouldn't recommend starting programming in C, though. At least not with the standard exercises you see. Get user input, read a file, do this do that with it.

Why? the C standard library is full of gotchas and tricks and goofy shit that makes it unsuitable for new programmers. The comp.lang.c FAQ should be standard reading material for anyone taking a C class. Look at all the posts on StackOverflow about the stdio functions 'not working right' and asking how to do menial things like collect keypresses.

C works well as a first language if you teach it like assembly (use of which as a teaching language is another debate): flip some bits and do some loops. But not for collecting user input/output. Half of your students are going to get stuck trying to collect a list of names from the user, before they even get a chance to get stuck trying to sort the list.

Re:Why Learn to Program in C? by DyslexicAtheist on Monday February 01, 2016 @12:37PM (#11013398)
My first language was C and I loved it. Maybe it takes a certain type of mindset and tenaciousness (madness?) that will put up with the gotchas. It was exactly those gotchas that got me hooked though. It was similar gotchas that made me love Linux the terminal, vi etc ...

The argument that one "should study other languages before they're fit to learn C" is terrible IMO and somewhat condescending. It's like saying one must learn "nedit/pico" before starting with editors like "emacs/vi". Please stop repeating that - especially if you have not done much C.

I am probably too old to understand the constant hate and criticism on why C shouldn't be taught to beginners. Not everything "has to be easy". Starting with C & Linux, I always had an advantage later in my career because it was these skills that enabled me to drill deeper than those who didn't know C & system programming.

C isn't just hard for beginners because of the language but the rest of the tool-chain. If you can get over this then learning C will also teach how to debug with gdb, strace, valgrind and learning about low level system calls, and a great deal about how a program can be loaded/structured e.g.: dynamic & static linking. Also where the resources are used and how to eliminate it’s bottlenecks. What is a heap, stack or static memory? How does memory management or garbage-collection work on a modern OS? What is IPC and how do the individual system calls function & require as input? How do you compile a program and optimize it for different target platforms? How do you write Makefiles or use autotools etc ...

Tell me again which other language forces you to learn these things? You could easily build a career just on C & Linux because of this "additional learning curve" and extra knowledge that a good C developer will have.

Sorry for all my bias (as I said my views might be very outdated :-))

Re:Why Learn to Program in C? by marcelluspye on Monday February 01, 2016 @01:01PM (#11013675)
It sounds to me like you haven't spent much time trying to teach a class to program. Most introductory courses these days focus on trying to teach students to understand how to solve problems (usually to some degree agnostic of language) and then how to turn their solution into code. The largest mental leap seems to be with the former, and using C as a starting language makes the latter unnecessarily difficult compared to, say, python (which is why it's gaining such popularity among intro. courses

I can understand if one is a) very motivated and b) has the right mindset to properly frame their ideas at the low level c operates at, C could be a good starting language. But this is not the case for many beginners.

Re:Why Learn to Program in C? by vram22 on Monday February 01, 2016 @03:57PM (#11015368)
>Most introductory courses these days focus on trying to teach students to understand how to solve problems (usually to some degree agnostic of language) and then how to turn their solution into code.

The "to some degree agnostic of language" part has been available for a long time in computers, initially as flowcharts and later as pseudocode.

>and b) has the right mindset to properly frame their ideas at the low level c operates at, C could be a good starting language

That requires prior knowledge and practice more than a mindset, IMO.

Re:Why Learn to Program in C? by Cpoll on Tuesday February 02, 2016 @10:13AM (#11019860)
I agree with this sentiment. In my experience, it's hard enough for a novice to learn to reason through basic control flow (loops, functions, variable assignment).

Over a few years of working as a teaching assistant, I saw two types of students: those that had some prior knowledge and effortlessly picked up the concepts, and first-timers that had to put in serious effort to stay afloat. If you were in the former camp, it's hard to envision how the latter might feel, and why every bit of additional complexity is a menace to someone who's already struggling with frustration over internalizing the basics. If you add too much complexity, the novice becomes discouraged, gives up trying to understand, and simply tries to memorize - this is always catastrophic for them.

As an example, I'm taking about students that write code like:

  if(x == true){
      y = true 
  } 
  else if (x == false){
      y = false
  }
Re:Why Learn to Program in C? by gnuvince on Monday February 01, 2016 @01:05PM (#11013723)
Learning to program is about solving problems using a computer. Any programming language allows this, however some languages make it harder than others, and C is in that category. A language like Python has very little quirks that will stump a person coding for the first time in their life; in C they'll wonder "what does int main(int argc, char argv) mean?", "why is there a & before my variable in a scanf but not in printf?", "what are 'nul-terminated' strings?", etc.

A programmer should definitely eventually learn C, but there's no reason it needs to be their first language and definitely no reason it should be their only language.

Re:Why Learn to Program in C? by vram22 on Monday February 01, 2016 @04:00PM (#11015394)
>in C they'll wonder "what does int main(int argc, char argv) mean?

They'll only wonder that if the book / course / instructor teaching them C, does NOT explain it to them. Which would be more of a reflection on said book / course / instructor than on the C language or the students.

Re:Why Learn to Program in C? by na85 on Monday February 01, 2016 @07:04PM (#11016711)
For students who are just learning to wrestle with the programming concept, python is far superior because it lets the student focus more on what to express and when, and less on remembering silly things like curly braces and semicolons.
Re:Why Learn to Program in C? by vram22 on Monday February 01, 2016 @07:48PM (#11016946)
First, braces and semicolons are not silly. They are just a different form of syntax than indentation. (And I say that as a Pythonista of many years, who also learned and then used C a lot before learning Python.)

Second, your point may (or not) be correct, but it is at best tangentially related to the point I was replying to, or to mine.

Re:Why Learn to Program in C? by na85 on Monday February 01, 2016 @11:34PM (#11017653)
I don't think it's tangentially related at all. The cognitive load of trying to program for the first time is quite high.

If the student doesn't have to focus on remembering whether or not you need a semicolon or a colon on switch statement cases, they can focus more on actually grokking the process of translating thoughts and algorithms to code.

Re:Why Learn to Program in C? by bluedino on Monday February 01, 2016 @01:22PM (#11013898)
>> A language like Python has very little quirks that will stump a person coding for the first time in their life

Python is great but some of the things I've come across:

  Why do some keywords use parenthesis and others don't?
  What's this Python 2/3 hubbub all about?
  What are __INIT__ and __MAIN__?
  Why do I see single, double, and triple quoted strings?
  What does the u prefix mean in u"Hello World"?
Re:Why Learn to Program in C? by kedean on Wednesday February 03, 2016 @08:49AM (#11026405)
Well sure, every language has its quirks, but those last four aren't going to show up unless the person starts diving into an existing codebase, which shouldn't happen if they're still learning. The keys/parenthesis bit I will concede is a bit of a problem.
Re:Why Learn to Program in C? by DyslexicAtheist on Monday February 01, 2016 @01:14PM (#11013798)
I agree it is not easy. Though I never said that it should be the only language! Emphasis was on the fact that one could build a career on C more than any other because of the additional overhead / toolchain baggage. (I quite frankly haven't met anyone who only knew C tbh and doubt such individuals exist in the industry (in a successful capacity))
Re:Why Learn to Program in C? by bluedino on Monday February 01, 2016 @01:15PM (#11013816)
>> C isn't just hard for beginners because of the language but the rest of the tool-chain.

I can agree with this, if not moreso the fact that you also have to learn the underlying system when you learn C.

For example, I 'learned' C from Greg Perry's "C Programming in 12 Easy Lessons". I was 11 or 12 years old at the time, had played around with a few other languages, but I knew C was the language video games were written in, so I wanted to learn C.

Part of the reason I wanted to buy that book was because it came with a compiler, Borland C++ 1.0. The book was also only $29.99 and was at a store in town. You'd be learning how to use functions like fscanf() but they never covered the details of 'when things go wrong'. You're missing some bytes, your file is incorrect, DOS does this while UNIX does that... You learn just enough to get you in trouble.

Sure, one book can't teach you everything, but it wasn't quite enough to give you a real good understanding of how C worked.

http://www.amazon.com/C-Programming-12-Easy-Lessons/dp/06723...

I eventually bought a game programming book and started to learn all the 'hard' stuff that I didn't even dream about when I first started. x86 interrupts, accessing joysticks and sound cards, writing to video memory...

All of this can be solved to a point by dumbing it down and using libraries. You still have to make sure you've got things like pointers down, though. You don't quite have to worry about that stuff with say, QuickBASIC or Turbo Pascal.

Re:Why Learn to Program in C? by ufo on Monday February 01, 2016 @01:39PM (#11014101)
I think there is a bit of a "survivor's bias" in this argument (which I actually hear very often). Many people give up after they first dabble with programming because its too hard or frustrating and C is a particularly unforgiving and restrictive language (and toolchain).

The reason I think this is important to point out is that I believe programming knowledge could be more widespread than it is today but unforgiving beginning languages tend to weed out people who aren't as familiar with computers as we are.

Re:Why Learn to Program in C? by DyslexicAtheist on Tuesday February 02, 2016 @05:01AM (#11018553)
I too think this survivor bias is kind of a key point yes. Also from my experience if I survive a steep learning curve I tend to build an elitarian view of my skills And I have seen this in most developers out their defending whatever it is they do. If you put your blood, sweat and effort into something it will stay with us. (I have seen this attitude also in others during countless flamewars on usenet when discussing the right editors, linux flavors etc, LOL ... and nobody really spends years studying something that was really hard and then gives up on it without defending it. There is just too much (self-)conditioning in the process of acquiring the skill.

In the end people will always choose the tool they're most comfortable with, whether it's the right tool for the job or not. I have no problem with this because, if there are not enough C experts in the team to maintain the project, it would be a good enough reason why a high-level language becomes the "right tool for the job".

Re:Why Learn to Program in C? by dllthomas on Monday February 01, 2016 @12:55PM (#11013586)
> The argument that one "should study other languages before they're fit to learn C" is terrible IMO and somewhat condescending.

I think I agree.

> It's like saying one must learn "nedit/pico" before starting with editors like "emacs/vi".

It's very little like that. Other languages have their own strengths in a way that nedit/pico do not.

Re:Why Learn to Program in C? by im_a_bug on Wednesday February 03, 2016 @12:36AM (#11024904)
Harvard's CS50 begins with C and it's quite successful. Well, technically they begin with Scratch, but the course quickly moves into C. They get around certain barriers (you mention user input) by providing helpers/abstractions, which are gradually torn down as the course progresses.
Re:Why Learn to Program in C? by bitwize on Tuesday February 02, 2016 @04:04AM (#11018367)
I think that if you are going to teach someone the craft of programming (which is different from computer science) -- really teach them, you should follow what I call the Old School Curriculum. The Old School is based on the way many kids learned to program in the 80s, and the 80s version went: first BASIC, then assembly, then Pascal.

The first language you should learn should be a doddle to learn, even if it isn't very powerful. This was BASIC (or sometimes Logo) back in the 80s, but you could probably substitute Python or even Scheme today. This language teaches you concepts like these:

* Computers follow instructions supplied by the programmer

* The instructions have to be carefully worded in order for a computer to follow them (i.e., intro to errors and debugging)

* Arithmetic and mathematical operations a computer can perform

* Computers can remember things (i.e., variables)

* Computers can interact with the world (input and output)

* Computers can make decisions (conditionals and program flow control)

These are the very fundamentals of programming and it's amazing how many people haven't internalized these concepts at a deep level.

You can actually get very far with BASIC -- entire companies have been run with BASIC code. (Software written in and for Business BASIC variants was a major industry back in the 1970s and 1980s.) You can get even farther with Python. But once the learner is ready to go deeper, it's time to begin Phase 2.

The second language you learn should be assembly, which familiarizes the programmer with how a computer actually works at a fundamental level, as well as important concepts like CPU word length, memory addresses (essential for understanding pointers), program call and return (and stacks), etc. You don't have to even complete a large project written in assembly to get the benefits of this low-level, bit-twiddling learning.

Finally, the last language you learn should be Pascal. C or C++ would be today's equivalent. In this phase you synthesize the knowledge of high-level programming, structure, and control flow that you learned during your "BASIC" phase with your low-level understanding of machine details that you learned during your assembly phase. Then, the details of how and why the language works the way it does make much more sense.

So yes, to me it makes total sense to teach C -- as (at least) a third programming language, perhaps after several years of proficiency are acquired in the other two (depending on the student).

Re:Why Learn to Program in C? by sklogic on Monday February 01, 2016 @12:45PM (#11013493)
"Unsuitable" is far too strong a word. It was ok for generations to follow the K&R examples, and now it somehow suddenly became "unsuitable"? I'd say it's just "somewhat more tricky" and "got a slightly steeper learning curve", that's it.
Re:Why Learn to Program in C? by kungtotte on Tuesday February 02, 2016 @09:34AM (#11019596)
If you start with C as your first language you're not really starting out by learning how to program, you're starting out by learning how the computer operates.

I'm not saying this is necessarily a bad thing, mind you, but it's important to note the distinction.

Using an analogy; starting out with C is like learning to drive by being told how an internal combustion engine works, and then you're asked to wire up your pedals manually and install a fuel tank of sufficient size before you're allowed to learn how to put the car in gear.

Those are all useful things to know, but you can learn them after you know how to drive, and your knowledge of either topic (driving and automotive engineering) is not in any way impaired by learning it in a different order.

Re:Why Learn to Program in C? by sklogic on Tuesday February 02, 2016 @09:54AM (#11019711)
Why? C is a very high level language. It is not that dramatically different from Pascal, which, in turn, is almost a pseudocode from your algorithm textbooks. You can learn fairly abstract concepts with C without caring at all about how it maps to the hardware.
Re:Why Learn to Program in C? by arc0re on Monday February 01, 2016 @12:38PM (#11013410)
I started with C and it took me 3 good years fooling around with other languages too to get a "good" understanding of C. Better learn with higher level languages indeed...
Re:Why Learn to Program in C? by agumonkey on Monday February 01, 2016 @12:48PM (#11013512)
Which languages ?

How common is it for people to get better understanding by travelling in other programming cultures ? My personal experience goes this way but I rarely hear it.

Re:Why Learn to Program in C? by ufo on Monday February 01, 2016 @01:34PM (#11014032)
I'm not the parent poster but in my opinion, any language that doesn't frustrate the beginner is fine. The most important thing for learning is practice and if that is not fun people will end up quiting to do something else.
Re:Why Learn to Program in C? by agumonkey on Monday February 01, 2016 @04:20PM (#11015556)
I hesitated to say that, but to me the most important part is paradigm and structures/patterns. lisp will teach you untyped tree recursion and metalevel perspective. ml/haskell will teach you typed composition. prolog goal based space exploration. forth stacks. APL arrays. C/Pascal etc are supposed to teach you 'imperative' but I believe imperative is mostly a conflation of lots of things, mutable state.. at best you'll learn state machines.
Re:Why Learn to Program in C? by ufo on Monday February 01, 2016 @05:57PM (#11016319)
I agree with you but I think paradigms are more of a "second" language problem than a "first language" problem.
Re:Why Learn to Program in C? by agumonkey on Monday February 01, 2016 @06:21PM (#11016474)
You may be right. It's hard for me to really put myself in the shoes of a completely new learner.
Re:Why Learn to Program in C? by arc0re on Monday February 01, 2016 @07:19PM (#11016778)
Yeah exactly a simple language like Python, with simple rules, one way to do a thing, and not the opposite.
Re:Why Learn to Program in C? by agumonkey on Monday February 01, 2016 @09:53PM (#11017393)
What I like the most in python is, until you peek too much below, the curated features that make it small yet expressive:

- tiny set of builtins: list, dict, set - literal - slices - small syntax, and canonical indentation - simple mapping between some operators and class methods

you have enough to abstract a bit but not too much without drowning in details.

Re:Why Learn to Program in C? by arc0re on Tuesday February 02, 2016 @05:19AM (#11018600)
Yeah and another good thing I like about Python, it doesn't force you to do object oriented. A beginner doesn't really need this. Its like if you begin with C, you'll have to deal with pointers early, and that means understanding things like memory, stack and heap allocations, safety, etc... Way too much for a new coder.
Re:Why Learn to Program in C? by jdbernard on Monday February 01, 2016 @12:55PM (#11013592)
This is a strawman. The author is not advocating this as a first language:

"Learning C is not necessary for everyone, but there are many posts on Reddit and programming forums with authors who feel like they’re missing something, and I wonder if this is part of what they’re looking for."

Re:Why Learn to Program in C? by nikdaheratik on Tuesday February 02, 2016 @12:43AM (#11017807)
Yeah, seems to be some confusion of the title. Probably a better title is "Why learn C programming?" The article itself isn't about "Learning to Program with C as a beginning language".

And I don't know how I feel about C as a first language. I don't believe it would be worse than Java, which was the intro course at my Uni, but my first language was BASIC of all things, which is good in some respects as it really is a "Beginners" language, but both C and BASIC could encourage sloppy practices without good instruction and C especially has some gotchas.

Re:Why Learn to Program in C? by tosseraccount on Monday February 01, 2016 @12:04PM (#11013087)
Overcoming goofy shit and gotchas is part of any programming system.
Re:Why Learn to Program in C? by mrestko on Monday February 01, 2016 @12:07PM (#11013100)
Yeah, but why start with an exceedingly painful one except to needlessly inflict pain and suffering on students. Better to lay the groundwork with a friendlier language, learn the basics, and then move on to the more complicated gottchas (at least in my amateur opinion).
Re:Why Learn to Program in C? by Apocryphon on Monday February 01, 2016 @12:40PM (#11013436)
JavaScript has been touted as an intro language, and in some ways it's even quirkier than C.
Re:Why Learn to Program in C? by livarot on Tuesday February 02, 2016 @03:41AM (#11018286)
Recommending JS as intro language is just plainly wrong.
Re:Why Learn to Program in C? by bxh on Monday February 01, 2016 @12:24PM (#11013286)
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.
Re:Why Learn to Program in C? by bigtunacan on Monday February 01, 2016 @12:57PM (#11013621)
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 early.

Re:Why Learn to Program in C? by tosseraccount on Monday February 01, 2016 @02:17PM (#11014495)
Ruby is written in C

Python is written in C

Lua is written in C

Re:Why Learn to Program in C? by bigtunacan on Monday February 01, 2016 @02:45PM (#11014785)
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? by tosseraccount on Monday February 01, 2016 @03:03PM (#11014945)
No. Just stick with C so that it's portable and fast.
Re:Why Learn to Program in C? by antod on Monday February 01, 2016 @05:49PM (#11016262)
I don't write Python in C /s

You meant Ruby, Python and Lua have their reference implementations written in C. They all also have other implementations written in other languages.

Re:Why Learn to Program in C? by tosseraccount on Monday February 01, 2016 @06:00PM (#11016335)
That's what I meant. Most important programs are written in C. Look at what program you are running now. See if you can find the standard C library it links to.
Re:Why Learn to Program in C? by pklausler on Monday February 01, 2016 @12:41PM (#11013444)
#include <stdio.h> int main(void) { (printf)("C is awesome\n"); return 0; }
Re:Why Learn to Program in C? by pklausler on Monday February 01, 2016 @12:44PM (#11013476)
#include <stdio.h>

int main(void) {

  (* * * * * * * * * * * * * * * * * * * * printf)("C is awesome\n");

  return 0;

}
Re:Why Learn to Program in C? by veddan on Monday February 01, 2016 @12:56PM (#11013600)
In C99:

    #include <stdio.h>

    int main(void) {
        (* * & * * * * * & * * * * * * * * * * * * * printf)(&1["C is awesome\n"]-3/2);
    }
Re:Why Learn to Program in C? by pklausler on Monday February 01, 2016 @01:01PM (#11013674)
I proudly display my "Best Abuse of the Rules" category win of the Int'l Obfuscated C Coding Contest on my resume.
Re:Why Learn to Program in C? by ArkyBeagle on Monday February 01, 2016 @01:08PM (#11013749)
The drop from Pascal to 'C' is pretty short.