• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

I don't know this syntax

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could some help to elobarate this syntax, i cannot understand
the syntax is
public DrawPanel( int w, int h )
{
width = ( w >= 0 ? w : 100 );
height = ( h >= 0 ? h : 100 );
}
:O
 
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's just a short hand way of doing:
if (w >= 0 ) {
width = w;
} else {
width = 100;
}
 
author
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"noorme",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
Thanks.
Sean
 
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by james swan:
It's just a short hand

and UGLY

way of doing:


I am sure, now that you know, that you will not use it. Otherwise you will soon find in this forum, someone asking the same question on your code.
W.

 
author
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seriously? Admittedly, you can use it to make code completely unreadable, but I personally findeasier to take in at a glance thanCould mere unfamiliarity be part of the problem? And if so, is not using it the right solution? After all it's not exactly rocket science.
I would, however, suggest using parentheses around the boolean condition as indicated above; this does improve readability by making the condition instantly recognisable and strengthens the parallels with an if () .. else .. construct.
- Peter

[This message has been edited by Peter den Haan (edited December 13, 2001).]
 
Why should I lose weight? They make bigger overalls. And they sure don't make overalls for tiny ads:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic