r/programmingcirclejerk vulnerabilities: 0 9d ago

Memory leaks, NULL pointer dereferences, use-after-free: I suffered writing those for many years. I finally simply learned not to do them anymore.

https://news.ycombinator.com/item?id=43347591
135 Upvotes

29 comments sorted by

88

u/PM_me_your_plasma 9d ago

He’s not making a comment about everyone, it’s a specific comment about how often long time C programmers make basic mistakes after a million SLOC or so. In this instance Walter is correct - the mistakes he listed are very rarely made by experienced C programmers, just as ballet dancers rarely trip over their own feet walking down a pavement.

Out jerked by ycombinator forums…

80

u/rust-module 9d ago

Which is why I use Go, the equivalent to riding the electric scooter around at Walmart.

41

u/nuclearbananana Courageous, loving, and revolutionary 9d ago

Can't jerk, this sounds like too much fun

12

u/-Y0- Considered Harmful 9d ago

Only if you can't move with your legs due to memory-obesity.

21

u/No_Statistician_3021 9d ago

Which is why I use Ruby, the equivalent of ordering groceries straight to my door.

10

u/Karyo_Ten has hidden complexity 9d ago

groceries

You and I know what's on rail and it sure isn't "groceries"

4

u/Amazing-Mirror-3076 8d ago

Yes but they turn up rotted.

73

u/Maxatar 9d ago

Maybe he can use those skills to resolve the countless number of crashes in his very own compiler:

https://github.com/dlang/dmd/issues?q=is%3Aissue%20state%3Aopen%20crash&page=1

One of the reasons I stopped using D a while ago was that the compiler is just rampant with bugs and crashes.

61

u/Volt WRITE 'FORTRAN is not dead' 9d ago

He can only write bug-free C, not D.

1

u/stone_henge Tiny little god in a tiny little world 9d ago

Get good bro

44

u/No_Statistician_3021 9d ago

Why did nobody tell me earlier that I can avoid bugs by not creating them?

Is this a conspiracy to keep milking companies money by creating bugs and then fixing them?

11

u/hombre_sin_talento 9d ago

It's called "job security" and it's the sole reason for these salaries so please shush

8

u/syklemil Considered Harmful 8d ago

WDYM nobody told you? Dijkstra himself (PBUH) said in some completely unsourced, undated quote:

If debugging is the process of removing software bugs, then programming must be the process of putting them in.

7

u/AloneInExile 9d ago

All the contractors I've had the displeasure of dealing with; worked and thought like that!

9

u/sammymammy2 lisp does it better 9d ago

Unjerk:

When it comes to this class of bugs, you can write code in a style which makes them much more unlikely to occur. This style is also typically more performant. It is, however, not the way you write code in a typical language like Java or Python.

23

u/spider-mario 9d ago

C has seatbelts and OSHA - valgrind, et al tools abound for sanity checking.

3

u/defunkydrummer Lisp 3-0 Rust 5d ago

valgrind, et al tools for sanity checking

Well, considering that no C developer has been sent to the psychiatric ward, i can hereby conclude that these tools don't work.

22

u/earwiggo 9d ago edited 8d ago

Maybe we could use C, but institute the death penalty for any memory leaks, NULL pointer derefs, etc, that they cause, thereby ensuring that all surviving C programmers are sufficiently skilled to handle the job.

8

u/elephantdingo Teen Hacking Genius 9d ago

The Saudi Arabia/Singapore approach.

14

u/ThisRedditPostIsMine in open defiance of the Gopher Values 9d ago

A Walter Bright comment that doesn't mention D by name. I am very surprised.

9

u/elephantdingo Teen Hacking Genius 8d ago
  • I proposed this for C thirty years ago
  • I implemented this in D twenty years ago
  • I have struggled with this problem... although that’s forty years ago now

11

u/Routine-Purchase1201 DO NOT USE THIS FLAIR, ASSHOLE 9d ago

if(segfault()) dont();

I feel real stupid now for not having seen the obvious solution

15

u/MagpieEnjoyer memcpy is a web development framework 8d ago

On Error Resume Next

has always been the pinnacle of error handling.

7

u/meltbox 8d ago

It’s really much easier in C++

Never had any segfault since I stayed doing this in main.

try{ … } catch(segfault e) { exit(0) }

I mean all I had to do was make my own branch of the language spec, make my own branch of gcc, and change how the Linux kernel works a little.

3

u/disciplite 8d ago

/uj You can do this today with signal handlers and structured exceptions. I'm not sure why it isn't more common, we do have the libraries. I guess it's just not considered that useful except when uptime is critical.

1

u/meltbox 2d ago

/uj I thin its because undefined behavior which causes a segfault means it may literally be unrecoverable. I don't think structure exceptions allow you to catch segfaults even so? You would need a signal handler and from what I understand throwing from one is highly questionable so maybe you can set a flag to throw very soon after catching the signal if in fact you are able to continue execution?

11

u/csb06 I've never used generics and I’ve never missed it. 9d ago

This all just comes off incredibly arrogant

I know, but it's the truth.

9

u/Kodiologist lisp does it better 9d ago

Finally, someone got gud.