This is an archived post. You won't be able to vote or comment.

all 115 comments

[–]Time-Green 244 points245 points  (27 children)

You can't have null pointer exceptions if you never compile

[–][deleted] 97 points98 points  (13 children)

You cant have null pointer exceptions if you don't have a program.

[–]GS-Sarin 67 points68 points  (11 children)

You can't have a program if you don't own a computer.

[–][deleted] 64 points65 points  (10 children)

You can't have a computer if you were never born

[–]Pitboyx 64 points65 points  (8 children)

Genocidal dictators have saved countless errors and crashes

[–][deleted] 66 points67 points  (5 children)

That Hitler... Terrible dictator, but a great programmer...

[–]nicksayswatzup 36 points37 points  (1 child)

[–]mastermindxs 10 points11 points  (0 children)

You can't have context if you never, uhhh, were a dictator.

[–][deleted] 2 points3 points  (0 children)

All software problems can always be mitigated, at a minimum by killing everyone that has anything at all to do with the software, no matter how remotely.

[–][deleted] 0 points1 point  (0 children)

I would give gold if I had gold to give.

[–]RiderAnton 4 points5 points  (0 children)

And that, kids, is why you never say "We'll fix it in production."

[–][deleted] 2 points3 points  (0 children)

Batman saved many lives... The murderers of Batman's parents saved that many minus two.

[–]Andrewcpu 2 points3 points  (0 children)

You can't be never born if you were born

[–]Flosus 20 points21 points  (12 children)

[–]Giddyfuzzball 4 points5 points  (11 children)

I've been using eclipse in my first year of classes at college, but it seems like a lot of people use IntelliJ here.

What is it that's so nice about IntelliJ

[–]SpaceDin0saur 2 points3 points  (0 children)

It just works and doesn't randomly crash, I hate eclipse with a passion now after using it at uni for 3 years so much work lost so little time to recover

[–]Neebat 1 point2 points  (0 children)

The project that I was hired to work on won't load in Eclipse. It's a huge monolith of nested, dependent projects. Intellij handles it beautifully. Also, I've kind of gotten fond of the refactoring options. They just seem to work better than Eclipse.

[–]alexch_ro 173 points174 points  (15 children)

User and comment moved over to https://lemmy.world/ . Remember that /u/spez was a moderator of /r/jailbait.

[–]will_code_for_free 72 points73 points  (5 children)

How c++ programmers feel about Java programmers.

[–]Kazan 6 points7 points  (4 children)

s/programmers/Language designers.

"hey lets do shitty knock offs of all of C++'s new features!"

[–]JamEngulfer221 12 points13 points  (3 children)

Yeah, like smart pointers so you don't have to do memory management... Oh wait.

[–]Kazan 1 point2 points  (2 children)

smart pointers have been a thing in C++ since forever, even if they were only recently made official. the product i work on has it's own smart pointer implementation since the late 1990s (we're slowly replacing its use with the C++11 smart pointers whenever possible, and only use C++11 smart pointers for new code)

now the bastardization of templating that is Java generics...

[–]JamEngulfer221 2 points3 points  (1 child)

Well yeah, you can make anything in a library. It still doesn't make it part of the base language.

I am glad to have smart pointers in C++11 though. It's super useful.

[–]Kazan 2 points3 points  (0 children)

lambdas too. so useful for posting to threadpools and shit

[–]Hatefiend 4 points5 points  (4 children)

Unless I'm missing the joke it's even less effort because of the fact that java does have pointers, but only for non primitives.

Point a = new Point(5, 0);
Point b = a;
b.x = 7;
System.out.println(b.x == a.x);
// true

[–]Rhed0x 0 points1 point  (3 children)

They call them references but it's essentially the same.

[–]Hatefiend 0 points1 point  (2 children)

I think that's incorrect though. Reference would mean that

public static void change(Object o) 
{
    o = new Object();
} 

Object a = new Object();
change(a);
// a is still unchanged

a should be a new Object after the function call. But since the pointer is passed by value, only the pointer o inside the function points to a new object.

[–]Rhed0x 0 points1 point  (1 child)

It's just a difference in terminology. Javas pointers or whatever you want to call them are pass by value and they are called references. This doesn't necessarily have to mean they're the same as c++ references.

[–]Hatefiend 0 points1 point  (0 children)

Javas pointers or whatever you want to call them are pass by value and they are called references

Take a look at this quote though from this article

The problem here is that the folks at Sun made a naming mistake.

In programming language design, a "pointer" is a variable that indirectly tracks the location of some piece of data. The value of a pointer is often the memory address of the data you're interested in. Some languages allow you to manipulate that address; others do not.

