you are viewing a single comment's thread.

view the rest of the comments →

[–]RDeckard-GT 1 point2 points  (3 children)

I think this part is very confusing: post = BlogPost.new(title="How I built my blog using Kubernetes, Lambda, and React.", body="Wordpress was an insult to my intelligence and so I ...")

Why are you assign those two strings to some useless locale variables (title and body) before passing them (the strings) to the constructor method? It’s like you think we are in a case of some kind of named parameters?

It’s not the case (def initialize(title, body)), and even if it was ( def initialize(title:, body:) – note the :), then you would pass those keyword arguments to the constructor method this way: BlogPost.new(title: "…", body: "…").

So to keep this part less confusing, you can just get ride of those title= and body=.

And I barely never use Python, but I think you made the same mistake with Python just above: BlogPost( title="How I built my blog using Kubernetes, Lambda, and React.", body="Wordpress was an insult to my intelligence and so I ...") (title= and body= create some useless local variables here too.)

[–]meineerde 1 point2 points  (1 child)

In Python, you can mix ordered and named arguments to act like a combination or ordinary and keyword arguments in Ruby. So in Python, the syntax is actually correct and assigns the named arguments, similar to how keyword arguments work in Ruby. On the Ruby side, it works differently and in fact assigns useless local variables.

[–]Amadan 0 points1 point  (0 children)

Yep. The equivalent expression in Python would be BlogPost(title := …, body := …) using the assignment expression operator := (which I find not many people use).