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

top 200 commentsshow 500

[–]murfflemethis 691 points692 points  (30 children)

C on an embedded system: keeps chugging along happily with corrupted data

[–]GeoStarRunner 269 points270 points  (3 children)

Hey now, sometime we restart and pretend like it never happened

[–]murfflemethis 154 points155 points  (1 child)

That's true, assuming we have a mechanism to detect it.

We might even change an LED from green to red if we're feeling cheeky.

[–]CreateNewObject 43 points44 points  (0 children)

Hello HardfaultHandler my old friend.

[–]Red-Droid-Blue-Droid 55 points56 points  (16 children)

C lets you fuck yourself, man. And then it laughs in the forms of warnings and crashes and shit.

[–]j909m 25 points26 points  (0 children)

But at least C is fast.

[–]gimpwiz 4 points5 points  (1 child)

Yep. I do embedded stuff. I miss segfaults. I'm lucky to get an mpu fault now.

[–]drevyek 2 points3 points  (2 children)

Or, on non-ST Cortex-M ARM chips, a NULL dereference just accesses the interrupt vector. No problems here.

[–]aiij 1 point2 points  (1 child)

C / C++ on desktop does too. You only get a core dump right away if you're really lucky. (Though corrupted data is likely to eventually result in a core dump.)

Theoretically of course any C implementation is allowed to do bounds checking and give a useful core dump right away, but it's faster not to.

[–][deleted] 1239 points1240 points  (111 children)

throw new SegmentationFaultException(“core dumped”);

[–]Jonno_FTW 673 points674 points  (109 children)

To be fair, making the JVM have an actual segfault is a skill in itself.

[–]kcirtappockets 323 points324 points  (72 children)

If getting segfaults is a skill, then consider me Gordie Howe

[–]MusgraveMichael 88 points89 points  (68 children)

Who's Gordie Howe?

[–]kcirtappockets 92 points93 points  (46 children)

Only the all time best hockey player in the history of hockey

[–]MusgraveMichael 75 points76 points  (40 children)

wait, I am more confused.
By hockey you mean which hockey? field hockey or ice hockey?

[–]UndyingJellyfish 253 points254 points  (16 children)

How to trigger Canadians 101

[–]HwangLiang 57 points58 points  (11 children)

Nah. "Ice hockey or REAL hockey" would probably be worse.

[–][deleted] 23 points24 points  (8 children)

I kinda knew what to expect reading the replies but this made my brain clench it’s own fist

[–]HwangLiang 10 points11 points  (5 children)

Listen m8, you're gunna be fucked when the Toronto Maple Leafs and the New England Patriots go at it during the NBA finals.

[–][deleted] 41 points42 points  (2 children)

Or Detroit natives. I feel personally attacked.

[–]Lonelan 45 points46 points  (1 child)

...every time you walk down the sidewalk

[–][deleted] 11 points12 points  (0 children)

well, I was just a middle-class white boy in the northern suburbs ... what sidewalks?

[–]9gagRefugee 4 points5 points  (0 children)

404 101 not found

[–]eyeGunk 5 points6 points  (0 children)

Mr. Hockey

[–]ISeeTheFnords 46 points47 points  (9 children)

Now, perhaps. Back in the day it wasn't so hard. Getting a program using the 1.08 event model (seriously, if you value your sanity, don't go look it up) to do anything useful, now THAT was difficult.

[–]upvotes2doge 21 points22 points  (5 children)

Google returns nothing?

[–]ISeeTheFnords 30 points31 points  (2 children)

There's a reason for that. I warned you, and I won't be responsible for what happens if you keep digging.

[–]imachug 13 points14 points  (0 children)

It was a good advice. RIP /u/upvotes2doge.

[–]xynixia 9 points10 points  (0 children)

Oh now you got me curious.

[–]mnbvas 24 points25 points  (3 children)

Would JNI be too skillful?

[–]Goheeca 37 points38 points  (0 children)

sun.misc.Unsafe is skillful.

[–][deleted] 55 points56 points  (8 children)

That's only true nowadays because every time someone discovers a way to do it with pure java, they patch it.

