Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional Logic: Correct ternary operator syntax #29021

Merged
merged 2 commits into from
Nov 5, 2024

Conversation

youssef-el-atmani
Copy link
Contributor

Clarified ternary operator syntax by replacing "conditional" with "logical" for accuracy.

Because

To make the ruby ternary operator syntax more accurate

This PR

  • Replaced "conditional" with "logical" in the ternary operator syntax

Issue

Closes #XXXXX

Additional Information

Pull Request Requirements

  • I have thoroughly read and understand The Odin Project curriculum contributing guide
  • The title of this PR follows the location of change: brief description of change format, e.g. Intro to HTML and CSS lesson: Fix link text
  • The Because section summarizes the reason for this PR
  • The This PR section has a bullet point list describing the changes in this PR
  • If this PR addresses an open issue, it is linked in the Issue section
  • If any lesson files are included in this PR, they have been previewed with the Markdown preview tool to ensure it is formatted correctly
  • If any lesson files are included in this PR, they follow the Layout Style Guide

Clarified ternary operator syntax by replacing "conditional" with "logical" for accuracy.
@github-actions github-actions bot added the Content: Ruby Involves the Ruby course label Oct 29, 2024
@CouchofTomato
Copy link
Member

Why do you feel conditional statement is not correct?

@youssef-el-atmani
Copy link
Contributor Author

Thank you @CouchofTomato for give me a chance to clarify my opinion

Why do you feel conditional statement is not correct?

Because the right name for something that could evaluates to true or false is a logical statement not a conditional statement,
for example :

#the followings are logical statements
5 == 7                #=> evaluates to `false`
6 >= 10               #=> evaluates to `false`
"hi" != "hello"       #=> evaluates to `true`


# I think the following is a conditional statement, which is composed of : `if ... end`
if logical_statement
  #do something 
else
  # do that another thing
end

I think logical statement ? <execute if true> : <execute if false> is as whole a conditional statement.

@youssef-el-atmani
Copy link
Contributor Author

@CouchofTomato May I ask you about what do you think?

@CouchofTomato
Copy link
Member

Apologies for the delay.

I don't disagree with you that it's a logical expression. However you'll often see it referred to as the condition in a lot of places because it decides the executed part of a conditional operator.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_operator
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/conditional-operator
etc etc

So in isolation it definitely is a logical expression, but as part of a conditional operator it is often referred to as the condition. That's why I'm not sure it's wrong to leave it as it is.

What are your thoughts?

@youssef-el-atmani
Copy link
Contributor Author

Thanks a lot @CouchofTomato, I guess it should stay as it is, conditional statement ? <execute if true> : <execute if false>

There is a little change I recommend based on the resources you provided: MDN and Microsoft,
MDN: condition ? exprIfTrue : exprIfFalse
Microsoft: condition ? consequent : alternative

So I recommend replacing conditional statement by condition, because I guess it fits better
And It is up to you to decide whether that change is worth it or not

@CouchofTomato
Copy link
Member

Yeah I'm happy to accept that. Thanks for working through this with me and I'm glad we arrived at a satisfactory outcome.

@CouchofTomato CouchofTomato merged commit 197e99c into TheOdinProject:main Nov 5, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content: Ruby Involves the Ruby course
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants