News for hackers. Stuff that matters.
Re:Why should I use a pointer rather than the object itself? by stormbrew on Friday March 07, 2014 @05:29PM (#7363169)
> note: in java, everything(except basic types) is a pointer. so you rather should ask the opposite: why do I need simple objects?

I think this is by far the most important piece of advice in that thread. It gets right to the heart of one of the most basic areas of confusion that programmers coming from garbage collected environments to ones with manual memory management have.

They need to understand that they have NOT been working in an environment without pointers, as they are often told to believe, but one in which nearly everything is a pointer. Understanding this is fundamental to understanding these differences and a 10,000 word essay about C++ allocation policies will not make it any clearer without dealing with that first.

Re:Why should I use a pointer rather than the object itself? by malisper on Friday March 07, 2014 @07:22PM (#7363643)
But the fact that they are programming in an environment where everything is a pointer is hidden to the them. In C++ one needs to explicitly use pointers whereas in Java all of the pointers are handled behind the scenes.
Re:Why should I use a pointer rather than the object itself? by abengoam on Friday March 07, 2014 @08:30PM (#7363846)
Not really. In Java it's a leaky abstraction - it's true that the JVM does a lot of micromanagement for you, but if you are careless you start getting exceptions (best case scenario) or start to get mysterious changes in your data (worst case scenario).

I agree with grandparent that understanding what a pointer is and that almost everything in a Java program is a pointer it's critical for a Java programmer.

Re:Why should I use a pointer rather than the object itself? by stusmall on Friday March 07, 2014 @09:34PM (#7364008)
I think that might be a bit too broad of a take away. I hate to be a pedant but C# allows user defined value types and I'm sure there are other GC'd languages that aren't as reference type heavy as Java. I think it would be a more fair statement if you replaced "garbage collected environments" with Java. I say "more fair" because I don't think I know any serious Java devs who don't understand the difference between reference and value types. I could just be lucky with who have crossed my path though.

EDIT: After thinking about it a little, most of the Java people I know have at least some embedded or native background. This could be a reason. I don't know what the market over all is like.

Re:Why should I use a pointer rather than the object itself? by stormbrew on Friday March 07, 2014 @09:58PM (#7364071)
Consider the other direction from Java, into the fully dynamic languages. Many of those give you even less ability to control heap vs. stack allocations than Java does and often present an everything-is-a-reference facade even on things that are often optimized to stack objects (Fixnum in Ruby for eg).

But yes, a java programmer with embedded or native background would have a better understanding of this than people who learned Java first, which is what I'm really addressing here. And in the OP on SE you can clearly see that this is a big part of that person's confusion.

Re:Why should I use a pointer rather than the object itself? by byroot on Friday March 07, 2014 @10:35PM (#7364132)
> optimized to stack objects (Fixnum in Ruby for eg)

I can't find any information on that, do you have a link on that subject?

Re:Why should I use a pointer rather than the object itself? by stormbrew on Saturday March 08, 2014 @05:14PM (#7366589)
Which part, that they're optimized to stack objects or that they appear as if they're referenced objects?
Re:Why should I use a pointer rather than the object itself? by banachtarski on Friday March 07, 2014 @07:41PM (#7363700)
I'm amazed at how many new programmers enter the workforce without a basic understanding of the stack and the heap.
Re:Why should I use a pointer rather than the object itself? by greatdox on Saturday March 08, 2014 @02:24PM (#7366047)
Most of them are recent high school and college dropouts. What did you expect them to know?

They learned programming by reading blogs and pirated PDF files on BitTorrent. Of course they don't got a level of understanding most hackers here have.

You want a good programmer you need 15+ years of experience plus a good understanding of computer science, recent high school and college dropouts don't have that.

You hire a cheaper labor source, you won't get that level of quality a more expensive labor source will give you and you get what you pay for!

Re:Why should I use a pointer rather than the object itself? by banachtarski on Saturday March 08, 2014 @04:09PM (#7366404)
Well, to be fair, I don't have 15 years of experience (professional experience anyways). But I do believe the fundamentals are important and they seem to be glossed over.
Re:Why should I use a pointer rather than the object itself? by IsTom on Saturday March 08, 2014 @05:14AM (#7364795)
I've met an 'architect' who didn't know either. Apparently Java world is governed by a different set of rules.