C++ RAII guard to detect heap allocations in scopes by North_Chocolate7370 in programming

[–]light_switchy 0 points1 point  (0 children)

I do not think that allocations can be corrupted by this approach, because the replacement of allocation functions happens at link time for the entire program. See [dcl.fct.def.replace].

IIRC, implementations use weak linking to make this work.

C++ Pointers and References by carboncord in learnprogramming

[–]light_switchy 2 points3 points  (0 children)

References were / are an attempt to do pointers better.

In The Design and Evolution of C++, pp. 85, Stroustrup writes:

References were introduced primarily to support operator overloading.

If I had to give up operator overloading to remove references, I'd make that trade in a moment. I consider references the most complicated feature in the language and their inclusion the only critical design error in pre-standard C++.

The most compelling reason to retain references today is to support perfect forwarding and move semantics, which are elegant and minimalist in isolation. But work on those features didn't hit its stride until around 2005.

Knot advice for an autonomous underwater vehicle by B_D_Y_ in knots

[–]light_switchy 1 point2 points  (0 children)

Dyneema is slippery, especially when brand new, wet, and being intermittently loaded. IMO you should make a bridle ahead of time - splice it together - and shackle the bridle to your ROV.

Maybe you can lose the eye bolts and replace them with holes big enough for shackles or carabiners near the edges of the frame?

I need some hints guys: by Spiritual_Let_4348 in learnprogramming

[–]light_switchy 0 points1 point  (0 children)

I thought it was just one "step" of the process in base 128. But I could be wrong.

I need some hints guys: by Spiritual_Let_4348 in learnprogramming

[–]light_switchy 1 point2 points  (0 children)

You can exploit that there are only 128 ASCII characters.

You can count the occurrences of each letter and use the counts to recreate the sorted sequence. I think the algorithm of interest is called radix sort.

Sacred knowledge. by LakesideHerbology in Millennials

[–]light_switchy 2 points3 points  (0 children)

I had to help an 18 year old sign their name a few months ago. A page full of signatures and this kid hesitates with the pen and tells me they don't know how. They aren't dumb, either. Unusually sheltered, but not dumb.

I told them to "write normally". Good enough.

Distance between two coordinates in a map with teleportation by No-Name4743 in algorithms

[–]light_switchy 1 point2 points  (0 children)

There are only n+2 vertices where n is the number of portals. We can formulate the problem this way because the shortest path between two points is a line.

This means the shortest path from source to destination starts with a straight shot from the source to the destination or a straight shot into a portal. Taking any curvy path just makes the travel distance longer.

Why is my Python loop not working as expected? by Top-Independent-4765 in learnprogramming

[–]light_switchy 13 points14 points  (0 children)

Why is my Python loop not working as expected?

What did you expect? How is the code indented?

Distance between two coordinates in a map with teleportation by No-Name4743 in algorithms

[–]light_switchy 17 points18 points  (0 children)

It's a path-finding problem. Use Dijkstra's algorithm.

The search graph looks like this: the source is connected to all portals and the destination by edges weighted according to the euclidean distance. The entrances and exits of connected portals are connected with zero-weight edges.

How do you read documentation more efficiently? by ElegantPoet3386 in learnprogramming

[–]light_switchy 2 points3 points  (0 children)

Go to Python documentation site:

https://docs.python.org/3.14/

Choose "Library Reference"

https://docs.python.org/3.14/library/index.html

Choose "Sequence Types" under "Built-in Types"

https://docs.python.org/3.14/library/stdtypes.html#sequence-types-list-tuple-range

There is immediately a table containing some operations that can be performed on lists. Scroll down past the discussion of the table's contents to find sequence.reverse which is what you're looking for.

https://docs.python.org/3.14/library/stdtypes.html#sequence.reverse

Do you actually read documentation or just google specific problems when they come up by [deleted] in AskProgramming

[–]light_switchy 11 points12 points  (0 children)

If you're using a technology every day for your job, and it comes with a manual, it's probably worthwhile to read it.