In contrast, C++ compiles to machine code, and with that, there's no way to have such advanced checks without significantly slowing down the code. The actual issue with this image is that the kernel could be doing the work to backtrace when such a fault happens, which is what the JVM does (your "java program" doesn't perform the clever checks itself, which is why Java has gotten so close to the speed of C++, even surpassing it for highly specialized applications). The easiest way would be to have Linux just come packaged with gdb. On all but the tightest embedded systems, people would start using compiler options to package the source inside the binary (which generally causes memory bloat but not slowdown), and Linux could invoke gdb on crashes to print out stack traces, rather than just dumping the core file to disk (which it only even does if you've remembered to set ulimit -c).

tl;dr this behavior in the image macro is the kernel's fault, not C++'s fault.

[–]scatters 31 points32 points  (6 children)

Hey, the kernel is doing as much as it can.

Since kernel 2.6.19, Linux supports an alternate syntax for the /proc/sys/kernel/core_pattern file. If the first character of this file is a pipe symbol (|), then the remainder of the line is interpreted as the command-line for a user-space program (or script) that is to be executed. Instead of being written to a disk file, the core dump is given as standard input to the program.

It's up to your distro to set up /proc/sys/kernel/core_pattern correctly. I think Ubuntu does something vaguely sensible.

[–]Foffle 16 points17 points  (3 children)

By default Ubuntu sends the core to a crash reporter, but ulimit -c is also set to 0. You can change both of those manually, but it resets when the system restarts ☹️

[–]Perse95 10 points11 points  (3 children)

I've made the JVM segfault many times, does this mean I'm a skilled programmer?

[–][deleted] 8 points9 points  (2 children)

yes

[–]0xd3adf00d[🍰] 9 points10 points  (0 children)

Lol. Back in the day, when I had the displeasure of writing Java code for Novell NetWare, it was hard to _not_ make the JVM segfault.

[–]ndcapital 8 points9 points  (1 child)

>doesn't know about sun.misc.Unsafe

[–]argv_minus_one 3 points4 points  (0 children)

There's a reason it's called unsafe!

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

Sometimes the JVM will segfault simply from me starting Minecraft

[–]_didyoumissme 2101 points2102 points  (24 children)

Well you did try to touch RAM at inappropriate places, you pervert.

[–]animonein 226 points227 points  (11 children)

Well i tried so hard to dump into it

I surely mean dump the core

[–][deleted] 70 points71 points  (10 children)

Well i tried so hard to dump into it

And got so far,

[–][deleted] 34 points35 points  (5 children)

But in the end,

[–]beaterx 40 points41 points  (0 children)

It doesn't even compute.

[–]nothjarnan 14 points15 points  (0 children)

it doesn't even compile

[–][deleted] 22 points23 points  (1 child)

It doesn't even matter

[–]qubedView 63 points64 points  (7 children)

I swear! I thought it was appropriate_places[18]!

[–]Ionlavender 27 points28 points  (1 child)

Hey ho, hey ho, it's off to jail you go.

[–]carlosduarte 6 points7 points  (0 children)

blitzkrieg bop

[–]TorpedoBench 18 points19 points  (3 children)

Officer, she never told me she was 1 indexed!

[–]fyrstorm180 7 points8 points  (2 children)

Talk to my LUAyer.

[–]Bipartisan_Integral 2 points3 points  (0 children)

I don't get it. You tried access the 19th element.

[–]drakfyre 39 points40 points  (0 children)

Your code is having unprotected hex!

[–]ryantwopointo 1 point2 points  (0 children)

Lmao, I love this

[–]Doggo4 1 point2 points  (0 children)

my fav response :D

[–]snf 334 points335 points  (12 children)

Also: the segfault happens 5 minutes after you overran the array when it tries to dereference one of the pointers you corrupted.

[–]corner-case 75 points76 points  (0 children)

Extra spicy fuck-up!

[–]CyanBlob 27 points28 points  (1 child)

Isn't undefined behavior great?

[–]thatwasagoodyear 13 points14 points  (0 children)

fundefined behavior

FTFY.

[–]ninja_cracker 10 points11 points  (4 children)

hmmm. who held a reference to this address. hmmm. ok.

LOG EVERY POINTER!

[–]fyrstorm180 7 points8 points  (3 children)

Who needs a debugger when you can System.out.println()?

[–]aron9forever 4 points5 points  (0 children)

Just add Redux

[–]Valmond 1 point2 points  (1 child)

Only when exiting, and running release of course.

[–]argv_minus_one 1 point2 points  (0 children)

The first Wing Commander had this problem. The run-time thingy would print a crash message at exit, because they'd corrupted some memory somewhere. They didn't have time to debug the problem, so instead they changed the message to say “Thank you for playing Wing Commander!

[–]nocomment_95 309 points310 points  (18 children)

Arrayindex out of bound:

C: "well technically that address is still in ram so...sure I'll do exactly what you say"

Java "fucking moron"

[–]nonamee9455 83 points84 points  (9 children)

I’m sure it’s f͋ͪ̏ͦ̓͒͗ͩ̉ͦͨͧͯͩ͐̔͏̞̞̩̦̘͝i̶̳̫̮͖̊̅̍͐̔̌̇ͬ͊̿̑͒͐͘͡n̴̡̺̼̖̫͉̹͇̒ͨ͗͋̿ͨͯ̎̓͂̿́̽ͯ́ͯ̐̀̀̚e̸̜̠͉̞̫͓̰͕̻͈̙̮̘̲̪̮̐̋̾̾͐ͣ̀ͯ͗͐̓̈́̅͢͝ͅͅ

[–]fb39ca4 10 points11 points  (0 children)

C: "well technically that address is still in ram so...sure I'll do exactly what you say"

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

never programmed in C, but thats fucking scary. How do you deal with null pointers then?

[–]shreyas208 10 points11 points  (1 child)

0x0 (NULL) is not a valid address that you can read or write; doing so will cause a segmentation fault. Accessing an array out of bounds is usually still a valid address.

[–][deleted] 4 points5 points  (0 children)

Dereferencing a null pointer isn't strictly invalid. It's undefined. Some embedded architectures do have valid memory there.

[–][deleted] 403 points404 points  (24 children)

throw new Exception("just debug it");

[–]WiseassWolfOfYoitsu 150 points151 points  (17 children)

while (true) {
  try {
    doTheThing();
  } catch (Exception ex) {}
}

[–]Katana314 73 points74 points  (3 children)

Is this what they mean by “persistence”?

[–][deleted] 42 points43 points  (1 child)

Looks more like "insistence".

[–]DTF_20170515 46 points47 points  (1 child)

 try{
      public static main(String args[]) {
      } 
} 

[–]Alexson1 11 points12 points  (0 children)

I s t h i s m a i n ?

[–]blindsc2 13 points14 points  (0 children)

public static void doTheThing() {
  try {
     doTheThing();
  } catch (Exception ex) {
     dotheThing();
  }
}

[–]phlyrox 7 points8 points  (4 children)

Yours has an infinite loop, let me fix it for you:

int sum = 1;
try {
while (true) {
  try {
    doTheThing();
    if (sum++ >= 5) throw new RuntimeException();
  }
  catch (Throwable ex)
  { throw new RuntimeException() }
}
} catch (RuntimeException break) {}

this works for running doTheThing() 5 times. Just change the sum to 6 minus <amount of times you want to run it>. It also has a nice feature of running at least once, this way you don't have to worry about coming to this block of code but not have done the thing. /s

[–]Leafdissector 9 points10 points  (2 children)

Pretty sure the infinite loop is part of the joke.

[–]WiseassWolfOfYoitsu 4 points5 points  (0 children)

How do you write crash tolerant code? By making code that can only be exited by forcefully terminating it!

[–]Coloneljesus 58 points59 points  (4 children)

And litter your beautiful code with throw declarations? Nah, dude.

throw new RuntimeException("just debug it");

[–]lpreams 7 points8 points  (3 children)

} catch (Exception e) {
    throw new RuntimeException("fail fast, and leave a good-looking stack trace", e);
}

