News for hackers. Stuff that matters.
Re:C/C++ Pointer Declaration Syntax – It makes sense by eru on Tuesday February 21, 2012 @06:29AM (#3616127)
If you had started with something more sane, like Forth or I guess even flawed Pascal, you would have understood pointers much earlier. C is such a horrible language to learn first, second or even third.
Re:C/C++ Pointer Declaration Syntax – It makes sense by dbattaglia on Tuesday February 21, 2012 @07:26AM (#3616231)
What about learning C first compared to languages that don't have the concept of real pointers (like, say, Java)? I started out with C++ (and still write C/C++ from time to time), and I feel like it's given me a better understanding of memory management and reference types that a lot of programmers I meet and work with don't seem to really grasp.

In C# code I constantly see the "anti-pattern" of new-ing up a variable at declaration, only to immediately overwrite it on the next line with the results of some function. I can't help but think that the person writing it has no concept of what "new" is actually doing (with regards to the heap and the GC, for example).

Re:C/C++ Pointer Declaration Syntax – It makes sense by eru on Tuesday February 21, 2012 @09:54AM (#3616620)
> What about learning C first compared to languages that don't have the concept of real pointers (like, say, Java)?

If you want to learn pointers, you have to learn a language that provides them. So C, or like I said, Forth or Pascal. C is fine as a first language, if you don't mind the pain. C++ is a horrible language, no matter when you learn it. Never cripple the minds of beginners with it.

About your C# anecdote, does the language allow something like the following?:

    type variables = someFunction ();
Nowadays I usually program in Haskell for my day job. There lots and lots of nice concepts to be understood there. You could even use pointers, if you are desperate enough.
Re:C/C++ Pointer Declaration Syntax – It makes sense by dbattaglia on Tuesday February 21, 2012 @10:50PM (#3619352)

  does the language allow something like the following?:
yes, exactly. The problem is you see stuff like this:

  var obj = new SomeType();
  obj = GetSomeType();
Basically creating 2 objects, the first of which is immediately garbage since it no longer has any roots. Anyone who understands pointers/references and memory allocation should understand that "new" is actually creating a new live object on the heap, rather than just initializing a pointer to null (or a stack-based value type to zero).

These days C# is actually a decent language to code in, it has a nice functional aspect to it with linq/lambdas, and you can still go down to C style pointers/"unsafe" code if necessary (with lots of restrictions of course). It's really the Microsoft dependency that kills it more than anything else.

Re:C/C++ Pointer Declaration Syntax – It makes sense by eru on Thursday February 23, 2012 @06:51AM (#3624589)

   var obj = new SomeType();
   obj = GetSomeType();
You could almost be tempted to write an automatic converter to

   var obj = GetSomeType();
but you can't in general, because you don't know whether `new SomeType()' doesn't have side-effects. But if it has some that are relied on, that's probably a bug.

I know that there's a free .net runtime called Mono. What about the compiler side of free C#?

Re:C/C++ Pointer Declaration Syntax – It makes sense by badboy on Tuesday February 21, 2012 @07:29AM (#3616238)
I started with C as my first language and even though pointers made some code really hard to read and sometimes my own experiments with pointers crashed horribly, it helped me understanding programming in a whole, how the memory is used and changed, ... I no longer write anything real in C now, but I feel quite confident when reading other's people C code.
Re:C/C++ Pointer Declaration Syntax – It makes sense by eru on Tuesday February 21, 2012 @09:52AM (#3616610)
I learned C pretty early on. But I wouldn't want to inflict that on other people.
Re:C/C++ Pointer Declaration Syntax – It makes sense by kstenerud on Tuesday February 21, 2012 @11:23AM (#3616996)
My first language (after BASIC) was assembler, after which I moved to C, so pointers in C weren't a problem. The re-use of symbols and keywords for different things was a pain, however, and got even worse in C++.