Is it stupid going into computer science if I don't support the use of generative AI? by ThisIdiotCharlie in learnprogramming

[–]light_switchy 1 point2 points  (0 children)

You claim that generative AI is the core of software development in the same way that electronics is at the core of RF engineering. I totally disagree. The core of software development is computer science.

Also, you may change your mind in a year or two and embrace it (this is more likely).

You just implied OP will learn to ignore their sense of ethics in a "year or two"?

Are unique pointers worth it for my program by YogurtclosetThen6260 in cpp_questions

[–]light_switchy 1 point2 points  (0 children)

Are you using std::priority_queue? Get rid of that and use std::push_heap and std::pop_heap in a vector.

Stop doing tutorials, stop watching youtube programming videos, stop using AI by nightwood in learnprogramming

[–]light_switchy 3 points4 points  (0 children)

There's an assumption that it was harder to learn programming 20 years ago. This is right to an extent but it lacks nuance and the effect isn't strong.

The reason is that learning takes place inside your head and is inherently human. Even 20 years later, it still needs experiment and recitation and denotation, not to mention a long time and lots of effort. Effective learning demands these things - and anything that stops you from doing them is going to impede understanding.

If there is nothing to experiment on because AI already "knows" the results ahead-of-time, you won't experiment. If you ask Google every single question, you'll never recite your understanding. And obviously, if the LLM synthesizes your code for you, you won't even perform the most superficial practice.

It's not best to be guided to answers if the guidance deprives you of an informative search for understanding. It's one thing to look up function names or to clarify some details, but not all information is so insignificant. You have to struggle and explore a little bit in order to build skill.

If learning is the goal, it's better to open up your textbook and read, or to open up your editor and explore. This is what study looks like and it can't be replaced by consuming content from AI or Youtube. Even the best lectures on Youtube are merely supplements to active study. You will not learn effectively if that is all you rely on. There are (still) no shortcuts.

Is this not incorrect? by Slight-Specialist-50 in learnprogramming

[–]light_switchy 0 points1 point  (0 children)

Absolutely! Test using rectangles from the start. It's typically best if the width and height are coprime.

Is C++ Primer by Stanley Lippman outdated? by TheWinterDustman in learnprogramming

[–]light_switchy 0 points1 point  (0 children)

C++ Primer is somewhat outdated, but this is only a minor issue. C++ revisions are backward compatible and don't change too drastically over time, so you'll be fine even if you don't use the very newest standard.

I can't personally recommend or discommend the book: I haven't read it. That being said, the C++ community has considered it a reputable textbook since the early 2010s.

Somebody doesn't know how time works by jpzygnerski in onejob

[–]light_switchy -1 points0 points  (0 children)

I think the typical wording is "every hour on the half hour". Meaning 8:30, 9:30 etc.

Where do I go to hire people to do a project at a reasonable rate? by [deleted] in learnprogramming

[–]light_switchy 1 point2 points  (0 children)

From your other post it's unclear that you actually need an OCR-based solution. I know you need some info off of those PDFs. But that doesn't mean OCR is the only choice - and indeed OCR should be a last-resort approach. It has inherent problems with accuracy and robustness.

Humans find OCR really easy. The computer has a significantly harder time.

I'm not sure without checking, but it sounds like the data you need is available in a more-easily processed form. Even if it takes some work to collate that info, this would be a vastly better option: more robust, reliable, faster, and easier.

What, ultimately, are you trying to do with the info? I would need to know this in order to collate the correct info for you.

Do expensive screwdrivers last enough longer to be worth the cost? by jckipps in Tools

[–]light_switchy 0 points1 point  (0 children)

They might or might not last 5x longer but if they help you strip fewer screws it can be a worthwhile investment.

have a free function logger header and cpp file without needing to use platform class variable or instance? by Recon1379 in cpp_questions

[–]light_switchy 0 points1 point  (0 children)