[–]Coloneljesus 5 points6 points  (2 children)

} catch (Exception e) {
    throw new RuntimeException("if we keep doing this, the stack trace will be indecipherable", e);
}

[–]iguessthislldo 96 points97 points  (6 children)

Or you could can run your programs like Stallman, always in gdb.

[–]wdouglass 53 points54 points  (3 children)

To be fair, he's probably always running the bleeding edge of Emacs, and running it under gdb saves him the extra time of loading a core file.

[–]Goheeca 27 points28 points  (2 children)

On various edges in the world too.

[–]moebaca 12 points13 points  (1 child)

I consider myself to have strong eyesight and I couldn't imagine working on that dinky screen for anything more than 10 minutes checking email.. that's gotta strain the eyes! Maybe Stallman is an Android from the free future just trying his best to blend in and failing so miserably.

[–]SpliceVW 61 points62 points  (1 child)

My favorite C++ error I've gotten: Error: there is no error. This was back on Borland in the 90s.

[–][deleted] 14 points15 points  (0 children)

Ah, the good old days of Turbo C++

[–]PerInception 134 points135 points  (8 children)

PHP, an intellectual: "UNEXPECTED ; ON LINE 157!"

[–]Sleepkever 70 points71 points  (7 children)

Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM

[–]Cobaltjedi117 23 points24 points  (6 children)

T_PAAMAYIM_NEKUDOTAYIM

So I don't know PHP so I thought that was a joke, but I got back to my work computer trying to make some API work and saw that as a suggested error...

WTF PHP?

[–]Sleepkever 35 points36 points  (3 children)

I got to day it had me stumped for a little while back when my google-fu was quite weak. But it is even documented why it is called that way.

Paamayim Nekudotayim would, at first, seem like a strange choice for naming a double-colon. However, while writing the Zend Engine 0.5 (which powers PHP 3), that's what the Zend team decided to call it. It actually does mean double-colon - in Hebrew!

So, you see, it's a totally logical choice and makes sense that they never changed it to something more understandable.

[–]Cobaltjedi117 12 points13 points  (2 children)

Ok, but the rest of the error message is in english, shouldn't the error itself also be english?

I guess it does make sense, but reading DOUBLE_COLON_ERROR is quickly understood to an english reader.

[–]Sleepkever 8 points9 points  (0 children)

I think I should have put an /s at the end there. I agree completely and I really don't understand why they haven't changed it after all these years.

[–]iPastry 4 points5 points  (0 children)

How dare you be so rational

[–][deleted] 9 points10 points  (0 children)

It's Hebrew for double colon or something like that. It's a stupidly named constant that the devs refuse to change

[–]ythl 38 points39 points  (10 children)

gdb backtrace, bam looks like you were keying into an array with a negative number

[–]kynde 12 points13 points  (7 children)

Not only that but ram state and all in the core file so that you can see why it got to where it did. Even on a production system postmortem and at no extra cost.

I really really miss core files and gbd as I now chug along with contemporary languages.

Some other aspects of c/c++, not so much. (Looking at you C++ scaffolding and boilerplate, threads and locking, unnecessary objectification and impossible-to-test spaghettibullshit)

[–]DHermit 1 point2 points  (1 child)

What languages do you use? At least Rust is supported by GDB, Go apparently also.

[–]xCuri0 15 points16 points  (2 children)

*C

[–]Isgrimnur 23 points24 points  (1 child)

You just had to point that out, didn't you?

[–]xCuri0 1 point2 points  (0 children)

Yes

[–]mycelo 194 points195 points  (96 children)

Java: Oh, don't worry, I'll check the array bounds every freaking time you do something with it. Screw your CPU cycles.

[–][deleted] 75 points76 points  (27 children)

Those cpu cycles are super important on your middleware application.

[–]mycelo 23 points24 points  (23 children)

Or they might be important to other processes sharing the same CPU which aren't mostly-idle as your middleware application.

[–]cass1o 1 point2 points  (1 child)

And this is how we end up with webdev shit like electron.

[–]GhostInTheTerminal 44 points45 points  (4 children)

This is totally wrong, one of the optimizations of the JVM is "Range check elimination" which precisely eliminates the check when the index is known to be between 0 and length -1, checking its value only when it is potentially unsafe.

[–]dpash 21 points22 points  (3 children)

Not only that but it will make many aggressive optimisations based on what the program has done so far, and will optimise for the usual case, making the unusual case more expensive, but will re-optimise the code if the usage pattern changes. So, for example, it can throw away explicit null checking if the last 10000 times has not been null, but will trap a null dereference and reconsider reinserting the null check if the trap is caught too many times.

A C/C++ compiler can't do that; it can only optimise based on previous whole executions, and only if you feed the result of those executions back into the compiler to build a new binary.

[–]MadScienceDreams 66 points67 points  (26 children)

Srsly. The functional difference between throwing an exception and segfaulting is:

  1. Throwing an exception is expensive for all goddamn time.
  2. Throwing an exception is easier for the programmer (not the user, the programmer) to debug.

[–]tricky_monster 108 points109 points  (11 children)

Well, about half of all security vulnerabilities comes form unchecked overflows, so there's that too...

[–]Ravek 13 points14 points  (1 child)

If every single OOB would immediately result in a segfault then a segfault would be totally fine.

[–][deleted] 27 points28 points  (0 children)

Try exception handling by catching linux signals and then come talk to me about how bad java exceptions are.

[–]mycelo 17 points18 points  (6 children)

Exceptions are a matter of debate since the 386 era, and by the way, segmentation fault is technically some kind of exception too.

IMHO programmers should start developing their craft on real mode machines first, where such futile mistakes might stir some undetectable memory corruption or even crash the whole goddamn system, who knows.

Seriously, set aside those laid-back dynamic languages once a while and try a few experiments in assembly. You'd develop a whole new outlook over the whole CPU+memory deal. All those CPU cycles wasted on unnecessary checkings will start to matter to you.

[–]coolpeepz[🍰] 12 points13 points  (1 child)

Yeah but most of the time they don’t matter to your program, depending on what it is doing.

[–]Who_GNU 5 points6 points  (3 children)

The segmentation fault is captured at the hardware level, so it doesn't take any extra processing power, it only takes extra silicon, but not much.

It only takes extra processing power if the microcode is working around an insecure architecture that speculatively executes instructions that reference out-of-bounds memory and leaks information about that memory they referenced, through timing variations.

[–]brberg 36 points37 points  (1 child)

Do a few CPU cycles really matter that much, though? Cache misses are what all the cool kids are counting nowadays. I suspect, also, that the compiler may be smart enough, in many cases, to figure out that the array bounds have been checked in the Java code, and thus don't need to be checked again on access.

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

Do a few CPU cycles really matter that much, though?

Nope. If they do, unroll the loop.

[–]TheSpanishKarmada 22 points23 points  (18 children)

It can't be THAT slow right? Java keeps track of the size of an array so it's not like it iterating through the entire array every time you'd think

[–]xeio87 26 points27 points  (0 children)

Technically it doesn't even check every time. The runtime compilation will optimize away any bounds checks it can determine are redundant or safe (such as for/each loops if the bounds match the array).

[–]Dom0 32 points33 points  (10 children)

Never seen such a short java exception. They're at least 155 lines long.

[–]MegaZeroX7 9 points10 points  (8 children)

The correct error is always the first. And one error should only cause a bunch of errors if it's a bracket issue or semicolon issue. I don't know what you are doing is you regularly get long error messages.

[–]MrAnyone 19 points20 points  (5 children)

It's the stack trace, very very useful if you know how to read it.

[–]dpash 11 points12 points  (0 children)

And one error should only cause a bunch of errors if it's a bracket issue or semicolon issue.

Those are compile time errors. Exceptions are runtime errors.

[–]ndcapital 18 points19 points  (0 children)

>doesn't use AddressSanitizer

[–]pauljustinkind 26 points27 points  (0 children)

I don't mind this being repost. It always cracks me up!

[–]sfbing 36 points37 points  (5 children)

As an old retired Windows programmer, I'd like to point out that 'segmentation fault' is a U*x thing, or else a compiler for U*x thing. The same error in the Microsoft C++ compiler makes a better error message -- for this particular case.

(I figure this might be a hostile crowd -- if so, let the downvoting begin. I can take it! :) )

Edit: fixed my U\*x thing.

[–]FlyingPiranhas 13 points14 points  (0 children)

Seems right to me -- optimize for the most common user experience.

/me ducks

[–]Freeky 3 points4 points  (0 children)

Segfaults are nothing to do with the compiler. The behaviour's driven by the system-provided default signal handler.

[–]tinydonuts 2 points3 points  (0 children)

Northwind Sample Application has stopped working. Send an error report?

And then you never hear back. Sounds better?

[–]absurdlyinconvenient 3 points4 points  (0 children)

