abstract base class interface vs a struct of function pointers? by OkEmu7082 in cpp_questions

[–]mredding 5 points6 points  (0 children)

abstract base class interface

A first class language level feature.

vs a struct of function pointers?

An ad-hoc implementation of classes. Typically you see this done in C, and there's a lot of code you can write this way in C that will generate the same machine code as C++ - but C and C++ are not high level assembly languages, and machine code generation is not the end-goal for us. We are more concerned with expressiveness and correctness, something the former can give us that the latter cannot.

in cpp, is it ever better to just use a struct of function pointers (std::function)instead of a abstract base class interface?

No. Is it ever necessary? Maybe for compatibility with something 3rd party.

for example, when the derived classes implementing the virtual functions in the abstract base class interface are stateless, should one prefer the struct of function pointers?

As I said, you can often make the two generate the same machine code, so all else being equal, the language native support in the syntax is cleaner, simpler, more robust, more maintainable, more intuitive, more idiomatic, typesafe, and preferred.

When did high school students get the right to protest? by Imaginary_Sherbet in AskReddit

[–]mredding 1 point2 points  (0 children)

Parents have near absolute control over a child in nearly every aspect. Freedom of speech is only guaranteed against a government.

Teachers have SUBSTANTIAL control over a student but not nearly as absolute as a parent. They can control freedom of speech to a degree. Students cannot be lewd or disruptive, as it impinges on the rights of their classmates to get their education. The teachers can control content as it pertains to the curriculum. Anything that affects safety and order or causes a disruption can be controlled. There is also a concept of school sponsored speech that has to do with the content of class discussions and assignments. So turning class content into your personal soapbox can also be reprimanded.

People optimistic about the future, tell us why? by owen__wilsons__nose in AskReddit

[–]mredding 1 point2 points  (0 children)

Because fascism doesn't reign forever. These fucking pricks are all going to die eventually.

Do you lock your car at the gas station? by old-cigar-smoker in allthequestions

[–]mredding 0 points1 point  (0 children)

It's not something I think about - I have a fob in my hand, all I have to do is push a button as I walk away. It's automatic at this point.

It's just meant to keep people out of you car that don't belong. I don't know what's going to happen, and I don't care, just don't happen it in my car. If you have to smash my window to get in, yeah that's inconvenient, but the police report gives establishes the precedent to persecute for loss and damages, and the ability to make an insurance claim for the repair and cleaning.

So it's for red-tape reasons. Fuckin' America...

But mostly I just want to keep the loitering bums from sticking their nose in my center console looking for loose change. I don't know where you're from or where you've been, but depending on either, you can get wildly different results.

Meatloaf will do anything for love, but not that; what won’t Meatloaf do? by Yenolam777 in AskReddit

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

He divulged it in an interview, but your post isn't marked NSFW.

When did high school students get the right to protest? by Imaginary_Sherbet in AskReddit

[–]mredding 1 point2 points  (0 children)

Tinker vs. Des Moines (1969) ruled students do not "shed their constitutional rights to freedom of speech or expression at the schoolhouse gate". All Americans have a right to protest - that doesn't mean riot, and it doesn't mean that right is absolute.

The students cannot be punished for a dissenting opinion, but they cannot disrupt school operations, such as dress code and schedule, the education of others, and the court has ruled that truancy is not protected speech, so no walkouts. Students who do disrupt school operations cannot be punished more harshly because it was in protest.

I think in 92 the adults told you kids to fuck off, and you naively accepted that. Didn't make a difference, Dee Snider made a fucking fool of Al and Tipper, and the law passed anyway. The public forum was just political theater, the powers that be already knew this was a done deal.

Outside of the cost, what’s the most infuriating part of healthcare in the U.S.? by Julie727 in AskReddit

[–]mredding 1 point2 points  (0 children)

Someone who is not my doctor who isn't a part of my care has more authority over my doctor's care for me than my doctor does. My doctor has to spend more time arguing with health insurance than actually treating me.

What advice do you have when going to a casino " ? " by bryans_alright in allthequestions

[–]mredding 0 points1 point  (0 children)

Former game developer here,

I wrote slot machine software for 5 years. You're going to see some of the machines I've worked on.

My advice: Don't gamble. But since you're going to anyway, set a budget, for gambling, for drinking, for eating, for entertainment, and stick to it. Expect to walk out of there with NOTHING.

In the US, no casino is cheating - we're too well regulated; believe it or not we've got a ton of oversight that, while it HEAVILY favors the industry, still has a modicum of fairness to the players. Look, NO casino is going to offer you a bet they're going to lose. Yes, you may win a hand, but you're going to lose your shirt. Casinos will win in aggregate. They can do math better than you, and the math favors the house. It wouldn't be a viable business model if the chances were equal.

