Just a small frog hopping from post to post. Because it may be Wednesday my Dudes!

Sometimes in German, sometimes in English.

  • 0 Posts
  • 37 Comments
Joined 2 years ago
cake
Cake day: June 14th, 2023

help-circle
  • This is basically one of the core ideas of Ruby: that you can read it like a story. Once you are used to reading it as “do X unless Y”, you will miss it in other languages. Note that I wrote Y, not Y is true. Because often Y is a statement that has meaning in itself.

    Example:

    # imagine that given_name is some text from user input
    
    # this is of course valid:
    user.name = given_name if !user.is_locked
    
    # but this reads more fluently:
    user.name = given_name unless user.is_locked
    

    Ruby also allows using ? as last character in method names, which is a convention for methods that return either true or false.

    Same goes for ! (the bang operator), that is commonly used to tell developers that there exists a non-bang version of the same method as well. The bang method is often the more strict version (e.g. raises an error instead of returning nil; or having side effects compared to the non-bang version).

    So the above example may be more commonly written like this:

    user.name = given_name unless user.locked?
    

    and the question mark makes you automatically adding is or has while reading: Set the user’s name to the given_name unless the user is locked

    Of course this is all by convention and you may also do it different. But that’s how most Ruby code is written.

    To stay consistent, lots of projects use RuboCop, which warns you on inconsistency based on your project’s settings.

















  • I get where you come from and my first thought was similar. But keep in mind: hurting or even killing someone else is not like simply stealing the Amazon packages from your MAGA neighbour’s front door to annoy them.

    Acting violent against someone else will have consequences for your own life. It does not matter if you where morally right to do so, even when you where simply fighting for your life. You will feel shame and regrets because you are an empathic human being. You will think about this act every time your mind wanders off.

    I don’t care about about the attackers well-being, do not get me wrong. I care about your well-being.

    We must stop these thugs before they can go after marginalised groups. Anything else is just pyrrhic victory.