Page 5 of 14 FirstFirst ... 2345678 ... LastLast
Results 41 to 50 of 132
  1. #41

    Quote Originally Posted by MarkCuering View Post

    when you hit enter right after the doSomething function, some IDE will place your line on the leftmost position,letting you remind that your code is outside "if" block statement.

    I still prefer to use "{ }" no matter how single lines of code is that... most of the debuggers evaluate blocks statement via curly braces plus you are taking the advantage of collapsing and expanding your codes (just in case your IDE is having that kind of features).
    for one liner if statements without having to use curly braces, u can always use the ternary operator..
    but special cases ra ni.. you have to do some assignment..

  2. #42
    Elite Member
    Join Date
    Aug 2008
    Posts
    1,053
    Blog Entries
    1
    Quote Originally Posted by bluedes View Post
    naa nay flags bro.. mao bitaw nay gamit sa flags.. this if case is not changing the language syntax or how it evaluates expressions.. its just checking for double '=' within an if condition, which is a special case appropriate for flags..

    have you ever compiled using gcc with all its superfluous flags?
    haven't encountered anything that double checks the '=' under if statement... the closest flags with respect to our discussion, is the one I mentioned above, using /Zs.

    My understanding about superfluous flags, or let me say unnecessary flags are appeared only at certain situation. eg. Compilers have default flags some of it are superfluous in Windows Operating Systems, BSD's, Linux and other distros and more...and We will disable/enable that manually.

    anyway, It’s not difficult to examine compiler's flag, coz it is all categorized into different purpose like Optimization, Code Generation, Output Files, Linking, and etc...

  3. #43
    Elite Member
    Join Date
    Aug 2008
    Posts
    1,053
    Blog Entries
    1
    Quote Originally Posted by bluedes View Post
    for one liner if statements without having to use curly braces, u can always use the ternary operator..
    but special cases ra ni.. you have to do some assignment..
    Frankly, I discouraged the usage of ternary operators, there are times when you are a bit tired and exhausted and seeing this code makes you more confuse, determining which end is which. Aside from that, you cannot set some breakpoints, especially if you want to investigate only at specific clause.

    The only help that ternary operator provide me is when I want conditional statement inside my WriteLine or cout function. the rest are all just plain if/else block.

  4. #44
    Quote Originally Posted by MarkCuering View Post
    Frankly, I discouraged the usage of ternary operators, there are times when you are a bit tired and exhausted and seeing this code makes you more confuse, determining which end is which. Aside from that, you cannot set some breakpoints, especially if you want to investigate only at specific clause.

    The only help that ternary operator provide me is when I want conditional statement inside my WriteLine or cout function. the rest are all just plain if/else block.
    if you discourage usage of ternary operators, why use it even in writeline??

    like i said bro, these are not hard and fast rules.. ternary operators are also used outside of writeline or what-nots.. its up to you if you're comfortable with it or not..

    however, personally, if a programmer is confused about ternary operator logic, then he's not really a programmer.. its expected na kahibalo na xa unsa gamit ana.. it makes for really compact code but still readable.. dre na ni mu-delineate sa real programmer or script-kiddie lng.. hehe.. so don't refrain from using ternary just because you fear that others might not be able to read your code properly, force them to learn the usage of ternary operators..

  5. #45
    Elite Member
    Join Date
    Aug 2008
    Posts
    1,053
    Blog Entries
    1
    Quote Originally Posted by bluedes View Post
    if you discourage usage of ternary operators, why use it even in writeline??
    Writeline as invistagation purpose only... not in production code., when I want to output something and suddenly think of something conditionally, I code directly with ternary operator, instead of going back again placing if/else block, but this won't be shipped to production.

    Quote Originally Posted by bluedes View Post
    however, personally, if a programmer is confused about ternary operator logic, then he's not really a programmer..its expected na kahibalo na xa unsa gamit ana.. it makes for really compact code but still readable..
    I'm not a real programmer I guess... coz it really confused me, going back after 2-3 months, feels debugging codes at hell, It makes a real compact code that you are not able to set some breakpoints.

    Anway, If this is one of your reasons for you to differentiate real programmer or script-kiddie, I respect your opinion. At least I was able to share my truthful comments.

  6. #46
    Quote Originally Posted by MarkCuering View Post
    Writeline as invistagation purpose only... not in production code., when I want to output something and suddenly think of something conditionally, I code directly with ternary operator, instead of going back again placing if/else block, but this won't be shipped to production.



    I'm not a real programmer I guess... coz it really confused me, going back after 2-3 months, feels debugging codes at hell, It makes a real compact code that you are not able to set some breakpoints.

    Anway, If this is one of your reasons for you to differentiate real programmer or script-kiddie, I respect your opinion. At least I was able to share my truthful comments.
    i apologize.. i don't mean any offense..

    my logic would go around why ternary operators are even placed in standards.. for the record, i also had the same question as yours before.. libog man pag-una.. pero once i got used to it, its pretty much useful as one-line if-statements.. instead of putting curly braces, i convert my one-line if to ternary operators..

    as for the unable to put breakpoints, its just one line of if, so, i don't see the need to rely too much on breakpoint and just evaluate the one line in my head..

    besides, you can set a watch instead of breakpoints if you want to monitor evaluation of expressions..
    Last edited by bluedes; 12-15-2009 at 02:23 PM.

  7. #47
    Elite Member
    Join Date
    Aug 2008
    Posts
    1,053
    Blog Entries
    1
    Quote Originally Posted by bluedes View Post
    besides, you can set a watch instead of breakpoints if you want to monitor evaluation of expressions..
    In C# case:

    "Watch" has limitations everybody knows that... and It doesn't help either way. Inorder for you to understand what I mean, try this:

    Can you add watch on the return value? how about the line Math.Sin(x) ?

    Code:
    return x != 0.0  ? Math.Sin(x) / x : 1.0;
    Can anyone distinguish what operation is this? And why there is no room for breakpoints?

    Code:
    byte x = (byte)(8 + ((myVar == 1) ? 4 : 2));
    In addition to that, here's some code where I do it with ternary operators.

    Code:
    MyClass.StaticMethod(Method1( ) ? Method2( ) : (Method3( ) ? Method4( ) : Method5( )));
    Obviously I already put some breakpoints/watches from the method I'd like to investigate. But this code does not belong to our production code; never would I allow anyone to use ternary operators in our modules.

    In C++ case:

    Code:
    #define MyFunc(a, b) (((a)>(b)) ? (a) : (b))
    Of course there is no room for breakpoints/watches coz this is just a macro, but can anyone understand this right away? What’s the worst possible thing can happen here?

    There are still a lot more to discuss why ternary operators are ban in some corporate standards, but I’m not telling anyone here not to use it. What I explained here is just purely base in my experience, and from my previous posts
    Last edited by MarkCuering; 12-15-2009 at 03:55 PM.

  8. #48
    Quote Originally Posted by MarkCuering View Post
    In C# case:

    "Watch" has limitations everybody knows that... and It doesn't help either way. Inorder for you to understand what I mean, try this:

    Can you add watch on the return value? how about the line Math.Sin(x) ?

    Code:
    return x != 0.0  ? Math.Sin(x) / x : 1.0;
    Can anyone distinguish what operation is this? And why there is no room for breakpoints?

    Code:
    byte x = (byte)(8 + ((myVar == 1) ? 4 : 2));
    In addition to that, here's some code where I do it with ternary operators.

    Code:
    MyClass.StaticMethod(Method1( ) ? Method2( ) : (Method3( ) ? Method4( ) : Method5( )));
    Obviously I already put some breakpoints/watches from the method I'd like to investigate. But this code does not belong to our production code; never would I allow anyone to use ternary operators in our modules.

    In C++ case:

    Code:
    #define MyFunc(a, b) (((a)>(b)) ? (a) : (b))
    Of course there is no room for breakpoints/watches coz this is just a macro, but can anyone understand this right away? What’s the worst possible thing can happen here?
    yeah, as a matter of fact, you can evaluate the entire expression not including the return..
    "x != 0.0 ? Math.Sin(x) / x : 1.0;"

    or you can also put watches on individual members of the ternary operator, if you're curious for the evaluation of separate expressions:

    "x != 0.0"
    "Math.Sin(x) / x"
    "1.0"

    you can evaluate them just before you get to that return statement.. which is the previous line.. add a breakpoint there and just check ur watch expressions..

    i don't know what limitation of watch you are talking about.. can u please specify?

    Quote Originally Posted by MarkCuering View Post
    There are still a lot more to discuss why ternary operators are ban in some corporate standards, but I’m not telling anyone here not to use it. What I explained here is just purely base in my experience, and from my previous posts
    that's your personal preference bro.. but i still don't see justification why you should ban ternary operators in some "corporate standards"..

    again, ternary operators are a good substitute for one-liner ifs, that's why they are created in the standards.. but if your if statements comprises more than one-line, then ternary operators only make the code confusing.. especially if nested ifs or if-else-if..

  9. #49
    Elite Member
    Join Date
    Aug 2008
    Posts
    1,053
    Blog Entries
    1
    a watch on: x != 0.0 ? Math.Sin(x) / x : 1.0
    and: Math.Sin(x)

    some sort of limitations or side effects...

    the messages are:

    1. This expression causes side effects and will not be evaluated as double
    2. Math.Sin(x) The name 'x' does not exist in the current context.

    I hope you figure it out why does it happened. The rest of those limitations is not relevant for this topic. like looking on float or double, type cast, virtual destructors. What IDE are you working on? So i could enumerate those limitations for you.

    Any comments or solutions on the other issues I mentioned? like this one:

    Code:
    byte x = (byte)(8 + ((myVar == 1) ? 4 : 2));

    Quote Originally Posted by bluedes View Post
    again, ternary operators are a good substitute for one-liner ifs, that's why they are created in the standards.. one-liner if?
    you mean as simple as this:
    Code:
    if (x!=y) doThis(); else doThat();


    I was really thinking that you want to utilize the entire ternary operator base on my given examples… when all of my opinions are base from that…

  10. #50
    Quote Originally Posted by MarkCuering View Post
    a watch on: x != 0.0 ? Math.Sin(x) / x : 1.0
    and: Math.Sin(x)

    some sort of limitations or side effects...

    the messages are:

    1. This expression causes side effects and will not be evaluated as double
    2. Math.Sin(x) The name 'x' does not exist in the current context.

    I hope you figure it out why does it happened. The rest of those limitations is not relevant for this topic. like looking on float or double, type cast, virtual destructors. What IDE are you working on? So i could enumerate those limitations for you.

    Any comments or solutions on the other issues I mentioned? like this one:

    Code:
    byte x = (byte)(8 + ((myVar == 1) ? 4 : 2));

    you mean as simple as this:
    Code:
    if (x!=y) doThis(); else doThat();


    I was really thinking that you want to utilize the entire ternary operator base on my given examples… when all of my opinions are base from that…
    sa imoha nang debugger problema bro.. coz wala jud problema sa ako dre..
    what debugger are u using? i'm using GDB - GNU debugger..

    i've tried those many times, evaluating even the most complicated expressions and multi-line expressions in my watch/expressions list, wala jud problema..

  11.    Advertisement

Page 5 of 14 FirstFirst ... 2345678 ... 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