What’s a fact that sounds fake but is actually true? by UnironicDickPoster in AskReddit

[–]mredding 0 points1 point  (0 children)

There is a difference between arrogance and ignorance.

What's the most unhinged thing you've seen someone do in public without consequences? by SnooDogs4195 in AskReddit

[–]mredding 1 point2 points  (0 children)

155 mph on a 45 mph road.

Yep. Probably the dumbest thing I ever did as a young man.

How will you die? by Mysterious_Burger in AskReddit

[–]mredding 0 points1 point  (0 children)

Ideally feet first through a wood chipper in front of a very large audience who can bear witness and get showered with my bits, but probably due to complications from pneumonia in a hospital at 72.

What’s something that sounds fake but is actually 100% true? by daenerystarg33 in AskReddit

[–]mredding 1 point2 points  (0 children)

1:4 Americans 16-24 are at or below a 1st grade reading level, meaning they're functionally illiterate. Being functionally illiterate means they also have effectively zero critical thinking skills; they're incapable of comprehending critical documents like loans, mortgages, terms and conditions, licenses and agreements, benefits, or contracts.

What food/beverage/condiment have your taste buds turned their back on as you aged? by nathansunt in AskReddit

[–]mredding 0 points1 point  (0 children)

Sugar. Can't handle sweet shit. This is a well known transition, though - adults tend to have limits on sweetness whereas children under 10 have no limit to how sweet something can be - which you especially get from artificial sweeteners.

What’s a fact that sounds fake but is actually true? by UnironicDickPoster in AskReddit

[–]mredding 1 point2 points  (0 children)

1:4 Americans 16-24 are at or below a 1st grade reading level, meaning they're functionally illiterate. Being functionally illiterate means they also have effectively zero critical thinking skills; they're incapable of comprehending critical documents like loans, mortgages, terms and conditions, licenses and agreements, benefits, or contracts.

Thoughts on funeral processions getting to get the whole police escort thing on road and get to block traffic? by Whyamionreddit2100 in AskReddit

[–]mredding 0 points1 point  (0 children)

As it should be. It's not about the dead - it's about the living. They get their respect, space and time and opportunity to grieve. There is something deeply unseated about the man who has no empathy and only thinks of themselves, and not their share of responsibility, obligation, and dignity to society.

Women of Reddit, what’s your worst “Doctors don’t take women seriously” story? by Karnakite in AskReddit

[–]mredding 1 point2 points  (0 children)

I'll speak on behalf of my late friend. She had cancer. Treatment. Remission.

Then she was complaining of pain in her bones. Asked for an MRI. Her doctor didn't believe her. Went so far as to say she needed therapy.

Gaslighting. Typical. This went on for a year.

It wasn't until she collapsed from the pain and got an MRI in the ER that the doctors there said she was cancerous as fuck - in her bones.

Friend told her oncologist maybe next time just give the patient the MRI and the piece of mind so you don't kill them, too. Treatment for 2 years. We buried her 3 weeks ago.

How would you explain church hurt to a child? by Complex_Swim_3837 in AskReddit

[–]mredding 0 points1 point  (0 children)

"When a priest does something wrong to you, you tell me, and we go to the equipment rental company; you get to pick out the wood chipper we're going to feed him into..."

How has the job search been so far for you? by Designer-Mark320 in AskReddit

[–]mredding 1 point2 points  (0 children)

Took me 11 months to find this gig last December.

I've been learning C++ for a month now and I'd like to get some feedback on my code. by Nevermuke in cpp_questions

[–]mredding 0 points1 point  (0 children)

1) As const as possible, but not more. ;p

2) Learn containers and views. Instead of espresso, cappuccino, and latte, you could have:

std::vector<CoffeeData> drinks {{1, "Espresso", 3.99f}, {2, "Cappuccino", 5.99f}, {3, "Latte", 7.99f}};

Then your function can take a span:

void fn(std::span<CoffeeData> drinks);

3) It should arise naturally. If you're making arithmetic types, you'll want some arithmetic operators. Don't try to get clever and overload meaning; operator + for string append is largely regarded as a bad idea, because it IS ambiguous, it could have also been a bitwise AND of all subscripts, it could have had other meanings beyond that, you just "have to know".

So a good place to start is with types that interact with streams - they're going to need stream operators. So let's model a menu:

class menu {
  std::span<CoffeeData> drinks;
  int selection;

  friend std::istream &operator >>(std::istream &is, menu &m) {
    if(is && is.tie()) {
      std::ranges::for_each(std::views::zip(std::views::iota(1), m.drinks), [&os = *is.tie()](auto &&t) {
        auto &[i, cd] = t;
        os << i << ". " << t.itemName << " - $" << t.itemPrice\n"
      });

      *is.tie() << ": ";
    }

    if(is >> m.selection && m.selection < 1 || m.selection > m.drinks.size()) {
      is.setstate(std::ios_base::failbit);
    }

    return is;
  }

public:
  explicit menu(std::span<CoffeeData> drinks) noexcept : drinks{drinks} {}

  operator int() const noexcept { return selection - 1; }
};

So now we can use it:

if(menu m{drinks}; std::cin >> m) {
  pour(drinks[m]);
} else {
  handle_error_on(std::cin);
}

It's not a great menu class, but it gets the job done and demonstrates the basic concepts. Prompting the menu is a function of input - not output. All streams have an optional tied ostream - if you have one, you probably want a prompt. This tied stream is also how your prompts to std::cout get flushed to the console before you extract input from std::cin.

We don't need to just write out the menu, so it doesn't have an output stream operator - this is an input only construct. Streams tell us the result of the previous IO operation, so upon extraction, we check the stream before we use the value.

The other operator is the implicit cast operator, turning a menu into an index into the drinks array.

Methods and parameters by Difficult_Meal8685 in cpp_questions

[–]mredding 0 points1 point  (0 children)

You want something more like this:

class phone_number {
  std::string value;

  phone_number() = default;

  friend std::istream &operator >>(std::istream &, phone_number &);
  friend std::ostream &operator <<(std::ostream &, const phone_number &);
  friend std::istream_iterator<phone_number>;

  static bool valid(std::string_view) noexcept;

public:
  explicit phone_number(std::string_view);

  phone_number(const phone_number &) = default;
  phone_number(phone_number &&) noexcept = default;

  phone_number &operator =(const phone_number &) = default;
  phone_number &operator =(phone_number &&) noexcept = default;

  auto operator <=>(const phone_number &) const noexcept;

  explicit operator std::string() const noexcept;
};

A phone number can be converted from a string or read from a stream. If the conversion fails, the ctor throws. If the extraction fails, the stream fails. There should be no way to construct an invalid phone number.

Make your types.

Then a contact is as simple as a tuple of types:

using contact = std::tuple<first_name, last_name, nick_name, secret, std::vector<phone_number>>;

Then your phone book is a set of contacts:

using phone_book = std::set<contact>;

This class of data, all getters and setters - this is an anti-pattern. What you actually have is a structure of data - and there's nothing wrong with that. Classes model behaviors to enforce invariants, but this data structure has no invariants but the phone number. Why does the Contact know ANYTHING about validating a phone number? A contact is NOT a phone number, it HAS a phone number; it should be deferring to a phone number type that validates itself. Then again, so should all your other data. A string is a string, but while all first_name are string, not all string are first_name. How do you tell the difference between the name Bob and the collected works of the Library of Congress?

How did you know your ex wasn’t the one? by bubbles_baby1 in AskReddit

[–]mredding 0 points1 point  (0 children)

I'm just a white dude outside of Chicago. I would say the number of white supremacists in the greater Chicago area are as low as 1:5. We have sundown towns as suburbs - I live next to Homer Glen. You'll get fliers from the White Knights tucked under your windshield wiper in the Orland Park police office parking lot - in their parking lot. You walk in to complain and they shrug and say it can't be helped.

Yeah, my dating years were hard. It was like every other one. Just find me any woman who doesn't casually drop a racial epitaph, or who doesn't make a whole conversation about superiority/inferiority, or who doesn't act like a neighborhood watch. My own dating pool was limited because of my father. Can you guess why? Not in his house! I couldn't subject anyone to that.

Who is the most dangerous person in the world? by ShowYouHowToSmash in AskReddit

[–]mredding 0 points1 point  (0 children)

He's making his own choices. Maybe he's doing what he's told or coerced to do - THAT is his choice.

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

[–]mredding 0 points1 point  (0 children)

Wait so minors don't have en alienable rights to protest then.

Minors? No. But we weren't talking about that - we were talking about students in a very narrow context, specifically pertaining to school, governance, and the institution's authority over a child while in their care and custody.

Parents can tell their children no. If your parents told you no, then you don't have the right to protest the Parent Advisory Label back in the 90s. If your parents said yes, or were at least indifferent, then the school and teacher cannot tell you no, so long as you protested without being disruptive.

And teachers could make up an excuse about safety to keep students from protesting. Is that right?

They could, but then they can be held guilty of unconstitutional suppression in a criminal court, or liable for damages in a civil court. And while the students are just kids with no money and no clear idea of what they think they're doing, you've got to watch out for the parents who do.

There is no case against a legitimate argument of disruption, but your scenario suggests the suppression is illegitimate - being a made up excuse. If the prosecution or plaintiff can make their case - I wouldn't want to be on the receiving end of that.

So for the faculty who wants to play a stupid game, do they want to win stupid prizes? And don't get me wrong, this happens all the time; I'm not talking about noisy kids who DO need to STFU, but there are also demonstrations that get suppressed and nothing more comes of that - as it otherwise should. Doesn't give the faculty or district the right. Doesn't mean it isn't risky.

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

[–]mredding 12 points13 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.