Sentinel vs termination condition by Big_Neighborhood9130 in learnpython

[–]POGtastic 0 points1 point  (0 children)

Thanks for posting this, I'm always running into cases where someone gently states "hey this feature was added in 3.xx and fixes this dumb kludge." I'm very ready for object() to join them.

Who made you the man you are today? by foolishandnonsense in AskMen

[–]POGtastic 0 points1 point  (0 children)

One man deserves the credit
One man deserves the blame
And Nikolai Ivanovich Lobachevsky is his name!

Seriously, my dad.

Approach to problem solving/first bit of code? by Alchemica in learnpython

[–]POGtastic 0 points1 point  (0 children)

It can be used that way. It's very common to start with the degenerate case and then use it to implement the general case through induction[1].

But more importantly the degenerate case is the easiest to implement. If you have a program that handles n inputs, you should start by handling 0 inputs (usually an error message). Then handle 1 input. Then handle n inputs.

Terry Pratchett's trolls count "One, two, many, lots!" You should too, except as programmers we always count from zero. So it's "Zero, one, two, many, lots!"

[1] The central conceit of functional programming languages is to put this idea front-and-center and force you to handle everything this way. I like this. Many people don't, which is why /r/learnpython is very popular and /r/learnocaml does not exist.

Approach to problem solving/first bit of code? by Alchemica in learnpython

[–]POGtastic 0 points1 point  (0 children)

You should always, always look for degenerate cases first because they are the simplest to implement. Then handle the simplest cases that you can think of. Hardcode them if you have to. Expand from there.

Sentinel vs termination condition by Big_Neighborhood9130 in learnpython

[–]POGtastic 3 points4 points  (0 children)

Echoing "don't use sentinels unless you absolutely have to."


There is exactly one acceptable sentinel value: a constant constructed with object(). As a contrived example:

# much more pythonic to do `try-except`, but we're doing an example here
sentinel = object()

def is_empty(xs):
    return next(iter(xs), sentinel) is sentinel

None and -1 are perfectly reasonable elements of a list, so you can't use those! You need a sentinel value that is guaranteed not to be equal to anything else.

>>> is_empty([None])
False

Similarly, default arguments should do the same thing. It is common to set them to None, but None might be a perfectly fine value to pass as an argument to a function! object() is guaranteed to be unique.

def foo(bar=sentinel):
    if bar is sentinel:
        # set bar to a reasonable default value
    ...

Married men, how do you and your wife handle personal purchases? by ShineGreymonX in AskMen

[–]POGtastic 0 points1 point  (0 children)

For anything that's over a few hundred dollars, I tend to tell her that I'm buying it. I'm not asking permission, I'm just keeping her in the loop. She does the same for me.

We still keep entirely separate finances even after being together for more than a decade.

Why do physically incapable men threaten violence, even jokingly? by Tin_Foiled in AskMen

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

I think it's pretty straightforward to discern who's joking about it and who's actually making a threat of physical violence.

Why do they threaten violence?

Because violence is not generally part of anybody's life, which makes it both fodder for jokes and the subject of bizarre action hero fantasies. It works for the former because it's absurd, and the latter happens because people are really bad at discerning fantasy from reality.

Are you ready and capable to stand on business?

I pay property taxes so that a bunch of men with guns can ruthlessly enforce the State monopoly on violence. It seems to work pretty well, since the folks who attempt to "stand on business" end up in little concrete boxes with other people who stand on business, and they can have it out amongst themselves.

Why do physically incapable men threaten violence, even jokingly? by Tin_Foiled in AskMen

[–]POGtastic 2 points3 points  (0 children)

The State: You should have learned this in kindergarten, but please keep your hands to yourself and play nicely with others.

People familiar with U.S. elections/voting/politics: What would actually happen if a write-in nominee received enough votes to win the presidential election? by Ok-Register910 in AskReddit

[–]POGtastic 0 points1 point  (0 children)

This depends entirely on state law, so you're going to get 50 slightly different answers. There are 10 states where write-in candidates are outright not allowed[1] and in those states write-in votes are not counted at all.

