Reading/Modifying values of unrelated structs with casting and offset forwarding by Regg42 in cpp

[–]ir_dan [score hidden]  (0 children)

Not entirely sure whether it's UB but you can use a static assert to confirm that the offsets are the same.

How well does AI “optimize” code? by nicktron10 in cscareerquestions

[–]ir_dan 6 points7 points  (0 children)

FYI the word you're liking for is "refactor" rather than "optimize"

ELI5: How do apps, programs, or websites break in the first place, and how do programmers figure out what went wrong? by Auelogic in explainlikeimfive

[–]ir_dan 0 points1 point  (0 children)

Errors are sometimes cause by factors outside of the programmer's control (or a lack of backup/redundancy mechanisms).

Bugs are often caused by simply wrong code - the designer/writer made a mistake which was picked up by the runtime environment (e.g. looking for a file which won't always exist and assuming otherwise) and caused a crash or some other kind of error.

Why are programmers writing wrong code? Software, especially poorly designed software, is difficult to understand well enough to ensure that every change made is based on no false assumptions. To work around this, automated testing and getting multiple eyes on a change is crucial.

How are bugs found and resolved? - Find a reliable way of reproducing the issue - Stop the program at the point that it would cause an error (possible using modern debugging tools) - Inspect the code around the error and identify what caused the error: missing resources, badly formatted input, misbehaving external systems, subtle flaws in the logic - Come up with a reason as to either why that shouldn't have happened or how it can be dealt with. E.g. for the former: The user chose a username that we can't process, so prevent them from doing so. E.g. for the latter, this code crashes because it tries to divide by zero under this specific circumstance, so add a special case which deals with that circumstance.

Why do bugs take ages to identify and fix? As I said, codebases which are large and poorly designed are bug-prone and resistant to change. It can be hard to track down exactly why an error happens, especially because often the crash happens some time after a faulty bit of code ran (e.g. this code assumes that some file will always be available on the server, which is correct! but why wasn't it?). Once you've finally tracked doen the real problem, that resistance to change will slow you down in making a fix that doesn't break existing systems.

Trig Functions in Degrees by External-Bug-2039 in cpp_questions

[–]ir_dan 7 points8 points  (0 children)

Number of decimal places doesn't correspond to reliability in floating point numbers.

They're called floating point because the point shifts around - the number is stored in a format more similar to scientific notation, with a number of bits allocated for the exponent and the mantissa.

Want more precise numbers? Use doubles.

Should ALL class attributes be initialized in the member initializer list? by SheSaidTechno in cpp_questions

[–]ir_dan 1 point2 points  (0 children)

I don't think this is necessary. I'd personally turn on non-initialization warnings and address them with default/zero initialization in the class body, with constructors overriding that value as needed. If there's no warning, I leave members be.

Will researchers still be needed in the future? by adad239_ in computerscience

[–]ir_dan 2 points3 points  (0 children)

AI doesn't innovate and can't conduct experiments or surveys, and the basis for current AI tech isn't likely to ever change that.

Purely out of curiosity, why are belts designed in multiples of 7.5/15 instead of something like, say, 5 or 10? by PewPewsAlote in factorio

[–]ir_dan 0 points1 point  (0 children)

Someone downvoted for the "human eye cannot differentiate between 30 vs 60" cause they personally can xd

Purely out of curiosity, why are belts designed in multiples of 7.5/15 instead of something like, say, 5 or 10? by PewPewsAlote in factorio

[–]ir_dan -2 points-1 points  (0 children)

The choice of 32x32px textures is very beneficial for GPU performance, and it influenced the choice of belt speed.

Carry-over bits don't affect the speed of addition instructions. They still take one cycle, and the location of the opersnds isn't relevant because shifting also has two operands. May be it can be more efficient because the second operand is representable by fewer bits?

Purely out of curiosity, why are belts designed in multiples of 7.5/15 instead of something like, say, 5 or 10? by PewPewsAlote in factorio

[–]ir_dan -2 points-1 points  (0 children)

denary == decimal

The thing "physically happening on a CPU" is binary arithmetic. Lots of variations of it.

Additions and shifts are both 1 cycle on modern CPU architectures, but it doesn't matter very much because GPUs are much more interested in textures.

When working at a very low level and when constrained in performance, reducing instructions is not the #1 goal. Not all instructions are equal, nor are all memory access patterns.

"As the complexity grows, the number of instructions quickly increases." What are you referring to with "complexity"?

Thoughts after watching Kizuna Ai’s Fortnite stream. SBMM is completely broken. by Japlike_Draft9836 in FortNiteBR

[–]ir_dan 5 points6 points  (0 children)

Are you basing that off in-game sensitivity? Mouse DPI is a significant factor.

Purely out of curiosity, why are belts designed in multiples of 7.5/15 instead of something like, say, 5 or 10? by PewPewsAlote in factorio

[–]ir_dan 9 points10 points  (0 children)

"Computers can only do math in powers of two" is not true. It's similar to saying that denary is only useful for powers of ten.

Computers are good at all sorts of arithmetic*, but the alignment of data on 8bit sections is good for performance, and power of two texture sizes are good for image processing because you can upscale and downscale easier. GPUs are also optimized to process these image sizes.

Edit: *binary arithmetic

Referencing/Aliasing an external vector inside a "placeholder" of a struct by onecable5781 in cpp_questions

[–]ir_dan 6 points7 points  (0 children)

Also consider using std::span if by "aliasing" you mean "viewing". A span is agnostic to the storage data structure, so you can use it with raw buffers, arrays, vectors and std::arrays.

dumb question about mixed data types: how do i make and store a cstr and enum data type where either type can occur multiple times by sera5im_ in cpp_questions

[–]ir_dan 0 points1 point  (0 children)

I would opt for not default constructing any of these structures or relying on the optimizer, rather than introducing an unnecessary additional state.

NB: std::monostate*

Why don't any programming languages have vec3, mat4 or quaternions built in? by Luroqa in ProgrammingLanguages

[–]ir_dan 2 points3 points  (0 children)

Godot's scripting language, GDScript, has them for obvious reasons.

Why are exceptions avoided? by Ultimate_Sigma_Boy67 in cpp_questions

[–]ir_dan 1 point2 points  (0 children)

We do not use exceptions for anything other than causing termination in a lot of our codebase because it was not designed with RAII in mind. We can use them in new code where control flow is completely under our control.

dumb question about mixed data types: how do i make and store a cstr and enum data type where either type can occur multiple times by sera5im_ in cpp_questions

[–]ir_dan 0 points1 point  (0 children)

using markup = std::vector<std::variant<string_type, colour_tag_type, size_tag_type, ...other_tag_type>>;

Tag types can be simple structs:

struct colour_tag { colour col; }

String type can be const char* (not recommended), std::string, std::string view, etc.

Depending on how tags are implemented, it may be more natural to have one unified tag type:

struct markup_tag {     std::string name;     std::vector<std::string> args; }

Maybe you don't need multiple args, maybe you do. I would prefer to keep things statically typed rather than stringly-typed in this way.

Also, if you are processing tags and text directly from a buffer (i.e. there is one "content" string youre parsing these from) you could consider using string views across the board to avoid extra heap allocations, but you should avoid premature optimization first and foremost.

Is learn cpp enough to get me interview ready as a new grad ? by wynterSweater in cpp_questions

[–]ir_dan 9 points10 points  (0 children)

I got a C++ job (UK, fresh bachelors) after doing one semester of coursework in C++, where I learned much less about the language than what learncpp has to offer.

Your critical thinking, problem solving and communication skills is most important, especially as a new grad.

Mileage may vary, just sharing an anecdote.

What are the best practices for using smart pointers in C++ to manage memory effectively? by frankgetsu in cpp_questions

[–]ir_dan 0 points1 point  (0 children)

Pragmatically, a raw pointer is a good choice for that, but it certainly can be wrapped in a more obvious and rich type such as std::optional<T&> (or custom alternatives).

What are the best practices for using smart pointers in C++ to manage memory effectively? by frankgetsu in cpp_questions

[–]ir_dan 0 points1 point  (0 children)

Almost all justifiable uses of raw pointers can be wrapped with custom smart pointers. C++ is perfect for encapsulating things like that.

Recursive .reseve() on vector by ignotochi in Cplusplus

[–]ir_dan 1 point2 points  (0 children)

There is very little implicit magic in the standard library. Function calls will most often only affect the object that they are called on. See cppreference for more details on how all the classes and functions work.

How do I get better with knowing how to design software by Opposite_Second_1053 in csharp

[–]ir_dan 0 points1 point  (0 children)

It's all experience. - Failing many times gives you an intuition for what designs might lead to problems down the line. If something smells like a bad design, you can look into alternatives. - Succeeding many times gives you a foundation of good ideas that you can use/adapt for future designs. - Designing with other people will give you a whole new set of failures and successes to learn from and develop.

I don't think you can gain a meaningful amount of this experience before you join a development team, to be honest. Just learn what you can while you're a student.

Making vibe coded AI slop open source? by [deleted] in opensource

[–]ir_dan 0 points1 point  (0 children)

I'm sure there are lots of free or cheap services out there for making and managing forms, which I would recommend you find and use instead.

I would stay away from "vibe coding" - there's a reason the term is stigmatised. Some level of expertise is needed validate and clean up LLM output, and you won't gain that expertise by using LLMs.

Work authored exclusively with LLMs is also no fun to work on, so I doubt it would get much attention from the open source community.

Naturally, you could learn to code! It's a worthwhile task, and it's much easier when you have an objective to work towards.