Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

which one is a good Practice?

 
Ranjith R
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy ...reader..
this topic is rather about Style or Practice in JSP: Plz read the piece of codes below.
Style1
------
...
<h3>Agent name is :</h3>
<%
  if(agentCode.equals("007")){
   out.println("<b>James Bond</b>");
  }
  else{
   out.println("<b>Jennifer Lopez</b>");
  }
%>
Style2
------
<h3>Agent Name is:</h3>
<%  if(agentCode.equals("007")){
%>
<b>James Bond</b>
<%  }
  else{
%>
<b>Hanibal Lector</b>
<%
  }
%>
... uh...

SO... what do you say? ..

------------------
Take care
r@njith
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally: always the second one.
Additionally, the bold tags are common so I'd pull them out as well (separate content and mark-up)

Dave.
 
Shama Khan
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed. I'd say the second one is more correct.
 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what about:
<h3>Agent name is :</h3>
<%
String strOut;
if(agentCode.equals("007")){
strOut = "<b>James Bond</b>";
}
else
{
strOut = "<b>Jennifer Lopez</b>";
}
out.println(strOut);
%>
 
Syam Veerakumar
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adam Hardy's type of code is always good Practice I guess.
 
Ranjith R
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
..err...
but tell me is it considered as a bad practice if i am using more out.println(someThing) s? rather than stuff like <%=someThing %>
thankx
[This message has been edited by Ranjith R (edited October 12, 2001).]
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Ranjith R",
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 again with a new name which meets the requirements.
Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic