C++ Moment - Lemmy.World

let’s not act like Java’s error log is useful

I think it’s pretty useful, be interested to hear your hangups with it though because it’s definitely not perfect.

If something goes wrong and I have a stack trace, that plus the type of exception will almost always be enough for me to figure out what’s wrong at least as a starting point. I’ve worked mostly with JVM languages in my career though so maybe I just don’t know how bad it actually is.

It’s not bad. It’s better than what most languages give you
skill issue

The same applies to using the core dump.

In fact, the Python one is the lest useful of the trio.

When the day comes that you need gdb you will indeed be amazed at how fucking powerful it is. If your server crashes grab that core dump!
Implying you can’t consistently go to the same line every time and it always has what you need.
It’s extraordinarily useful
The developer must either provide the logging and attach a debugger or go get fucked when a runtime error happens
That’s not true though. You can get the backtrace and other useful information from the coredump mentioned by the error message by loading it with gdb. Not as good as attaching it to a living process, since you can’t see step-by-step what happens leading up to the error, but still more useful than ā€œgetting fuckedā€.
Well yes, that’s a pretty good way of debugging a third party app but if you are developing something you can have more ease with gdb attached
You can also debug post-mortem with the minidump or the core dump file with WDT on Windows. Great fun and a good way to brush up on your assembly skills

Great fun and a good way to brush up on your assembly skills

Just load it on the debugger and leave your asm skill gather patina.

My favorite compile error happened while I was taking a Haskell class.

ghc: panic! (the ā€˜impossible’ happened)

The issue is plainly stated, and it provides clear next steps to the developer.

I had a similar error, though not from the compiler
Error message just read this should never happen
Ah, good old PlarformIO

I know this is supposed to be humorous, but there’s a reason why these languages can, and are doing what they’re doing.

Core dumps are also worth learning about, they’re really helpful if you understand them.

gdb: Am I a joke to you?

Yes. It’s a surprisingly bad debugger the more you think about it. I use it largely in assembly and it loves to spit out random errors about memory it tried to access based on the current register state. The shortcuts are kind of dumb.

It certainly works but I wouldn’t call it a pleasure to use.

I use gdb with great success for x64, rv64, and c:

info registers rip or just setup tui:

# ~/.config/gdb/gdbinit: tui new-layout default regs 1 {-horizontal src 1 asm 1} 2 status 0 cmd 1 tui layout default tui enable
I honestly vastly prefer using IDA and Windows specific tools (x64dbg) over gdb. IDA can interface with gdb so it can act as a frontend which can be handy for visualization.
No bounds checking, only fast.
This right here - C++ iirc is used mostly for microprocessor code in an industry setting, where EXTENSIVE testing is done so that bloated code doesn’t need to constantly check for programmer errors every single time, i.e. where execution speed is prioritized over programmer development time. And whenever that is not the case, well, as OP pointed out, other higher-level languages also exist (implication: to choose from).
It’s also used for basically any AAA game

C++ iirc is used mostly for microprocessor code

lol no, it’s used almost everywhere where performance is important and people want(ed) OOP, from tiny projects to web browsers (Chrome, Firefox) to game engines (Unreal, CryEngine). Many of these are hugely complex and do encounter segfaults on a somewhat frequent basis.

Saying C++ is mostly used for embedded applications is like saying C# is mostly used for scripting games, i.e. it doesn’t nearly cover all the use cases.

higher-level languages also exist

This depends on your definition of ā€œhigher-levelā€, but many people would argue that C++ is on a similar level to Java or C# in terms of abstraction. The latter two do, however, have a garbage collector, which vastly simplifies memory management for the programmer(generally anyway).

I also currently use it for a new project since all needed 3rd party libraries are from a very specific domain and the project has a deadline, so writing and testing wrappers for Rust that would provide me with any meaningful advantages down the road are too costly to budget for before the deadline.

That could become part of a future refactoring, though.

There is bounds checking, but it’s opt-in. I often enable it on debug builds.

At least you are getting a dump, count your blessings. Could be worse!

Just hook your app to a debugger and load the dumb.

Python: So you used spaces and tabs for indentation? NOW DIE!
Good. Spaces and tabs for indentation should never be mixed in any language other than Whitespace.

Raw adjust with tabs, fine adjust with spaces.

Don’t laugh, people are actually doing that.

Some people use tabs for indentation and spaces for alignment. It kind of gets the pros of tabs (user configurable indent-width) and the pros of spaces (alignment).
There are no pros to tabs. Configure tabs to a number of spaces.
Mixing spaces and tabs should be a warcrime.

Find me anyone who claims they use tabs for indentation, and I bet I’ll find at least one case where they’re using both tabs and spaces.

The only safe way to avoid war crimes is to avoid tabs.

I use the tab key but I’m pretty sure vs code converts that to spaces
Depends on your settings, but yeah typically it does
It worries me that a programmer wouldn’t know for sure what’s happening when they hit tab, and that it’s a setting that can be changed.
I mean I was 99% sure it convert to spaces, I cannot say I was certain. The default settings are fine for what I do, I only ever had to change the spacing from 4 to 2 spaces once when dealing with someone else’s files
Why would I use spaces if I use tabs? Also, it seemd like a huge waste of time hitting the space bar so many times…
Most modern editors/IDEs do indentation automatically and, when you press the tab key, insert whatever style of indentation you have configured (tab, multiple spaces at once)

Why would I use spaces if I use tabs?

To comply with Python’s best practices:

peps.python.org/pep-0008/

Also, it seemd like a huge waste of time hitting the space bar so many times…

You use an editor that doesn’t auto-indent?

PEP 8 – Style Guide for Python Code | peps.python.org

This document gives coding conventions for the Python code comprising the standard library in the main Python distribution. Please see the companion informational PEP describing style guidelines for the C code in the C implementation of Python.

Python Enhancement Proposals (PEPs)
I assume this was a joke 😁
I use vi without syntax highlighting.
Please don’t hack me, mister FBI
To be fair you can totally bind an arbitrary number of spaces to tab in vi. I’ll dig out the syntax highlighting file some time. Oh and I use vim really.
I do use neovim myself too 😁
Don’t IDEs just replace any tab with 4 spaces anyways? Pretty sure VSCode does

I    don’t    use    an    ide,    but    I    wrote    a    script    that    replaces    any    space    I    type    with    four.

I    haven’t    worked    out    all    the    use    cases    yet,    though.

That’s a setting in the editor.
Linux kernel coding style — The Linux Kernel documentation

And in Python, it’s merely a SyntaxCrime.
Mixing tabs and white spaces in 2024 is categorically a you problem lmao
The guy is testing the result of malloc and you are complaining about how?

www.youtube.com/tsoding

If you’re a programmer, or think you might want to be one, I highly recommend this channel. He’s a savant at all sorts of low level things, quite funny and entertaining, and does a fantastic job of explaining what’s going on.

Bevor Sie zu YouTube weitergehen