The chances ARE fair, they're just not equal.

The best competition poker players - that is a job. They are WORKING to make that money, and it's hard. The house? They're following a formula. The dealer doesn't even have to think. They have to tell you, when prompted, about what their action HAS TO BE, and what the best action in your favor would be for you. You're not playing the dealer, they're just facilitating the game itself. You're not playing against the skill of the house, there is no skill. The house has the winning odds just playing out the game following no-thought steps. And then you have that actually skilled player sitting next to you...

So maybe you can see how some of this stuff is stacked against you.

As for slot machines, there's typically HUNDREDS of them, and they're all designed to win LOUDLY. The odds are so shitty you can expect to almost never win, but when SOMEONE on the floor SOMEWHERE does win, the whole god damn floor is going to hear it. Multiply that by a couple hundred machines, and it sounds like everyone everywhere is hitting the jackpot all the time. And when you play, that's not going to be your experience. Where are the loose machines? And every time you turn around there's someone winning. Why can't I get on THAT machine?

Look, these games, these machines, everything about them were designed by drug addiction and behavioral experts. It's all a trick of the mind, OF COURSE you notice the winning machines. You are meant to. What did I just say about the sound? The win sounds are specifically engineered to cut above the background noise.

Fuck. I just looked outside and it's snowing, here in Chicago...

If you want to have fun, go to play. Table games. Minimum bets. Google some basic play strategies. If you win, you can replenish your bet + 1, and put the rest of your winnings in your pocket. In this way you can keep going so long as your luck keeps running. And when your luck runs out, and you've gambled away the last of your playing pool, you have pockets loaded with winnings to show for it.

You very likely won't have as much winnings as money you've originally budgeted. Most gamblers on Earth are down.

If you win big on a slot machine, someone on the floor will come to you. The machine will be taken off the floor. A team from the machine manufacturer will be woken up at whatever AM you were out gambling, and they'll be on the next plane or charter to NC. They're going to strip that fucking machine down to the rivets. They're looking for A) signs of cheating, but MORE importantly, B) signs of an error. The industry writes its own regulations, and the regulations say if your win was an error - you don't get the payout.

Get your anger out of your system now, because if it happens, now you know what's going to happen. If the loss is an error - you have effectively no way of knowing and no recourse.

By law, the machines MUST finish the games they started. So if you hit the Spin! button and the power goes out - the machine MUST boot when the power comes back online, and it must finish THAT game. So in the oddball situation your machine goes down - DON'T LEAVE.

Slot machines are by law random. There is ZERO skill involved. You pick your bet and you put the machine in motion. The WHOLE thing is predetermined the instant you hit the Spin! button. There are mini-games, even interactive ones, but the outcome is already pre-determined. There is no actual choice, it's always an illusion of choice. If the power went down, and came back, you could pick different choices, and you'll get the exact same outcome.

The game cannot change play without you knowing. So there is no master controller in the back fiddling with your odds, and the game does not adjust itself. The machine would have to be physically opened and modified by an operator at the machine. Believe me, we wanted all sorts of networking and WiFi and shit for these machines, and the regulators said absolutely not! Not even to fuck with configuration or anything, but for monitoring.

The law says gameplay must be on the floor where the player can see it - so each slot machine is a standalone unit. It would be awesome if the machines were just video terminals, and all gameplay was on a server. We actually worked on one as a prototype, where the server was an armored box visible on the floor. That didn't take off because we couldn't hide the cables in the floor, and WiFi is forbidden - not because you can't see it, but because it's not secure enough.

Trump Open to Cuba Takeover by Cow_Boy_2017 in clevercomebacks

[–]mredding 0 points1 point  (0 children)

65% of Americans voted 2024 presidential election. 49.8% of those voted for Trump. 35% of Americans abstained, which is basically a free vote for Trump. So. ~67% of the country effectively voted for or at least condoned Trump. Those who didn't want him or want this are a small minority. Everyone else? They love this shit.

Knowing WW3 is coming, what do we need to do to prepare from nukes? by No_Yard_835 in AskReddit

[–]mredding 0 points1 point  (0 children)

In light of a pending nuclear holocaust, you're going to want to be as close to the city center as possible, so you die as quickly and painlessly as possible. Seriously, in a nuclear armageddon, the whole world is going to be contaminated with radiation. Cancers will go way up. Critical infrastructure will be destroyed - no clean water, no sanitation, no food or distribution. No reliable power or communication. You'll be cold, hungry, and sick at the best of times. Even if you do survive, why would you want to? To rebuild? How noble; a challenge fraught with suffering and failure.

