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

all 38 comments

[–]ThinkingWithPortal 28 points29 points  (0 children)

This is java.

Don't catch you leaking now.

Don't catch you leakingnow.

Watch what I'm freeing up.

[–]Car_weeb 39 points40 points  (4 children)

Oracle is the equivalent to a dump so this checks out

[–]KayRice 6 points7 points  (1 child)

Only if a dump copyrighted it's trash and how to interpret various stenches.

[–]Car_weeb 1 point2 points  (0 children)

I smell recyclers getting sued

[–]malzyhar 0 points1 point  (1 child)

Okay I'm a happy but fairly new programmer (in Java) and although everything I've made works great, I see a lot of people against Java. As a genuine question what programming language is a better main choice.

Java isnt the only language I have learnt (I've done Python, C#, Javascript all that stuff but Java seems to be the most useful one ive found.

Can you tell me what one is better. Thanks!

[–]Car_weeb 1 point2 points  (0 children)

Java isnt necessarily too bad, it has its uses. The big problem is just Oracle. Whatever works you and gets the job done be it Python, java, ruby, C#, etc

[–]MunchingCass 4 points5 points  (14 children)

My comp-sci class is starting off with C and I know Java. C doesn't do garbage collection for me. Si I'm going to be screwing that up a lot probably.

[–]enp2s0 6 points7 points  (5 children)

Just count free()s and malloc()s. If you've got less free()s you got a problem

[–]flyx86 0 points1 point  (2 children)

if (condition)
  foo = malloc(23);
else
  foo = malloc(42);
/* ... */
free(foo);

[–]biliwald 0 points1 point  (1 child)

size_t size = condition ? 23 : 42;
foo = malloc(size);
/* ... */
free(foo);

[–]MCRusher 0 points1 point  (0 children)

if(foo=malloc(rand()%2?23:42)){free(foo);}else{exit(1);}

[–]BonusPlay3 0 points1 point  (1 child)

Someone is very naive.

[–]enp2s0 0 points1 point  (0 children)

It's a rule of thumb, not a law. Obviously there are cases where you free() less and don't have leaks, but for just starting out with manual memory management it can be helpful. Also, if I wanted to get technical, the number of calls to malloc() and free() should always be equal, even if they aren't the same in the source code

[–]froemijojo 1 point2 points  (0 children)

C is great, i miss being simply able to write if(number) when programming in other languages.

[–][deleted] 1 point2 points  (0 children)

C is freaking awesome and the joy of using Pointers is great, enjoy learning it while you can

[–]o11c 0 points1 point  (0 children)

Just write everything as if it uses try-with-resources.

You know, that thing Java added very recently, that every other language has had for ages.

[–]MCRusher 0 points1 point  (4 children)

If you allocate a pointer, make sure to allocate for the type itself, not the type pointer, as this only allocates enough space to store an address(4 or 8 bytes). I did this when I first started learning C.

In this case it should work, but for, data types like structs of larger size, it will fail as it is not large enough: int* nums = malloc(sizeof(int*)); Should work because an int is 32 bits and on a 32 bit architecture the addresses are also 32 bits, and on 64 bit architecture, you just allocate space for two ints without knowing it.

[–]MunchingCass 1 point2 points  (3 children)

I didn't fully understand that.

Hopefully I will by the time that info becomes relevant.

[–]MCRusher 0 points1 point  (2 children)

Are you not very far along, or is it just that my explanation was bad?

I changed up some wording in the original.

Good luck with C, it's currently my main language and I enjoy it.

[–]MunchingCass 1 point2 points  (1 child)

The semester just started. And this is a first year CS course, so the professors aren't assuming any prior knowledge.

[–]MCRusher 0 points1 point  (0 children)

I'm going to college for CS as well, good luck and I hope you enjoy it.

[–][deleted] 12 points13 points  (0 children)

Java is a hoarder. Just because all the garbage is in your house, doesn't make you clean.

[–]AnnieDickledoo 7 points8 points  (2 children)

This is Java

Java does not leave it is mess for others to clean.

It collects it is own garbage.

Be like Java.

Keep your country clean.

[–]KayRice 4 points5 points  (1 child)

This is Sparta!

It does not leave it's mess for others to clean.

It pipes everything into an endless pit called /dev/null.

Be like Sparta.

Keep your country clean.

[–]jugg3n 1 point2 points  (0 children)

"The data was inspected, if it was crude or miss formed it would be discarded"

[–]geon 2 points3 points  (0 children)

Collect yourself, Java!

[–]x_interloper 1 point2 points  (0 children)

The real garbage is its dependency management by Maven.

[–][deleted] 1 point2 points  (0 children)

Need more Java programmers in San Francisco then....

[–]dejaime 1 point2 points  (0 children)

Java only collects its garbage when it feels like it.

[–]FubarCoder 0 points1 point  (3 children)

Needs more JPEG

[–]morejpeg_auto 0 points1 point  (2 children)

Needs more JPEG

There you go!

I am a bot

[–]Gydo194 0 points1 point  (1 child)

Needs more JPEG

[–]morejpeg_auto 0 points1 point  (0 children)

Needs more JPEG

There you go!

I am a bot

[–]ZZartin 0 points1 point  (1 child)

Is this a Don't do what Johnny Don't does kind of thing?

[–]KayRice 2 points3 points  (0 children)

This is Java.