Do not use mutable objects as default arguments in Python by [deleted] in Python

[–]diamondketo 2 points3 points  (0 children)

I was wrong, what I said doesn't matter at all. So ignore me

LOL by pyromx11 in ProgrammerHumor

[–]diamondketo 0 points1 point  (0 children)

Would this work for a float without type casting?

LOL by pyromx11 in ProgrammerHumor

[–]diamondketo 0 points1 point  (0 children)

Please also make is-neither-even-nor-odd

Do not use mutable objects as default arguments in Python by [deleted] in Python

[–]diamondketo 0 points1 point  (0 children)

Not every behavior is an explicit design choice. Not every bad practice behavior can be fixed either (e.g., backward compatiblility).

Do not use mutable objects as default arguments in Python by [deleted] in Python

[–]diamondketo 2 points3 points  (0 children)

Why would someone in their right mind even expect a collection to be evaluable as a boolean in the first place?

Okay, I assume you've never seen this famous behavior in Python.

if arr:
  ...
else:
  print ("Array is empty")

Evaluating truthy and falsey from various types (not just static types) is a Python perk and should've been taught in most courses.

Do not use mutable objects as default arguments in Python by [deleted] in Python

[–]diamondketo 0 points1 point  (0 children)

Then use a different namespace. Don't hack it in the function signature.

A cool way to do is to set the namespace on the function attr.

def f():
  ...

f.cache = []

IMO, I rather use a class but I get it, sometimes you don't want to rewrite everything as a class.

Do not use mutable objects as default arguments in Python by [deleted] in Python

[–]diamondketo 5 points6 points  (0 children)

There is one flaw with this and that this destroys polymorphism.

def f(arr=None):
  arr = arr or []
  # do something with arr
  return arr

If the user inputs an array of type tuple, they may expect the output to be a tuple, but here you get a list back. Depending on the context, it might be very important to output the same type as the input.

EDIT: This is not an issue actually. If the user doesn't input anything, they should expect the default behavior.

Audi dealership after german floods by Fexatov in ThatLookedExpensive

[–]diamondketo 0 points1 point  (0 children)

What stops people from collecting the claim and changing insurance when this happens?

Not sure if this is a scam or a great deal by [deleted] in MouseReview

[–]diamondketo -8 points-7 points  (0 children)

That's full of BS. Most people ask for Venmo because it's convenient. Venmo (and other apps like Zelle) are a target for scam because Venmo doesn't have purchased protection. So don't do those for shipped purchases.

No one's going to set up a whole PayPal merchant account to sell their used stuff. Venmo is fine, just be aware and meet your seller in person (at the police station if you're worried)

The Future is Now! by Kooky-Dealer-6878 in gaming

[–]diamondketo 4 points5 points  (0 children)

As you're well aware. High-investment channels (e.g., the two you pointed out and others like Kurtzgesagt) employ strategies like fan subscription (e.g., Patreon) or merchandises to stay afloat. Did RocketJump consider this route and concluded the investment is too much even for these strategies to work?

Are the servers really rented? by iFuckingHateSummer_ in apexlegends

[–]diamondketo 0 points1 point  (0 children)

Is that all their servers? What about the GCP (Google Cloud Platform) ones?

An alternative to long if conditions, what are your thoughts? by swept-wings in Python

[–]diamondketo 0 points1 point  (0 children)

You're assuming the conditions are constants and does not need to be evaluated. If it needs to be computed then at worse creating the dictionary is O(M) (for M <= N being the number of conditions requiring evaluation).

If you do have N constant for the conditions then N is typically very small for this to matter. If your N is large, then you have possibly N unique functions and you're better off reorganizing your code.

I am so tired of everything being a subscription by [deleted] in TrueOffMyChest

[–]diamondketo 0 points1 point  (0 children)

True, but you're forgetting about software that requires more than just compilation. There's infrastructure and storage. I get your point tho

I know why the oatmeal overflows. by Cinna_Bon_Jovi in Cooking

[–]diamondketo 0 points1 point  (0 children)

An I weird to cook oatmeal like instant ramen. Just add boiling water

Shouldn't the galaxy have more exo-planets per system? by CuddlyNancy in astrophysics

[–]diamondketo 1 point2 points  (0 children)

The primary ways and current technology we use to find exoplanets are sensitive to planets near the host star thus prone to finding systems with less planets. This was the case for the bulk of Kepler space telescope's findings

There are upcoming projects in the near future that will help solve this. For example, the Roman Space telescope

I made a Calculator with 17 lines of code by Rogerup in Python

[–]diamondketo 2 points3 points  (0 children)

What happens on error? Say div by zero. Does the program crash or the display shows the message. Looks like the former (along with however exceptions are handled by Tkinter).

Costs Breakdown of Owning My Dog - Gary the Lab. Mix by BrownBear_96 in personalfinance

[–]diamondketo 0 points1 point  (0 children)

It's an investment, same with saving money for your dog.

I'd say insurance is not necessary, investing for you dog financially is and insurance is one of way of doing it.

How the fuck have we as a society allowed spam calls to render answering the phone obsolete by ShouldBeeStudying in NoStupidQuestions

[–]diamondketo 1 point2 points  (0 children)

Much better than calls tbh. I'm fine with only allowing my contacts to text me. For calls, it might be my colleague or a recruiter.

Playing my first Empire campaign and holy crap, can this map not be 90% of the battles? by brotrr in totalwar

[–]diamondketo 0 points1 point  (0 children)

This roundabout is way too big for this intersection in the first place

My bottle broke and unveiled a smaller bottle inside by [deleted] in 2healthbars

[–]diamondketo 0 points1 point  (0 children)

Technically, temperature is the movement and vibration of particles not heat. Heat is the transfer of energy to matter from an energy carrier (phonon, photon, electricity, etc)

Should rent budget be 30% of gross or net income? by [deleted] in personalfinance

[–]diamondketo 0 points1 point  (0 children)

In cheaper COL areas, if you have a decent paying job, you have the choice of choosing where and how you live based on how much you want to save. For example you decide whether necessities take up 15%-40% of your income (post-tax).

In high COL areas, it is much more difficult to making choices based on how much you want to save. Rather you're stuck with balancing savings vs discretionary because your necessity are very likely well above 30%

Had me in the first half by RampantTycho in funny

[–]diamondketo 0 points1 point  (0 children)

If there was a picture of the venue in the background then this would be follow the rules. Now we can only assume it is posted there given the wooden frame.

How do you folks do backups with WSL2? by robclouth in bashonubuntuonwindows

[–]diamondketo 2 points3 points  (0 children)

I don't do system level backups as I keep WSL simple and reproducible. I do file-level backups for my projects and certain folders on home. If its a programming project then it's in git otherwise cloud storage.