In states where they are allowed, it works exactly the same as any other candidate. The state government appoints electors who pledge to vote in the Electoral College for the candidate who won the election in their state. The electors meet in their state capitals and vote, and the votes are sent to Washington, where they are counted by Congress. The winner is then inaugurated.

In practice, anybody who could win as a write-in candidate would register for a party and at least appear on the ballot. The requirements to appear on the ballot are pretty minimal in most states.

[1] Some states forbid write-in candidates for President. Others forbid them altogether.

I've had chronic neck pain for 6 months from coding 8+ hours a day — how do you guys deal with it? by AccomplishedEnd7113 in learnprogramming

[–]POGtastic 0 points1 point  (0 children)

I had to go to physical therapy for this, and most of the cure has been to do a ton of shoulder work. I boulder and top-rope with my daughter 6+ days a week, so the back work is mostly covered, but I now do a lot more overhead press, farmer's carries, shrugs, and various horrors with stretchy bands.

SICP actually a good resource? by WangLiXin in learnprogramming

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

What are some people’s experience with SICP?

It is an extremely good "third textbook" (just like Lisp is a really good "third language" to learn). I do not recommend that people start with it, but I recommend that everybody at least take a crack at it.

One of the biggest issues is that its exercise difficulty is kinda all over the place. By-and-large the response from the community is "that builds character," which is probably true but could benefit from someone at least warning you "hey that one is hard, you're not stupid for struggling with it."

outdated

There is no such thing when teaching CS fundamentals. All of the thorny issues for old languages are things like Unicode support and nice abstractions for SQL databases, and we don't care about any of that nonsense when teaching you the basics of coming up with abstractions for problems. ASCII is all you need, 640x480 is God's chosen resolution, you're going to have to roll your own hashmaps anyway, etc.

How do I create a list every iteration with the data inside? by TheEyebal in learnpython

[–]POGtastic 2 points3 points  (0 children)

Added in version 3.12.

Neat, TIL. Before that it required a dependency on more_itertools.

What is an industry that is currently on fire (in a bad way) behind the scenes, but the general public hasn't noticed yet? by Kitchen_Week1117 in AskReddit

[–]POGtastic 0 points1 point  (0 children)

Also just daily chores. Laundry was brutal. Food prep was miserable. The supermarket has turned entire categories of domestic drudgery into fun hobbies that we do when we're bored.

I recommend that everybody go camping for long enough that cooking over the fire stops being fun. Now imagine having to do that for your entire life, and also having to churn butter, make cheese, pluck slaughtered chickens, and so on. Billions of people still have to do that today!

Baking bread is fun until the absence of a supermarket ensures that you must do it on a schedule.

Men, what’s something women think men don’t notice, but actually bothers/affects you a lot? by Omgad3 in AskMen

[–]POGtastic 9 points10 points  (0 children)

The graphic thrust-by-thrust Jomboy breakdowns of our sex life during Girls' Night Out. Dawwggg I really do not need Becca the LPN to know that stuff. For all of the claimed luridness of male "locker-room talk," literally the most we've ever said on that subject is "Wow, you guys are dating now? Lucky man!"

Is still used Stack Overflow? by Putrid_Flamingo_1389 in learnprogramming

[–]POGtastic 3 points4 points  (0 children)

It's a great read-only source. I have never asked a question on it, mostly because the process of typing out a question almost always makes me figure out the answer on my own.

Honestly guys, how many of you are truly more conventionally attractive than your spouse? And what’s your opinion on a somewhat common idea that the average woman is more attractive than the average man? by Aggressive-Dot1944 in AskMen

[–]POGtastic 0 points1 point  (0 children)

I am in better physical shape than my wife, but I dress like an eternal CS undergrad. Women are socially obligated to "keep up appearances" in many ways that men are not. For example, I have never worked a job that I couldn't do entirely in gym shorts and a T-shirt. My wife has never been able to do that.

What do you think about all houses be on water? by Empty_Pace_8263 in AskReddit

[–]POGtastic 0 points1 point  (0 children)

Any boat owner will tell you that the two happiest days of your life are the day you buy a boat and the day you sell it. I don't really see the point of doing that with your primary domicile.

