codethesaur.us icon indicating copy to clipboard operation
codethesaur.us copied to clipboard

Control structures: Add trailing conditionals

Open geekygirlsarah opened this issue 3 years ago • 2 comments

Description

Languages like Python and Ruby have the ability to add conditionals to the end of statements, like:

return if arg.nil?

Add this into control_structures.json file

geekygirlsarah avatar Apr 18 '21 18:04 geekygirlsarah

Would it be better to add "trailing conditionals", or to instead have a concept for "light-weight conditionals"?

The moral equivalent of this in Ruby:

do_something() if condition

is this in Scala:

if (condition) do_something()

In ruby, doing this with a normal conditional is somewhat more verbose, which can make it useful for clarity to use the "trailing conditionals" construction:

if condition then do_something() end

So, I guess the question here is: Should concepts exist to describe individual syntactic approaches (in this case, a variant syntax for conditionals is a separate concept), or to describe how to satisfy specific needs (in the case of a "light-weight conditional", the idiomatic way of saying "if simple_test do simple_thing" in the language.)?

hypatian avatar May 05 '21 00:05 hypatian

Oh good point! This came up in one of the Twitch streams where we were working on adding Ruby. You have a good point too.

I'll come back to this when I don't have as much day-job stuff to do!

geekygirlsarah avatar May 05 '21 02:05 geekygirlsarah