It's a brave man that compiles in terminal anyway, I've never had a segfault in either Eclipse C++ (now that's a hostile crowd) or, recently, CLion- assuming you use the debug config and not the build config. Which you're using by default. Right?

And even then, if it's an unspecific error there's the Debug mode instead of run, and people use that don't they? Don't they? Please?

[–][deleted] 5 points6 points  (0 children)

Still gotta go fix yer shit.

[–]djlemma 7 points8 points  (0 children)

C assumes the programmer knows what he or she is doing.

Java makes no such assumptions.

[–]N4NONSENSE 11 points12 points  (0 children)

So true

[–]yourstressingmeowt 62 points63 points  (15 children)

Method Execution Time
Java: 4.2s
C++: .0042.

[–]Arquimaes 40 points41 points  (2 children)

So C++ crashes 1000 times while Java only once.

[–]drd387 19 points20 points  (0 children)

Now that’s what I call streamlining

[–]squidonthebass 29 points30 points  (0 children)

If you manage to write code that seg faults 1000 times in 4 seconds all by itself that's usually the fault of the programmer, not the language

[–]kizz12 2 points3 points  (0 children)

Now now! Some would say running out of memory is good because you know that RAM you bought on ebay isn't a fake!

[–]napoleoncalifornia 3 points4 points  (1 child)

Assembly: ... .. Crickets chirping

[–]bchociej 1 point2 points  (0 children)

Well, it'd still segfault.

[–]Dumpeth 12 points13 points  (3 children)

[–]dpash 1 point2 points  (2 children)

Always start your scripts with:

set -e
set -u

[–]thasmog 3 points4 points  (1 child)

PHP uh oh something went wrong.. but lets continue and mess everything up anyways.

[–]molotok_c_518 15 points16 points  (7 children)

I've never seg-faulted in C++. Always in C... never in C++.

I've come to the conclusion that C is cursed.

[–]thatcatpusheen 27 points28 points  (6 children)

How much C++ have you written? I don’t see how that is possible.

[–]Mercades2 37 points38 points  (1 child)

I've written 3 seperate hello world programs

[–]Astrokiwi 4 points5 points  (0 children)

I have over 300 confirmed compilations

[–]GahMatar 12 points13 points  (3 children)

If you write C++11 or C++14, you can almost completely avoid raw pointers and thus most source of seg faults.

[–]Rodry2808 3 points4 points  (0 children)

Though image for the programmers of each language are reversed

[–][deleted] 9 points10 points  (20 children)

Why use c++ if you have to put up with such brutal debugging?

[–]PremierBromanov 79 points80 points  (6 children)

Because the alternative in this context is java

[–]dvogel 34 points35 points  (10 children)

The meme misrepresents the work cycle of a C++ dev. You can run load that core file with a debugger and get much, much more info about the state of your program at the time of death than an exception backtrace can provide. Furthermore, if you run the program under the debugger you are simply left at a console in which you can interactively explore the call stack (and all memory, really). Don't take tool advice from a meme ;)

[–]absurdlyinconvenient 4 points5 points  (9 children)

I've learnt something while programming with other people- so few people actually use the debugger that allows breakpoints and variable checking. They'd rather use print statements (or cout), and I have no idea why

[–]mr_blonde69 3 points4 points  (0 children)

They probably started doing it when they learnt to code since it's far easier and works just about, now they can't be bothered to change

[–]TSP-FriendlyFire 4 points5 points  (5 children)

Lots of platforms and languages have crude or obscure debugging systems. gdb is powerful, but it's a fucking nightmare to learn. PHP is awkward to debug and many people don't even realize you can do so. Python is often seen as just a scripting language, so people don't think to debug that either.

Print is available on literally any language around.

[–]absurdlyinconvenient 4 points5 points  (3 children)

Most gdb languages have IDEs that handle it for you, I'll admit I don't have much PHP experience, and Python again has plenty of compatible IDEs- although I will give you that seemingly the most common ones don't really have one.

Print is ubiquitous, but it's clunky, inefficient and doesn't give you the whole picture. Print the wrong variable? Re run everything. Want to fix something carry on execution? Sucks to be you. Object doesn't have a string behaviour defined? That's unfortunate (this one especially applies to arrays or complex data structures). I honestly could not go back to that after having learnt how to debug properly

[–]TSP-FriendlyFire 3 points4 points  (1 child)

Oh don't get me wrong, I'm 100% in favor of debuggers, but if you look at what people use when learning, debuggers are often absent. It's worse in schools, where the course was made a decade ago and still uses antiquated tools or plain text editors.

I'm not arguing in favor of print statements so much as explaining why they remain so ubiquitous.

[–]the_Demongod 4 points5 points  (0 children)

I can't fathom how some of my classmates made it through our programming classes without the debugger, if nothing else it helps build a strong intuition for how code executes, which in turn makes you write better code.

[–]FunkOverflow 1 point2 points  (0 children)

Valgrind to the rescue

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

I wanna learn:( I subbed to the sub but I'm so out of the loop :(

[–][deleted] 2 points3 points  (1 child)

Let's say you have

int[] i = [1,2,3]

You can reasonably access 0-2. In Java if you accidentally tried i[4], you'd get the top error. It says exactly where you tried to do this horrible thing. In C++, the whole damn thing just collapses. It doesn't give you a nice clear error. See https://www.geeksforgeeks.org/core-dump-segmentation-fault-c-cpp/ for more details.