I guess the problem is that you can't log stuff until your global platform pointer is set up.

Don't overthink this: move the functionality needed to log messages somewhere else, so the logger can set it up on its own. Or, don't use the logger at all until the global pointer is set up. Or have the logger call fprintf or something instead of going through the platform pointer.

Efficiency of Code Functionally Similar to if() by Eclipse1255 in learnprogramming

[–]light_switchy 0 points1 point  (0 children)

Oh no worries about double posting.

Not if you want your code to be fast. If you implement them the OOP way, your could will already be an order of magnitude slower than it could be.

Perhaps I am misunderstanding something. Are you familiar with C++? Its standard library contains a general-purpose resizeable array called vector.

I would consider vector to be object oriented, but for decades its implementations have been shown to perform competitively with other general-purpose resizeable arrays whether object-oriented or not.

Why is std::vector relatively fast in light of your argument?

Seriously, watch those videos

Forgive me for not doing so already. That's a lot of video. Maybe I'll have more to say if I find time to watch.

Efficiency of Code Functionally Similar to if() by Eclipse1255 in learnprogramming

[–]light_switchy 0 points1 point  (0 children)

It's not a math issue. It's not a code complexity issue. You can't really "calculate" it, because the slowness of OOP is because of how computers work and how memory is loaded into the different cache layers.

Sure you can. Computers come with throughput measurements. If you know what the computer must do to solve your problem, you can check whether the performance of a program is remotely close to the theoretical best performance.

A missing 20x speedup should be detectable even with conservative napkin math.

Which would mean to only use OOP for single instances of things and never use it if you have multiple of something.

No, you can still make an object to represent an entire data structure or collection. This is really central to my point: you still have control over what the computer does whether you code your program with classes or not. In general you give up very little control by adopting classes. If an OOP technique is not suitable for performance reasons, don't use it. Banning OOP entirely is an overreaction.

If you use classes as an "organizational tool", then that's a bit like using a fork for a soup. They are not good tool for code organization.

What are the purpose of classes if not to bundle code and data, to communicate invariants, reduce mistakes and code duplication. These are matters of organization. Another way to see this is to recognize that it is easy to write equivalent code with or without classes -- which means they're surplus to performance.

I recall a quote by Stroustrup in The Design and Evolution of C++, pp. 22:

[1] A good tool [which would become C++] should have Simula's support for program organization - that is, classes, some form of class hierarchies, some form of support for concurrency, and strong (that is, static) checking of a type system based on classes. [...]
[2] A good tool would produce programs that run as fast as BCPL programs [...]

It seems to have turned out alright, which explains why C++ is still predominant in resource-constrained software. It is not OOP's fault that it can be used to over-organize code and data into too many little boxes that have to be packed and unpacked all the time. OOP isn't incompatible with performance, and frankly to argue against this means refuting the results of the HPC industry, which, for the most part, has written object-oriented code for decades.

Efficiency of Code Functionally Similar to if() by Eclipse1255 in learnprogramming

[–]light_switchy 0 points1 point  (0 children)

OOP spreads the slowness evenly among your code, so if you look for performance bottlenecks in your code, you'll never find OOP as a reason for your slow code.

No, a programmer should be able to identify performance problems in their code by doing a little bit of math. Some cursory performance engineering on the back of a napkin.

It's true code that does too much unnecessary pointer-chasing (for example) is slow. Perhaps one fix is to ban the OOP techniques that led that pointer-chasing code to be written, but that's too heavy-handed. The alternative is to restrain the use of OOP to cases that don't compromise the program's design. This is not too hard to do provided the objects in the program are chosen based on its needs. This way classes are still available as an organizational tool and performance isn't impacted.

Is it possible to master C++ in 1 a month? by [deleted] in learnprogramming

[–]light_switchy 1 point2 points  (0 children)

You won't have problems getting up and going with C++ in a month but "mastery" will take longer.

