Page 2 of 14 FirstFirst 1234512 ... LastLast
Results 11 to 20 of 132
  1. #11

    Quote Originally Posted by kamsky View Post
    I think it's reverse. tabs looks uglier in different editor and spaces are consistent. I was a 'space' fan for that reason and but now reverted to 'tab'. element of java style preferred spaces in their first edition but changed to 'tab' in 2nd edition. Using tab is okay as long as you stricly use as 1 unit. then i changed to tab.
    i dont think its reverse.. different people have different conventions for spaces, so it would be ugly if you're forced to read someone's code with a defined space character of say 8 spaces per indent unya imoha kay 3 or 5 ra diay.. tabs is more flexible in that manner..

  2. #12
    Quote Originally Posted by bluedes View Post
    i see..

    for example:

    if ( response == yes )

    change to

    if ( yes == response )

    Is there a difference in the two like semantically, or how it is represented internally?

  3. #13
    Quote Originally Posted by -_- View Post
    Is there a difference in the two like semantically, or how it is represented internally?
    semantically, there's no difference between the two.. this practice is just to help the compiler spot an error if in case only 1 equals sign was written


    if ( variable == TRUE )

    when mistakenly written as

    if ( variable = TRUE )

    will not trigger a compiler error even though logically, error na na..


    but kung balehon nimo..

    if ( TRUE == variable )

    a mistake like this

    if ( TRUE = variable )

    will be spotted by compiler right away..

  4. #14

  5. #15
    Junior Member
    Join Date
    Jun 2009
    Gender
    Male
    Posts
    478
    Quote Originally Posted by bluedes View Post
    semantically, there's no difference between the two.. this practice is just to help the compiler spot an error if in case only 1 equals sign was written


    if ( variable == TRUE )

    when mistakenly written as

    if ( variable = TRUE )

    will not trigger a compiler error even though logically, error na na..


    but kung balehon nimo..

    if ( TRUE == variable )

    a mistake like this

    if ( TRUE = variable )

    will be spotted by compiler right away..
    nice.

  6. #16
    nice thread keep it coming...

  7. #17
    Elite Member
    Join Date
    Aug 2008
    Posts
    1,053
    Blog Entries
    1
    Quote Originally Posted by bluedes View Post
    semantically, there's no difference between the two.. this practice is just to help the compiler spot an error if in case only 1 equals sign was written


    if ( variable == TRUE )

    when mistakenly written as

    if ( variable = TRUE )

    will not trigger a compiler error even though logically, error na na..


    but kung balehon nimo..

    if ( TRUE == variable )

    a mistake like this

    if ( TRUE = variable )

    will be spotted by compiler right away..


    in C++, I saw some people do this way

    if (8080==port)

    they use it only for numerical values and not for boolean expressions.
    but if you asked me, I never do this, I used the conventional way: if(port==8080).

    I don't know what compiler you are talking here... but if I do it accidentally this way,

    if (x = 1)

    It throws a compile time error... Cannot implicitly convert type 'int' to 'bool', you declared x as int, if you wrap it with "if" statement, a good compiler that supports stronger type check will give you an error.

  8. #18
    Quote Originally Posted by MarkCuering View Post
    in C++, I saw some people do this way

    if (8080==port)

    they use it only for numerical values and not for boolean expressions.
    but if you asked me, I never do this, I used the conventional way: if(port==8080).

    I don't know what compiler you are talking here... but if I do it accidentally this way,

    if (x = 1)

    It throws a compile time error... Cannot implicitly convert type 'int' to 'bool', you declared x as int, if you wrap it with "if" statement, a good compiler that supports stronger type check will give you an error.
    anything that is a constant value, not just boolean or others.. even string literals.. basta constant value..

    if ("YES" == response)

    if (true == choice)

    if (3 == count)



    you are probably using .Net.. it has all those checks in the compiler.. in a way, it also makes your code too explicit and kinda redundantly messy..

    other compilers have implicit conversions.. obviously, yours doesn't have one..

  9. #19
    Elite Member
    Join Date
    Aug 2008
    Posts
    1,053
    Blog Entries
    1
    Quote Originally Posted by bluedes View Post
    anything that is a constant value, not just boolean or others.. even string literals.. basta constant value..

    if ("YES" == response)

    if (true == choice)

    if (3 == count)



    you are probably using .Net.. it has all those checks in the compiler.. in a way, it also makes your code too explicit and kinda redundantly messy..

    other compilers have implicit conversions.. obviously, yours doesn't have one..

    .NET is nothing to do with this, its just a set of classes anyway I tried on my other C compiler ISO/C99.

    compile error: warning #2030: '=' used in a conditional expression. (solves the problem)

    On the other hand, it runs on my old C++ compiler (which supposedly not) but if you use the syntax check (which a good practice before compiling) you will get the error.

    I don't want to comment about how you evaluate explicit conversion, explicit and implicit have both disadvantage as what I have observed in Python and C++, yet I haven’t seen anything that is messy to me there’s always been a good way.

  10. #20
    Quote Originally Posted by MarkCuering View Post
    .NET is nothing to do with this, its just a set of classes anyway I tried on my other C compiler ISO/C99.

    compile error: warning #2030: '=' used in a conditional expression. (solves the problem)

    On the other hand, it runs on my old C++ compiler (which supposedly not) but if you use the syntax check (which a good practice before compiling) you will get the error.

    I don't want to comment about how you evaluate explicit conversion, explicit and implicit have both disadvantage as what I have observed in Python and C++, yet I haven’t seen anything that is messy to me there’s always been a good way.

    messy na kaau ni na style ang explicit conversion..

    what if choice is integer, and 0 is considered false..

    if (choice = getChoice())
    this will result in error

    so you'd have to explicitly convert it or some other..


    choice = getChoice()

    if ((bool) choice)
    or

    choice = getChoice()

    if (choice != 0)
    but anyway, its programmer's preference... so its up to you which u prefer..

  11.    Advertisement

Page 2 of 14 FirstFirst 1234512 ... 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