Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8594179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:08:30+00:00 2026-06-12T00:08:30+00:00

int foo = bar > baz ? bar : baz; int foo = someBoolean

  • 0

int foo = bar > baz ? bar : baz;

int foo = someBoolean ? bar : baz;


int foo = (bar > baz) ? bar : baz;

int foo = (someBoolean) ? bar : baz;


int foo = (bar > baz) ? bar : baz;

int foo = someBoolean ? bar : baz;

I can’t decide which of these three I should use. I can:

  1. Use no parentheses and risk bad readability in examples such as:

    min[0] = min[0] > pos.x ? pos.x : 0;

  2. Always use parentheses, but risk
    somewhat ugly code in short expressions:

    setValue(val + scrollBar.getBlockIncrement() * ((scrollsUp) ? -1 : 1));

  3. Stay somewhere in between and use parentheses when there are spaces
    in the condition, but not if the condition is just a boolean
    variable:

    min[0] = (min[0] > pos.x) ? pos.x : 0;

    setValue(val + scrollBar.getBlockIncrement() * (scrollsUp ? -1 : 1));

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:08:32+00:00Added an answer on June 12, 2026 at 12:08 am

    Oracles Code Conventions states the following

    return (condition ? x : y);
    

    .. and further

    if (a == b && c == d)     // AVOID!
    if ((a == b) && (c == d)) // RIGHT
    

    …which is freely translated to

    return (someBoolean ? x : y);
    return ((x > y) ? x : y);
    

    .. although on a personal note I wouldn’t mind relaxing a parenthesis or two.
    In the end it’s still a subjective matter. If you feel adding/removing a parenthesis offers better readability, then by all means feel free to do so.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Where can we write code like struct Foo { int bar; int baz; }
The question Given a path like thus: G:\path\foo\..\bar\baz.txt Which we can immediately parse in
Given the following code: public struct Foo { public Foo(int bar, int baz) :
Why i can't use reinterpret_cast operator for such a cast? enum Foo { bar,
Say I have two independent classes: class Foo { int bar; } class Baz
is there a reason I should do public class Foo { int Bar() {
For example: struct Foo { int bar; int (*baz)(int); }; int testFunc(int x) {
Let's say I have an interface: public interface Foo{ String bar(int baz); } Now
I have a constexpr function that looks something like this: constexpr int foo(int bar)
Say I have an object: struct Foo { int bar_; Foo(int bar) bar_(bar) {}

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.