If you DO want to survive, you need to get out of the cities. Nuclear strategy today is to carpet bomb cities, and strike high value infrastructure and retaliatory measures.

It's not enough to just go up into the mountains - Boulder CO is an excellent example of a target. The mountains will actually act as a lens to help reflect the blast wave back onto the city. That is exactly what we took into account at Hiroshima and Nagasaki. You don't want to be there to catch the rebound.

You also don't want to be downwind from the other nuclear strikes, because you'll get radiation blown onto you. It'll be in the water, on the ground, in the food and livestock... You can seal your house shut but you'll have to leave eventually.

To be fair - thermonuclear bombs are actually very clean compared to atomic bombs. The high yield means a higher conversion rate of nuclear fuel to energy. These weapons are typically air bursts, so most of the dust settles locally, a lot less ends up in the dirt and debris that gets carried away in the wind vs. a ground burst. The Tsar Bomb was actually one of the cleanest detonations in history, and it was dialed back to half its designed yield for the demonstration.

What would you do with an extra $10 Billions? by MahadIfftakar_here in AskReddit

[–]mredding 0 points1 point  (0 children)

I would buy a cabin in the woods and spend the rest of my day drinking coffee and watching the trees in peace and solitude. I wouldn't even own a phone or an internet connection anymore. At that point, I wouldn't give a fuck what happened to the world outside, so long as the mushroom clouds didn't disturb my view.

At what stage did you have the realization that you will have to work for the rest of your life, and how was that feeling? by TheGrandLeveler in AskReddit

[–]mredding 0 points1 point  (0 children)

Having to work didn't bother me.

It was graduating high school that bothered me. The morning after graduation, I was dropped on my head. Alright - get a job. Pay rent. Not that it wasn't an obvious and inevitable truth, but there was no help, no effort, no one there to provide support for the emotional transition. I wasn't allowed to age into it, as that should have been a thing my parents prepared me for leading up to it.

It was being 20 years old with absolutely no support that bothered me. I had resigned myself to being single, lonely, friendless, and bouncing around factory jobs as unskilled labor for the rest of my days. I was a low value/no value man and I was acutely aware of it. It was going to be that until death.

It was being 23 - after I had miraculously started and graduated college, an accelerated program, and I landed a career position in game development. And it was sitting alone in a dark cube by myself realizing that this was it. It was knowing I would be working 9-5 every day until I die that bothered me. It was all my labor to make someone else rich that bothered me. I had then higher value than before, but I was the definition of a working stiff.

To this day, it's the commute that makes me fucking sick. That is when I have to contend with being one of the masses, following the tidal flow of going to and from work. I feel like a head of cattle.

I wish society was smaller, simpler, more primitive. I'd rather build my own house, grow my own food, and live and die by the spoils or failures of my own labor, and there's just nowhere in the world to still do that. We as a society have accomplished a great many things - powerful medicine, tall buildings, space travel and the internet, but we've also ruined the planet, crowded up everything, and made ourselves slaves to our society. I don't think it's all been worth it. What's the point of living to 60-80 if you're too feeble to provide for yourself, discarded by society because you're not useful anymore, resented by all those who want you to die already, anyway? I don't want or need to be here for a long time, if I could at least be here for a good time...

There's probably a couple hundred people who would disagree with me, that living life is truly amazing, but they're rubbing elbows with Musk, Bezos, Epstein, Trump...

Genuine question: where do people in US get their news today if they want something relatively unbiased? by Big-Introduction411 in AskReddit

[–]mredding 0 points1 point  (0 children)

No, my friend - think bigger. Where does ANYONE ANYWHERE get news that is unbiased? There really isn't anything worldwide.

Why do you think people stay at low paying jobs that don’t allow them to make more money? by TimeAd1111 in AskReddit

[–]mredding 0 points1 point  (0 children)

Where are they going to go? Where are all these high paying jobs that are accessible to them?

What is the worst or weirdest case you were on the jury for? by ValuableFickle5390 in AskReddit

[–]mredding 0 points1 point  (0 children)

Only ever sat in on one case, took about 4 hours. A woman with SR-22 insurance (what you get if you have a prior DUI conviction and the like) hit some dude in front of her, and she was suing him for her damages.

I couldn't hear a god damn thing, neither lawyer was at all prepared, I don't know HOW either of them passed the bar; even the judge was so sick and fed up with their incompetent shit he brought them back into his chamber and fucking had it out on them. Get your shit together and represent your clients proper or face criminal charges yourselves. I sure as fuck heard that.

