News for hackers. Stuff that matters.
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#?