Question: The following code excerpts are problematic. For each one, explain what is wrong with the code, which good practice was not applied and how you

The following code excerpts are problematic. For each one, explain what is wrong with the
code, which good practice was not applied and how you would improve the code.
a)[3%] Result r = null;
if (something)
r =[..some query..];
try {
r.method();
}
catch (Exception e){
}b)[3%] $q1="an SQL query";
$q2= "another SQL query";
...
$qn = "the nth SQL query";
...
for ($i =1; $i <9; $i++){
$qi ="q$i";
$q = $$qi;
query($q);
}
c)[3%] for (int i =0; i <3; i++)
{
switch (i)
{
case 0:
DoThing1();
break;
case 1:
DoThing2();
break;
case 2:
DoThing3();
break;
}
}
d)[3%] String result =( String ) aMap.get( key );
if( result == null )
{
result = null;
}
return result;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!