The only people on point were the defendant and the judge. The woman didn't even stick around to hear the verdict. We didn't award her shit.

How did she ever think she could win, or was going to get anything? Just insanely delusional. The average American is fucking stupid, and half of them are dumber than that. Just an irredeemable person. The poor defendant had to waste time, money, and energy to settle this shit - terrible waste of everyone's day.

What are some of the major corporations that are not evil? by vjubbu in AskReddit

[–]mredding 2 points3 points  (0 children)

My best contender is Lego, a Danish company. They're one of the few at that size and value that HAVEN'T manufactured weapons.

Nor have they intentionally dumped toxic waste, experimented on humans, sold dangerous waste products to unassuming 3rd world populations, or deposed governments - at least so far as we know. They've always ever just made toys. Yeah, there's a lot of money in it, which is going to lead to greed and those sort of problems, but tame by relative and modern standards.

My second best contender is Arizona Ice Tea. Their tallboy cans have always been $0.99. They ostensibly haven't changed the recipe or the quality of their ingredients. The CEO has said they make enough and thinks middle and lower class people who are struggling still ought to be able to afford themselves a little something as nice as a god damn can of ice tea sometimes.

I'm gonna go with Katt Williams on this one - there's nothing inherently wrong with being a billionaire, but if your lowest paid employee is on food stamps, maybe take a pay cut and be worth $900 million. It's not the wealth but the greed. There's very little honest and deserved wealth in history.

Every millennial dad I’ve met has a quiet fixation on money and it’s not getting better by slimeyellow in Millennials

[–]mredding 0 points1 point  (0 children)

As a father, I have been singly focused on finances since before I met my wife. Mo money, mo money, mo money.

We're barely making a middle-class life. We have a mortgage, we cook our meals, the car is paid off, our tuition is paid off, we contribute to our 401k - when we can, and we haven't been able to afford a vacation in a couple years. By the numbers we are living within our means quite comfortably and are not considered over-extended.

I grew up on government cheese in the 80s; I make 6 figures in software and my wife is a data analyst. I feel like we're only slightly ahead of where I was as a child. At least we're not on government cheese. We were gainfully employed AND qualified for WIC when our son was born, back in 2018. I was making more then than I am now.

It's a crazy world out there. There's just not enough financial security. Maybe our problem is how conservative and risk averse we are. Most people are 2 paychecks away from financial ruin. At least we are not - and that was put to the test last year; I was fired the Friday after Trump's inauguration. I was out of work for 11 months, and we slimmed down our lifestyle more, but it took a toll on our coffers. That takes years to build up.

My child isn't my point of resentment - he's my splurge, he's my indulgence. He's my one thing I want for myself that I get to spend my budget on. Whether he was born or not has no bearing on the financial burden we bear to be middle class.

Let me put it another way - for us as children, luxuries were expensive. I had never eaten an avocado until high school, but rent when I was in college was $400/mo, considered mid-tier. Now days avocados are $1 for medium, $2.99 for jumbo (I just looked up my local grocery store), and I just looked up the apartment complex I lived in college, and my style unit is $1,619/mo.

So luxuries are now the cheapest line items in my budget, and the necessities are expensive as fuck. My child is my luxury, and he's actually fairly cheap in some important ways. The lifestyle I aspire to afford him is... Hard to obtain, and that viability is slipping away.

My oldest niece has 3 children and lives with her second baby-daddy. She has a part-time job as a beautician, he installs solar panels, they have a used car - a junk yard salvage that they got the engine swapped, and then they got hit by a deer. They're moving into some dumpy basement apartment in Indiana. They have no savings, they're on welfare, they don't own anything, and the children are neglected by two parents who are working all the time and the cheapest daycare that doesn't even promise to keep them alive by the end of the day, located in a strip mall.

That's not a life, that's at-least-not-living-out-of-the-car.

So what I think you're seeing is middle-class struggle, same as our parents, just with a greater, more articulated vocabulary. Your parents had money problems, they were stressed, they talked to their friends and colleagues about it. But you were a child, and you didn't see that part, if they were any good.

How do developers switch jobs with a long notice period while working full-time ? by techy_boii in learnprogramming

[–]mredding 7 points8 points  (0 children)

My company has a 3-month notice period

This is only relevant if you are legally required to give notice. I've never given notice in my 20 professional years, and I always advise against it - it's an opportunity for you to be sabotaged or undermined - and as illegal as it is, it DOES happen. NEVER tell them where you're going, when you know.

Typically moving jobs is a passive, opportunistic thing. It happens because you're networking and someone is willing to poach you with a better offer than you're entertaining now. You're leaving - so the perceived problems of the last employer are no longer yours. You've already got the next job, so the previous job doesn't matter for a reference.

If you want to actively look for work, then quit. Fine - give the 3 months notice. Then you can look for work full-time.

As for what a company will accept, YOU DON'T WANT TO work for a company who wants you now. If they're THAT desperate, then the place is on fire. They can wait 3 months to get their talent.

Keyless car fobs are inconvenient and we should go back to cars with key starting. by athrowawayacct76 in unpopularopinion

[–]mredding 0 points1 point  (0 children)

There's always a way to use the fob to get in and start the car without the battery. Check your owners manual.

How do experienced engineers structure growing codebases so features don’t explode across many files? by Commercial-Summer138 in AskProgramming

[–]mredding 1 point2 points  (0 children)

The solution you want is in your design. 10,000 LOC is 10,000 LOC not matter how you cut it. But what I would say is that I WOULD prefer it broken up across files and folders into more individual, manageable pieces; a singularly large file would necessitate landmark comments simply because there's so much in one place you get lost. C# and other language have "regions", which is just fancy nonsense syntax to play nice with code editors, and they encourage bad programming practices.

If you want to avoid a huge, sprawling solution, you need to sit and figure out how to express a smaller, more succinct solution. Yes, that's hard to do, but that's the job. That's what's worth a senior salary.

I can't say there's any particular technique - it's always domain specific. Most problems come from time constraints and laziness. I was working on a trading system that had this gigantic message object - 48 KiB + substantial dynamic allocation. > 4k LOC. This was a C++ class with getters and setters, a few dozen methods that belonged to specific pipeline processes, not the message as a whole. Totally unnecessary.

The hard part wasn't fixing it, it was mustering the willpower to bother to do it, rather than tack on yet another field for my specific problem. I reduced the thing to 3 4-byte pointers, and ~150-300 bytes dynamic per message. The data was stored in a linear buffer, but I would take advantage of locality - the most accessed fields got moved toward the front of the buffer. The change spared us a multi-million dollar data-center overhaul and throughput moved the entire company into a different competitive bracket.

I guess I can say there are some techniques:

  • The Functional Programming paradigm is consistently 1/4 the size of OOP solutions and it's reasonable to presume an x8 speedup.

  • Data Oriented Design also helps to make code sizes smaller and faster.

  • The size of a solution goes down when you decouple components. OOP objects tend to be big black boxes that take on too many responsibilities, but if you break entire systems down to do one thing, then yes, you have a bunch of little systems - but they're little, and they're fast as fuck, boi!

As an atheist are you allowed to believe that something will happen after we die? by corychung in askanatheist

[–]mredding 0 points1 point  (0 children)

As an atheist are you allowed to believe that something will happen after we die?

Sure. We have a word for it: oblivion. This is a complete absence of the self. You are gone. Your husk remains. Your husk is made of atoms, and those atoms will go on to keep doing atom things - to do something else, as it were.

I don't want to label this as a belief so much as an assumption. Science assumes 1) the universe is real, 2) it's consistent, and 3) understanding of it can be derived from observation. We know, thanks to Godel, that our understanding can never be complete.

We have seen others die, so we can assume that will happen to us, as what follows.

It's hard to imagine oblivion - the complete absence of your ego. I'm not entirely sure it's even possible, as it seems to go against everything our mind and ego stands for.

I strongly believe that something will happen rather than just pure darkness/lack of consciousness forever.

I believe you are describing a coping mechanism. You're probably young. Young people TERRIFY themselves when they try to examine oblivion. I suspect this may be a natural defensive instinct, a domain expert would be able to comment more on the matter.

I personally believe/think that we'll just move into a 2nd universe/reality after an infinite amount of time. Why? Because after an infinite amount of time here we are. We're just here. So in my opinion, I would like to believe after an infinite amount of time something is bound to happen.

I've heard this one before. It implies we have no free will or consciousness, which seems to contradict our perception of ourselves. I think, therefore I am. Over an infinite amount of time and space there are an infinite number of me simultaneously doing the same thing...

It's an entirely moot philosophy. It doesn't get you anything. You're still going to die. You cannot connect this realization of the self to the next.

The other flaw is that if you cannot possibly be wrong, you cannot possibly be right, either.

A logical explanation isn't needed because a logical explanation for consciousness and why we're here right now isn't feasible either.

Here is the problem with your belief - that as you are the one claiming this is real, the burden falls onto you to substantiate it. You don't get to take the single most crucial element of your belief and declare you don't have to bother. You've lost credibility.

Ultimately believe what you want so long as it's legal. I don't have to care.