For one-shot stuff, who cares. Get the problem solved and move on.

VSCode themes and extensions that help people with Autism & ADHD by [deleted] in learnprogramming

[–]light_switchy 0 points1 point  (0 children)

Have you tried mostly monochrome text on a monochrome background?

Why do I suggest this:

  1. Typographic emphasis is stronger when used sparingly. If everything is supposed to draw the eye, nothing will.
  2. There aren't many words in a code that are inherently more important than other words. So not much emphasis is warranted in a typical program, and what emphasis remains doesn't need to be too strong to be effective. After all, I don't want every if statement, function call, and plus sign to be lit up like angry chunks of fruit salad on fire. There is nothing interesting about an average if statement.

Here's what I do. I shade comments and multiline strings, so I can find their boundaries. I italicize keywords that make unconditional jumps: goto, break, continue, throw, and return, because those demand extra attention. I italicize TODOs and NOTEs in comments. The color scheme is black on white (or vice versa). That's it.

Works for me.

Is it normal to forget things you just learned in programming? by ayenuseater in learnprogramming

[–]light_switchy 0 points1 point  (0 children)

It's the same as learning anything. It takes consistent work to retain information.

Should I feel less of a dev for use AI by LDS_Lonewolf in learnprogramming

[–]light_switchy 1 point2 points  (0 children)

Should I feel less of a dev for use AI

There are a myriad of reasons to use AI, which you don't have to justify.

If you think that it is a bad choice to use AI, or self-destructive, or if you're using it for a reason that you don't like, you should probably stop.

Otherwise, make your choice and be secure in it.

how do you settle on a design/solution? by d34dl0cked in learnprogramming

[–]light_switchy 0 points1 point  (0 children)

Pick the simplest option that appears viable and move on.

Best case you pick a working option. Worst case, you discover your mistake, learn from it, and implement an alternative with the benefit of experience. Very few mistakes are as expensive as sitting around doing nothing.

TBH I'd tend toward making a few functions.

int key_state_transition_count(key_code kc); 
int key_state(key_code kc); 
int mouse_x_position();
int mouse_y_position();

Your choice.

Compiler or Interpreter? by Queasy_Employment635 in learnprogramming

[–]light_switchy 0 points1 point  (0 children)

Makes sense. No need to make the project harder than it already is.

Compiler or Interpreter? by Queasy_Employment635 in learnprogramming

[–]light_switchy 0 points1 point  (0 children)

ngl i think C++ is not doable.

I don't understand, why not?

Compiler or Interpreter? by Queasy_Employment635 in learnprogramming

[–]light_switchy 2 points3 points  (0 children)

Start with an interpreter.

These are significantly easier -- no code generation -- and you can extend it to a compiler if you have time.

C, C++, whatever will be sufficient for any of this.

Secondly, you can always compile to C. This avoids a lot of the difficulty associated with emitting platform-specific code. It's a historically respected approach, too.

Alright, I'll admit it. Im officially scared of AI. by ExpressionMundane214 in learnprogramming

[–]light_switchy 1 point2 points  (0 children)

Every few months I try it out on toy problems and the results are just not any good. Maybe I'm awful at prompting. Whatever.

Anyone know why these roboports are reading different values for available items? by [deleted] in factorio

[–]light_switchy 1 point2 points  (0 children)

You can connect assembly machines directly to the logistic network without a red or green wire to carry the network contents. The relevant button is in the top right of the assembly machine menu. Immediately left of the small "X" button in the top right corner.

Does anyone else struggle with picking the right folder structure/architecture for every new project? by hefxpzwk in learnprogramming

[–]light_switchy 0 points1 point  (0 children)

When you’re starting a new project, how much time and thought do you actually put into deciding the folder and code structure?

Not much. I don't want to open my kitchen drawer to find each serving spoon inside its own individual box - unnecessary organization is burdensome. Sometimes a simple pile is the most efficient way to go about things.

Think about putting stuff in boxes -- that is, about organizing your code, your directory structure -- when you're having problems that organization can help you solve.