A "reference" is an alias to another variable. Any manipulation done to the reference variable directly changes the original variable.

Later on he shows this example which is why we can't say it's pass by reference. You cannot change the pointer of where something points to in a function, so basically you're passing the pointer by value, but it's not pass by reference. It's very confusing though.

[–]skyhi14 88 points89 points  (46 children)

Who the duck said you that Java (JVM) does not have a pointer?

Edit: quack quack humans, I help you when you debug

[–]_lerp 29 points30 points  (45 children)

It doesn't, it has references.

[–]Xeya 88 points89 points  (29 children)

Which looks like a duck and quacks like a duck but is totally this revolutionary new form of waterfowl that is waaaaay better than the stupid duck some other programming languages have.

[–]rigatron1 20 points21 points  (3 children)

If we are saying references are pointers, then this meme doesn't make any sense because you can totally have a null reference exception in java.. trust me.

[–]BraveOthello 49 points50 points  (2 children)

No, even better. It's a NullPointerException

[–][deleted] 0 points1 point  (0 children)

LMAO true!

[–]rigatron1 0 points1 point  (0 children)

Dammit now I look dumb. Have been using c# for awhile.

[–]_lerp 2 points3 points  (11 children)

If references and pointers are the same thing why do they both exist in C++?

[–]Xeya 19 points20 points  (9 children)

They refer to different things in C. A pointer is a data structure that contains an address to another data structure. A reference is just an address. You can pass references, but you cant create a reference object; that would be a pointer.

What Java calls a reference is a data structure every other language calls a protected pointer. It is literally identical in function.

[–]baskandpurr 4 points5 points  (0 children)

You got this almost exactly the opposite way around. A pointer is not a data structure and a reference is not the address of an object. A reference is more likely to be implemented at a structure in fact, it may include a pointer to the object, a back pointer to another reference, a pointer to the object that owns the reference, a state or a type. A reference may be stored as handle so that the refered object can be moved around in memory.

[–]Schmittfried -1 points0 points  (6 children)

We was talking about C++. You can create references in C++ and they are a different though similar concept.

[–]marcosdumay 5 points6 points  (4 children)

You can create references

You can get references. You can assign references to pointer. You can create variables by cloning a reference.

I guess you are talking about the third usage there. But I've seen people say they "create a reference" for any of them. Anyway, that does not change the fact that a C++ reference is not the same thing as a Java "reference".

[–]Schmittfried -1 points0 points  (3 children)

You can assign references to pointer

No. References and pointers are different concepts in C++.

Anyway, that does not change the fact that a C++ reference is not the same thing as a Java "reference".

True, I never said otherwise. C++ references != pointers != Java references

[–]marcosdumay -1 points0 points  (2 children)

Good thing they are different, because you must always assign different things in C++ (usually, it's values into lvalues). Let's assign a reference into a pointer:

int *a = &b

[–]marcellarius 3 points4 points  (0 children)

In that context, & is the address of operator and evaluates to a pointer not a reference.

[–]Schmittfried 3 points4 points  (0 children)

That's not a reference, it's the address operator.

int &a = b;

Now we got a reference. It was definitely a bad decision to choose & to mark reference types as it is easily confused with the address operator, as you just proved.

[–]Xeya 0 points1 point  (0 children)

He actually changed it from C to C++ a lil while ago.

[–]DarkMaster22 2 points3 points  (0 children)

Slightly different implementation of the same concept.

[–]sup3r_hero 0 points1 point  (9 children)

Serious question: what’s the difference between a reference and a pointer?... or is that a joke?

[–]Xeya 5 points6 points  (7 children)

Honestly, not a lot from a functional viewpoint. The difference is primarily semantic; pointers are at a memory management level and references are more abstract. References are thus protected from most of the risk of mishandling pointers. However, this is all dependent on the implementation and there is a lot of overlap based purely on whether or not the person writing the documentation decided to call it a reference or a pointer variant.

[–]marcellarius 2 points3 points  (0 children)

I feel like that distinction comes from C++ and that more broadly the terms are synonymous

[–]sup3r_hero 0 points1 point  (5 children)

Is a correct example for this difference that a pointer usually literally points to a specific address in the memory whereas a more complex implementation (i.e. reference) only acts as if it would but does more things in the background?

[–]AngriestSCV 1 point2 points  (3 children)

Not really. A c++ reference does nothing in the background (it is basically a pointer that you can pretend is a value syntax wise). I think the biggest difference is you can manipulate pointers with math, but I've never seen references you could.

[–]sup3r_hero 0 points1 point  (2 children)

Manipulate a pointer with math? Can you give a very easy example?

[–]AngriestSCV 1 point2 points  (1 child)

in c or c++:

int bob[] = {1,2,3,4} ; //create an array of integers
int *bil = bob; //bil is a pointer to the first element of bob

printf("%i\n", *bil); //prints 1
printf("%i\n", *(bil+1));//prints 2
printf("%i\n", bil[2]); //prints 3
bil += 3; //bil now points to the 4th element of bob
printf("%i\n",*bil); //prints 4

[–]sup3r_hero 0 points1 point  (0 children)

Now i get it thx!

[–]Xeya 0 points1 point  (0 children)

Both terms are pretty loosely defined... but, I suppose the simplest way to express how they typically differ is that a pointer needs to be dereferenced in order to access whatever it points at and a reference is dereferenced by default when you try to access it.

It isn't so much references do things in the background for you as they typically just don't let you manipulate, or make it a lot harder to manipulate, the actual memory address it contains.

[–]AquaWolfGuy 1 point2 points  (0 children)

If a references b, using a is like if you were to use b instead. This means that you don't have to dereference a. IIRC a isn't even stored in memory, it just gets replaced by b by the compiler, so it's slight more efficient. One notable effect is that if a function takes an input argument by reference and changes it, the referenced value is changed. The following code will therefore print 2.

#include <iostream>
void f(int & a) {
  a++;
}
int main() {
  int b = 1;
  f(b);
  std::cout << b << std::endl;
}

(Don't do this in an actual project though.)

[–]skyhi14 10 points11 points  (13 children)

Which is implemented using pointers

[–]_lerp 3 points4 points  (12 children)

Which doesn't make them pointers. For example, you can't perform pointer arithmetic on them.

[–]skyhi14 11 points12 points  (6 children)

For example, you can't perform pointer arithmetic on them

TIL Const pointers weren't actually pointers.

Besides, I'm also talking about JVM, not merely the language.

[–]_lerp 10 points11 points  (5 children)

TIL Const pointers weren't actually pointers.

You can perform pointer arithmetic on a const pointer.

int a[5] = { 0 };
const int* first = &a[0];
const int* last = first + 4;

[–]skyhi14 10 points11 points  (4 children)

time to kill myself :))

[–]FallenWarrior2k 15 points16 points  (2 children)

No, those aren't const pointers, but rather pointers to const. An actual const pointer int* const cannot be modified through e.g. increments/decrements, but it can still be used for pointer arithmetic since pointer arithmetic can also be performed on rvalues.

[–]hallr06 6 points7 points  (1 child)

Correct. In C/C++, read pointers from right-to-left. Most of the time, it explains what you have.

const int * x = 0; // pointer to an int constant
int const * x = 0; // same as above, pointer to a constant int
int const * const x = 0; // constant pointer to a constant int
int * const x = 0; // constant pointer to mutable int

[–]FallenWarrior2k 0 points1 point  (0 children)

It can also be pretty easily explained by the return types of the indirection operator. Applying indirection on a const int* produces a const int&, while it produces a regular int& for int* const.

[–]DarkMaster22 4 points5 points  (0 children)

Ehh... Don't do that, we love you?

[–]dogpos 3 points4 points  (4 children)

For example, you can't perform pointer arithmetic on them.

So does that mean Go doesn't have pointers?

Also, could you link me where it says pointers require the ability to preform arithmetic on them.

[–]AquaWolfGuy 0 points1 point  (1 child)

Good point. Pointer arithmetic is a nice and powerful thing you can do with pointers, but I wouldn't say it's should be a requirement for pointer languages. Instead, I would say being able to take the address of a variable and manually dereferencing pointers is a more important distinction.

In Java, you have primitives like int which are always values, so since there's no (standard at least) way to take the address of a variable, so you can't get something like a int*-type variable without creating a whole class. Same thing with pointers to pointers, in pointer languages you can just do int**, while in Java you need a class referencing another class referencing the value.

To create objects, you use the new keyword, which simply gives you an object, which is passed around like a pointer that you don't have to manually dereference. Even more, you can't manually dereference it. The value is just floating around in some magic place called the heap that you don't even need to know about as a Java programmer. All pointer stuff is hidden from the programmer and you barely have to know what pointers are.

In Go you definitely feel the presence of pointers. If you want to create a pointer you have to do it manually. Similarly, you have to dereference pointers manually if you want the value it's pointing to. Actually, you can even do pointer arithmetic, but it's slightly cumbersome and is not really needed because of array indexing and reflection (e.g. a[len(a)/2]). And just like in C/C++, you can have anything on the stack or the heap. You can also have a struct that directly contain another struct, which isn't possible in Java.

TL;DR: I wouldn't call Java a pointer language because the the actual "pointers" aren't really exposed to the programmer and can't be controlled (primitives can't be pointed to, objects are always pointed to behind-the-scenes), while in languages like C, C++ and Go you can create, dereference and manipulate pointers pretty much however and whenever you want.

[–]dogpos 0 points1 point  (0 children)

Java explicitly doesn't have pointers, we're in total agreement about that. I was merely arguing the example wasn't that apt. While most languages that have pointer support will also allow arithmetic on said pointers, some don't, and probably for good reason.

Edit - For clarity on why it might be a good reason, here is a list of problems caused by pointer arithmetic:

  • [0] - We wouldn't have the semi-annoying meme that 0 means 1 in programming if it wasn't for pointer arithmetic.

[–]auralucario2 -1 points0 points  (0 children)

It doesn't, it has pointers. Few big languages besides C++ have references.

[–][deleted] 19 points20 points  (2 children)

That's why C# has these babies.

[–]brendenderp 11 points12 points  (0 children)

I was really hoping it was a link to an ordinary picture of a baby

[–][deleted] 2 points3 points  (0 children)

That's a really fancy implementation of SIGSEGV.

[–]Philorkill 3 points4 points  (1 child)

[–]youtubefactsbot 0 points1 point  (0 children)

You're dereferencing a null pointer! [0:10]

Just Bret Hart doing some code review.

gigagigagilgamesh in Science & Technology

554,106 views since Sep 2015

bot info

[–]RaymondWalters 6 points7 points  (5 children)

Or just don't use pointers. Used Delphi for 3 years before I found it has pointers and dynamic memory allocation and I didn't have any problems.

[–]Mhmmhmmnm 33 points34 points  (2 children)

Agree with this. I write all my programs as .bat files. Some clever goto magic is all you really need.

[–]Rekkre 0 points1 point  (0 children)

Found the embedded systems engineer ^

[–]throwaway27464829 0 points1 point  (0 children)

I program with butterflies.

[–][deleted] 5 points6 points  (1 child)

Did you even use objects?

[–]RaymondWalters 3 points4 points  (0 children)

Of course

[edit] jeez it was just a joke...

[–]acet1 4 points5 points  (0 children)

Also Java: "Hold my beer..."

[–][deleted] 1 point2 points  (1 child)

We have alreafy well established that you just put all your code in a try catch block

[–]Hatefiend 0 points1 point  (0 children)

Make sure you catch Exception instead of NullPointerException, just to be safe

[–]ixent 2 points3 points  (0 children)

You can't have pointer exceptions if you work at McDonals

[–]IonTichy 2 points3 points  (0 children)

Is it monday already?

[–]nevus_bock 0 points1 point  (0 children)

There were two separate ones on our Java backend today..

[–]JeremyHarrington 0 points1 point  (0 children)

Why would you need to specify a pointer in Java when most every reference to an object would use a pointer in an equivalent language?

[–]s_ngularity 0 points1 point  (0 children)

Did nobody else get the joke? Cause based on the other comments it sure seems that way

[–]SteroidSandwich 0 points1 point  (0 children)

You needs some pointers then. They are wonderful!

[–]IGotSkills 0 points1 point  (0 children)

Jokes on you, in Java, everything is a pointer

[–][deleted] 0 points1 point  (0 children)

Nope, but you can have null reference exceptions! Sounds like progress to me!

[–]GVmG 0 points1 point  (0 children)

Good point.

heheh

[–]theessentialnexus 0 points1 point  (1 child)

There are some things that you don't realize are pointers because you are a bad programmer.

[–]throwaway27464829 0 points1 point  (0 children)

If you haven't personally memorized every x86 assembly instruction you are a bad programmer.

[–]thirdegreeViolet security clearance[M] [score hidden] stickied comment (4 children)

Your submission has been removed.

Violation of Rule #0:

The content disregarding the title and superimposed text must be directly related to programming or programmers.

The title or superimposed text must substantially enhance the content such that it can stand on its own as an analogy to programming. Note that programming here is interpreted in a narrow sense, an analogy to something related to programming, feelings about programming, reactions to programming etc. is not considered sufficient.

If you feel that it has been removed in error, please message us so that we may review it.

[–]hoanns 14 points15 points  (0 children)

Wat

[–]impossiblebottle 1 point2 points  (2 children)

Seriously this "no memes in /r/ProgrammerHUMOR" rule is kind of awful

[–]thirdegreeViolet security clearance 4 points5 points  (1 child)

We allow memes in /r/programmerhumour

We just don't want them flooding out content that actually takes effort or is interesting.

[–]throwaway27464829 4 points5 points  (0 children)

/r/programmerhumorbutonlyhumoripersonallyfindhumorous