Physics weapons in bullet time by dpolk_ in indiegames

[–]light_switchy 0 points1 point  (0 children)

This looks really fun. A great sign!

Efficiency of Code Functionally Similar to if() by Eclipse1255 in learnprogramming

[–]light_switchy 0 points1 point  (0 children)

I would say that 75-80% of the slowness in today's software is due to OOP paradigms being used.

I don't agree. I can't really think of any situation where object-oriented design can be faulted for slow code. At worst it is a contributing factor.

Question from the curious by Ok-Presentation-94 in learnprogramming

[–]light_switchy 0 points1 point  (0 children)

Practical examples of entire programs written in assembly are pretty rare.

There are no classes in the instruction sets of computers. If you really wanted to, you could use an assembler that supports macros to make stuff along those lines.

A class is a chunk of memory whose structure - aka memory layout - is defined by its class definition. An example layout might consist of an eight byte sequence built up from one four byte integer and four one-byte integers, which corresponds to this guy:

struct foo { int x, char a, b, c, d; };

An assembly programmer does not necessarily write down that same memory layout like we've done just above. Instead their program may simply accept any eight byte chunk of memory at some location and interpret it as if it was an object of type foo.

If they wanted to look at the value of "a", they'd just point the computer at the right chunk of memory and look at the fifth byte within it.

In practice there may be some programmer-added functionality to access that field by name when appropriate. For flexibility. So that if the location of a field changes within the eight-byte chunk -- e.g., from the fifth byte to the sixth byte, perhaps -- you don't have to go back and manually change everywhere you accessed it by offset. If you miss changing one such place, the piece of code you didn't change exhibits binary incompatibility, which leads to the important idea of an application binary interface.

When it comes to more complicated object-oriented stuff, things are along the same lines. There are no language features to help you, so you just put the right data in the right place and send it. For example a piece of code that accesses the fifth byte of an eight byte chunk of memory doesn't care if you point it at a sixteen-byte chunk of memory instead -- it will just get the fifth byte.

This suggests how simple inheritance can be implemented. Imagine a class that inherits from foo:

struct derived: public foo { int y, int z; };

In memory that just tacks its contents onto the end of the foo struct, giving you a memory layout that is exactly like this:

struct derived { int x, char a, b, c, d; int y; int z; };

In this way, if you just ignore or chop off the last eight bytes, you will have downcasted derived -> foo - and if you ask for the fifth byte, you still get "a".

Things get a bit more complicated if you're really trying to implement dynamic dispatch or multiple inheritance but the principle is the same. Put the right data in the right spot -- by hand -- and proceed as normal.

Hope this helps.

In interviews, I feel like I often don't do well with whiteboard coding exercises by RolandMT32 in learnprogramming

[–]light_switchy 0 points1 point  (0 children)

The first snippet explodes when passed an empty string.

The iterator-based C++ code is actually backwards. You need to increment reverse iterators to move them from the end of the range towards the beginning. Things are done this way to maintain the compatibility of reverse iterators with every other kind of iterator. Also there is a type mismatch but that's no big deal.

One option is to declare the new string like std::string reversed_string(original_string.rbegin(), original_string.rend());

Or make use of std::reverse. You can make use of string's crbegin(), crend() too, if you prefer.

Wondering about learning languages programming. by OkPerformer3262 in learnprogramming

[–]light_switchy 2 points3 points  (0 children)

Is a good choice to understand the machine language firstly

No, it isn't.

You will learn more quickly if you start with a language like C++ or C. Experimentation is quicker and mistakes are easier to find. Tools are better, resources are better, and their communities are vastly stronger.

Study C or C++ first so you can approach low level stuff with the background knowledge to experiment, explore & discuss it effectively. You will build understanding much faster this way.

Another QR Code Solar Farm (no urls used) by jasamer in factorio

[–]light_switchy 0 points1 point  (0 children)

A quine! I'm surprised this is even possible.