What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 13275 |  Welcome, Guest!   Register  Login
 Home > Coding Horrors > Pattern and Practices > Ooh No ...
Vuyiswamb

Ooh No

 Coding Horror posted by: Vuyiswamb | Posted on: 10/12/2011 | Category: Pattern and Practices | Views: 3498 | Level: NotApplicable | Status: [Member] [MVP] [Administrator] | Points: 75 | Alert Moderator   



Telerik Introduced a nice application that is intergrated with visual studio. I suggest you ask your company to buy it. The name of the Product is called "JustCode" , as you can see the name says it all. Just code and the software will tell you the problems afterwards. Visual studio does not report logicall Errors or bad coding. Now Just code is made exactly for that. well i came across this 

            If CCD(val) < 1 Then
                    val = CCD(valueR)
                Else
                    val = CCD(valueR)
                End If
                Return Format(valueR, "0") & "%"

Well what is wrong here ? the First user who will respond with the correct answer , will win points to his profile. 

Lets discuss this







Thank you for posting at Dotnetfunda
[Administrator]
Found interesting? Add this to:


Experience:11 year(s)
Home page:http://www.Dotnetfunda.com
Member since:Sunday, July 06, 2008
Level:NotApplicable
Status: [Member] [MVP] [Administrator]
Biography:Vuyiswa Junius Maseko is a programmer and a moderator in ".NetFunda. Vuyiswa has been developing for 9 years now. his major strength are C# 1.1,2.0,3.0,3.5 and sql and his interest are in Silverlight,WPF,C#,Kinect , Xbox Gaming Dev.
 Responses
Ndebata
Posted by: Ndebata | Posted on: 10/13/2011 | Level: Starter | Status: [Member] | Points: 700 | Alert Moderator 

Hi Vuyiswa,

In this case whether the condition is true or false it does not matter, in any case
val = CCD(valueR)
will be executed.
and if this code block is inside a method and val is not a passed as ref or out then we do not need write this also only return statement will do the job.

Thanks,
Debata


R_kharwade@yahoo.co.in
Posted by: R_kharwade@yahoo.co.in | Posted on: 10/13/2011 | Level: Starter | Status: [Member] | Points: 700 | Alert Moderator 

In this code I can see there is an if condition which is of no use at least for this kind of scenario as in both the cases the same code will be executed As val = CCD(valueR)

Even though removing of if condition it will be returned same thing as there is no relationship between if condition and return statement.

So, I think there should not be an if condition and only return statement should be there.




Vuyiswamb
Posted by: Vuyiswamb | Posted on: 10/13/2011 | Level: NotApplicable | Status: [Member] [MVP] [Administrator] | Points: 15 | Alert Moderator 

Congradulations Debata and R_kharwade@yahoo.co.in

You have won yourself 700 Points. you have now both won yourselves 700 points for your replies. There is no need for an If statement because the results will be the same. I think sometimes a programmer that write's this kind of code, is either coding at night tired or i assume drunk or ignorant or no one is doing code reviews at his company.

I will make sure that the contributors of this section get this kinds of points. Let us promote good coding standards

Thank you Guys.


Thank you for posting at Dotnetfunda
[Administrator]

Akiii
Posted by: Akiii | Posted on: 10/14/2011 | Level: Bronze | Status: [Member] | Points: 15 | Alert Moderator 

Here if and else are of no use as both are doing the same thing.....so this must be changed.

Thanks and Regards
Akiii

Vuyiswamb
Posted by: Vuyiswamb | Posted on: 10/14/2011 | Level: NotApplicable | Status: [Member] [MVP] [Administrator] | Points: 15 | Alert Moderator 

That is true. Akiii

Thank you for posting at Dotnetfunda
[Administrator]

Biswarup90
Posted by: Biswarup90 | Posted on: 11/22/2011 | Level: Starter | Status: [Member] | Points: 15 | Alert Moderator 

Thank you to all......Akii also true

Biswarup Ghosh

Lakhwinder.Ghuman
Posted by: Lakhwinder.Ghuman | Posted on: 2/29/2012 | Level: Starter | Status: [Member] | Points: 15 | Alert Moderator 

The statement in the else block must be different as to if block.


Best Regards
Lakhwinder Ghuman

Sinha.Rajeshk
Posted by: Sinha.Rajeshk | Posted on: 8/9/2012 | Level: Starter | Status: [Member] | Points: 15 | Alert Moderator 

Both if and else blocks are executing the same code so whether the condition is true or false it hardly matters the same code will get executed.

Kundan64
Posted by: Kundan64 | Posted on: 12/26/2012 | Level: Starter | Status: [Member] | Points: 15 | Alert Moderator 

Here If and Else both block are doing same work.

>> Write Response - Respond to this post and get points

More Coding Horrors

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/21/2013 5:33:21 PM