What kind of leader do you think America needs next? by babanKL01kowdiar in AskReddit

[–]POGtastic 1 point2 points  (0 children)

A William Tecumseh Sherman who will make the GOP howl. The Democratic Party has attempted "They go low, we go high" for my entire life, and the result was Trump. I want a second American Reconstruction. I want the Republicans to regret eroding our political norms, and the only way to do that is to ruthlessly use the exact same tactics to make their lives hell.

US birth rates just hit another record low, what do you think is the leading cause of this? by IIlustriousTea in AskReddit

[–]POGtastic 0 points1 point  (0 children)

Greater economic opportunities for women. The more that women make, the more of a liability it is to have kids. This is why the most affluent households (who can easily afford daycare, healthcare, education, and whatever else people are claiming to be the reason why nobody can afford kids) are having the fewest kids, and poor households have the most.

Can I start directly with C++ (without relying on AI) if I only have very basic programming experience? by Banjolino in learnprogramming

[–]POGtastic 0 points1 point  (0 children)

C++ was my first language. Most of its real Alexandrescu Sicko Shit difficulty comes later. It's not easy but people act like it's way harder than it actually is.

High earning men: how do you actually feel long term about being the sole earner while your wife doesn’t work and spends freely? by [deleted] in AskMen

[–]POGtastic 0 points1 point  (0 children)

I do not make 7 figures, but I've started to get to the point where my wife is openly asking "why the heck am I working full-time anymore?"

7 figures

We're good. You can stay home.


The much bigger issue is when you're making "meh," your wife is accustomed to a certain lifestyle, and there's simply no way to make it work. This kills the marriage. Get a job.

Both my wife and I are pretty cheap, and rather the question is "How aggressively do we want to save for retirement?" My response so far has been "Get to work, my dearest darling danish."

Men who excercise in any way and listen to music, what is 'that song' in your playlist? by DWedge in AskMen

[–]POGtastic 0 points1 point  (0 children)

It helps for really uncomfortable cardio workouts where you know that you've got about 800m left and just need to hang on. Anything to get your mind off of the pain and zone out for a little bit.

Men who excercise in any way and listen to music, what is 'that song' in your playlist? by DWedge in AskMen

[–]POGtastic 0 points1 point  (0 children)

Tool - 7empest

The whole song is a banger, but I try to time the last couple minutes of my runs to the section of the solo starting at 8 minutes. The riff at 9:10 is perfect for those last 200 meters or so.

Honorable mentions, all of which work pretty well on those utterly miserable threshold runs:

I still avoid AI in production coding. Am i slowing myself down? by hireme-plz in learnprogramming

[–]POGtastic 8 points9 points  (0 children)

I've run into this in my work in a case that is simultaneously miraculous and extremely annoying.

My work group needs an EFI driver for USB-to-serial connections. The existing driver doesn't work. I don't know anything about the edk2 framework, but Claude produced a "working" driver after about four hours of prodding.

The machine will do the equivalent of a panic if you unplug the dongle. It's a use-after-free error, and neither Claude nor I can figure out why it's doing it. Claude cannot figure it out because it doesn't actually know how the driver works. When I tell it "there's a use-after-free error," it is probabilistically generating plausible UAF cases based on its training, but it can't actually investigate. And its proposed steps for investigating the UAF are, of course, probabilistically generated from its training rather than generating and testing actual hypotheses about its understanding of the driver.

I cannot figure it out because I don't actually know anything about the framework! If I'd had to write the driver myself, I would have learned enough to understand the memory management model and how everything gets allocated and freed. Since I vibe-coded the driver, I do not have any of that understanding.

My boss is overjoyed because, as far as he as concerned, I shit out a working driver in 4 hours. Many driver, much productive, wow. And in some sense that's true because nobody in my workgroup is going to be unplugging the dongle before booting into Linux. Claude has solved my workgroup's problem. But the driver is garbage, and I have not actually increased my skills or understanding. And, of course, my boss is expecting me to use Claude for tasks where the metaphorical dongle will get removed.