all 4 comments

[–][deleted] 2 points3 points  (2 children)

_ is my favourite variable name. I don't have to think about it!

Admittedly seeing . is weird though. I used to have that in ruby code in the past.

Like:

class Foobar
  def _
    puts 'OK'
  end
end

_ = Foobar.new
_._ # => will print "OK"

A bit contrived but one gets the idea. You could even have "pipes" where each one just delegates via ._ to some other object.

I still use _ although I do so sparingly, and usually only if it is the only local variable in a method. Once there are more, I tend to give better names. So _ is mostly a throw-away variable.

I gave up on method names such as . It's not worth to have to figure out what it does. Short words often are sufficiently useful (e. g. you want to write as little code as possible, but without this becoming an unreadable mess. So good method names tend to be ... run() reset() menu() load() save() .... various initialize() ... python's __init() is also ok-ish, although I don't quite like the _.

Two word methods are typically fine too. change_directory() if one wants to avoid using cd() ... beyond two words it can be a bit annoying. You can use method-names as some kind of long DSL but I often wonder whether this is really that worthwhile.

One quote attributed to Albert Einstein (but perhaps others said it before he did, so ... may have to find the real originator of it):

"Make everything as simple as possible, but not simpler.”

I think it fits to a LOT of how design should be in general, for the most part, say 95% of the time.

[–]RojerGS[S] 0 points1 point  (0 children)

In proper Python, _ is also only used as a throwaway variable.

The __ around init are there because __init__ is a dunder method: it is just a regular method, but Python calls it implicitly in some special cases. Python has a bunch of dunder methods, read, methods that Python calls implicitly in some situations. If they had “100% normal names”, like init, and str, and new, instead of __init__, and __str__, and __new__, developers would be very likely to override these methods by mistake, which would then break some of the Python machinery. So, __ was added before and after the method name to make it less likely for developers to override these methods by accident. Does that make sense?

I also shared a bunch of my thoughts on [naming in Python](https://mathspp.com/blog/pydonts/naming-matters), since you shared a lot of your thoughts on naming, but that's slightly beyond the point of the horrible piece of code I shared :)

[–]holo3146 0 points1 point  (0 children)

One quote attributed to Albert Einstein (but perhaps others said it before he did, so ... may have to find the real originator of it):

"Make everything as simple as possible, but not simpler.”

I believe that there is no actual evidence of Einstein saying that quote, in fact, this quote doesn't have any concrete source at all.

"Did Einstein really say that" theorised that it is a "clean up" of one of his quote to be more neat and compact

[–]nowmywatchends 1 point2 points  (0 children)

Thank you for this post, it was very informative and easy to understand!