Page 3 of 14 FirstFirst 12345613 ... LastLast
Results 21 to 30 of 132
  1. #21
    Elite Member
    Join Date
    Aug 2008
    Posts
    1,053
    Blog Entries
    1

    Quote Originally Posted by bluedes View Post
    what if choice is integer, and 0 is considered false..
    I think boolean expressions evaluate 0 as false.

    you can have like this:

    if(getChoice()) or if(!getChoice()) or if(getChoice() > 0)

    What language and compiler you are referring by the way?

    other than that, I normally don't place function in any of my "if statement", where I need the funcion's returned value/reference, and the function itselfs is having another function calls or any small-medium operations, that makes some overhead.

    eg.

    if(MyFunc())
    {
    x = MyFunc();
    }
    the above code process functions twice.


    Real world situation.


    a function that returns two element, first is boolean, second is an object.

    BAD CODE:


    if(MyFunc()[0])
    {
    anObject = MyFunc()[1];
    }
    GOOD CODE:
    anObject=MyFunc();

    if(anObject[0])
    {
    //do whatever you want in anObject[1];
    }
    Quote Originally Posted by bluedes View Post
    if ((bool) choice)
    and I seldom/haven't seen a code casting some variable to boolean type, integer can be treated as boolean values, however boolean type variables are two bits size only.

  2. #22
    Quote Originally Posted by MarkCuering View Post
    Code:
    if(MyFunc()[0]) 
    {
       anObject = MyFunc()[1];
    }
    what kind of function call is that? unless ur function returns an array, why not reference the array directly.. obviously that is bad code.. anybody can see that..



    Quote Originally Posted by MarkCuering View Post
    and I seldom/haven't seen a code casting some variable to boolean type, integer can be treated as boolean values, however boolean type variables are two bits size only.
    that is why if you don't have implicit conversion, ur integer in if statement will resort to a compiler error..




    this:

    Code:
    if (oldChoice = getChoice())
    is totally different from this:

    Code:
    if (oldChoice == getChoice())
    so if you want to be clear, its better to put the function on the left side

    Code:
    if (getChoice() == oldChoice)
    or.. as i have suggested earlier, the constant on the left side..

    Code:
    if (8080 == port)
    
    if ("YES" == response)
    
    if (true == choice)

  3. #23
    Elite Member
    Join Date
    Aug 2008
    Posts
    1,053
    Blog Entries
    1
    from your previous post: I replaced the "TRUE" to 0.

    Quote Originally Posted by bluedes View Post
    if ( variable == 0 )

    when mistakenly written as

    if ( variable = 0 )

    will not trigger a compiler error even though logically, error na na..
    when you write:

    if ( variable = 0 )

    my compiler triggered this as an error, that's why I keep asking you what compiler you are talking here? what specific language?


    Quote Originally Posted by bluedes View Post
    but kung balehon nimo..

    if ( TRUE == variable )

    a mistake like this

    if ( 0 = variable )

    will be spotted by compiler right away..

    I agree on this, coz you cannot assign variables to any numeric/constant values, but if my compiler detects an error from previous approached why should I do this in the first place right?

    again, my compiler does not allow "=" to be at any of conditional expression... although my old compiler allows it, but if you perform "syntax check" it detects the error.


    Quote Originally Posted by bluedes View Post
    that is why if you don't have implicit conversion, ur integer in if statement will resort to a compiler error..

    returning as an error is an advantage for me




    Quote Originally Posted by bluedes View Post
    what kind of function call is that? unless ur function returns an array, why not reference the array directly.. obviously that is bad code.. anybody can see that..
    yes it returns an array. I already explained that

    not all can see that, believe me , they are doing more likely similar to this scenerio.

    if(Multiply(num1, num2) <> 0)
    {
    t = Multiply(num1, num2);
    }
    if you have worked with MFC library you can find like that... that's why people are force to make some direct Windows API Calls, to avoid overhead, eventhough you can get it to 3-5 lines of code using MFC.

  4. #24
    Quote Originally Posted by MarkCuering View Post
    from your previous post: I replaced the "TRUE" to 0.



    when you write:

    if ( variable = 0 )

    my compiler triggered this as an error, that's why I keep asking you what compiler you are talking here? what specific language?
    obviously, if your compiler triggered an error, then it has specific checks for that sa iyang hash-table during compilation..

    its pointless to answer your question what kind of compiler i'm using.. obviously, my compiler does not trigger that error, that's why i suggested those tips in if statements..

    and if your compiler triggers an error, then obviously, you cannot use those kinds of if conditions..

    does your compiler trigger an error if ingon ani:

    Code:
    if (choice = getChoice())
    and somewhere along the code

    Code:
    func getChoice()
    {
       return 0;
    }




    .
    .

    Quote Originally Posted by MarkCuering View Post
    I agree on this, coz you cannot assign variables to any numeric/constant values, but if my compiler detects an error from previous approached why should I do this in the first place right?

    again, my compiler does not allow "=" to be at any of conditional expression... although my old compiler allows it, but if you perform "syntax check" it detects the error.
    you don't.. ang2x naman buhaton pa nimo, klaro ana na mu-error sa imong compiler.. but what if your code is ported to another compiler?? its up to you.. these are just guidelines or suggestions, they're not hard-and-fast rules na you have to absolutely follow..

    ang title sa thread is Best Practices diba..

    don't be so in love with your compiler bro..

  5. #25
    Quote Originally Posted by MarkCuering View Post
    if you have worked with MFC library you can find like that... that's why people are force to make some direct Windows API Calls, to avoid overhead, eventhough you can get it to 3-5 lines of code using MFC.

    sorry, but MFC suckz... that's the slowest foundation classes i've ever tried to work with..

  6. #26
    Elite Member
    Join Date
    Aug 2008
    Posts
    1,053
    Blog Entries
    1
    no I'm not... it's just my opinion I feel it may be applicable to other Intepreted language, like python. but python, returns SyntaxError. I don't know about the other.

    Yup, early days of MFC burdens anyone with massive difficulties to use and familiarize, (version 4.x, 6.0x, etc...) there's no proper documentation, which is really awful. But there are huge changes at MFC 8.x++ along with the Visual Studio 2005/.Net2.0, which is a great effort...bad side, troubles Microsoft with lots of backward compatibility issues.

  7. #27
    Quote Originally Posted by MarkCuering View Post
    no I'm not... it's just my opinion I feel it may be applicable to other Intepreted language, like python. but python, returns SyntaxError. I don't know about the other.

    Yup, early days of MFC burdens anyone with massive difficulties to use and familiarize, (version 4.x, 6.0x, etc...) there's no proper documentation, which is really awful. But there are huge changes at MFC 8.x++ along with the Visual Studio 2005/.Net2.0, which is a great effort...bad side, troubles Microsoft with lots of backward compatibility issues.

    i don't like MFC.. but .Net is forgivable.. pero hinayan japon ko..

    its nice na .Net is a very comprehensive framework..

  8. #28
    Elite Member
    Join Date
    Aug 2008
    Posts
    1,053
    Blog Entries
    1
    watch on intel website, they will now specialized their cpu's for .NET support. more results can be seen on latest Winddows 7.0

  9. #29
    ScrapeBox Development softtouch's Avatar
    Join Date
    Jan 2004
    Gender
    Male
    Posts
    3,699
    Blog Entries
    1
    Quote Originally Posted by MarkCuering View Post
    in C++, I saw some people do this way
    if (8080==port)
    Yes, I saw this too, quiet weird in my opinion...

    Make more sense for me when if (mymoney == 100 pesos) then if (100pesos == mymoney)

  10. #30
    I saw this code in one printer driver code. Their reason is same as what bluedes said.

  11.    Advertisement

Page 3 of 14 FirstFirst 12345613 ... LastLast

Similar Threads

 
  1. what's the best and most practical NEGOSYO today?????
    By fratbaxxx in forum Business, Finance & Economics Discussions
    Replies: 166
    Last Post: 10-09-2014, 01:31 PM
  2. Looking For: Pattern makers, Seamstresses and Tailors
    By kamikaze_007 in forum Jobs
    Replies: 5
    Last Post: 06-02-2013, 10:47 AM
  3. Replies: 0
    Last Post: 09-14-2007, 10:14 AM
  4. Replies: 0
    Last Post: 06-21-2007, 11:01 AM
  5. Bad design and coding practices (antipatterns)
    By cmontoya in forum Programming
    Replies: 8
    Last Post: 01-05-2006, 06:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top