|
 |
|
 |
|
View Poll Results: Which Style of curly braces layout do you prefer?
|
|
Style 1
|
  
|
7 |
30.43% |
|
Style 2
|
  
|
16 |
69.57% |
04-02-2003, 07:50 AM
|
#31 (permalink)
|
|
Person of interest
Join Date: Mar 2003
Location: New Jersey
Posts: 102
|
Quote:
|
Ternary Operators are used to give variable a value, It returns a certain value, You can't really use it to execute, For example functions.
|
What!? In what language is this? For Java and Perl this is perfectly valid.
Code:
x != null ? do(x) : doh() ;
sure this is invalid if doh() is a void method
Code:
printf( "%s\n", x != null ? do( x ) : doh() );
This wouldnt work, since printf needs a string to print, and doh() isnt going to return one. But yes, you can execute methods out of a ternary operator, you can even nest them!
Code:
return( ( gotAccount == YES ? ( status == 'A' ? YES : ( [self isSuspended] == YES ? YES : NO ) ) : NO ) );
jeffro
__________________
Jeffro
Linux counter#:213782
GnuPG ID: 406238E7
|
|
|
04-02-2003, 10:11 AM
|
#32 (permalink)
|
|
Code Monkey
Join Date: Feb 2003
Location: Netherlands
Posts: 89
|
Hm, Calling a function from Ternary Operators is something i
haven't seen used, I guess it's possible but you might as well
go for the IF statements, It's easier to understand.
|
|
|
04-02-2003, 09:55 PM
|
#33 (permalink)
|
|
Regular Contributor
Join Date: May 2002
Location: Alkmaar, the Netherlands
Posts: 167
|
there is some contest (maybe more than one?) to write a c program which is as less readable as possible ... the most unreadable code wins (as long as the program does as required results) .. one of the most common tricks used in there is to post all code on 1 line (using no indention ...) but also to use no brackets at all
i forgot the url i had for that contest
the 'go to first unread post' doesnt work anymore .. it just goes to the last post .. although i hadnt read about 10 posts in this thread
__________________
The specialty of the house? thats me (cheap as always)
|
|
|
04-03-2003, 05:02 AM
|
#34 (permalink)
|
|
Registered User
Join Date: Mar 2003
Posts: 1
|
The International Obfuscated C Code Contest
http://www.ioccc.org/
has an annual competion for impossible to read C code
Code:
#include <stdio.h>
#define S(s)char x[]=#s;s
#define Q(x)x
#define A(x,y)y##x
#define B(x,y)A(y,x)
#define C(x,y)B(y,x)
#define Z(s,t,u)case s:if(*p!=32){t;}else{u;}break;
S(B( A( a ,m ),A(n ,i))() {B (A(h,c ),A(r ,a ))*p=x ;B(A( n, i),t)t
=0;B(A(n , i),t)s =0;B( f ,A(r, o )) (;*p;Q( p)++){C( B( A(c,t) ,h),B(A(
w, s),i))( s){ Z( 0,t+=8 *8-00 ,s ++)Z( 1,t+= 8 ;,s++ )Z
( 2, t++ ,putchar(t-73);t=s=0)}}})
|
|
|
04-03-2003, 06:36 AM
|
#35 (permalink)
|
|
Registered User
Join Date: Apr 2003
Location: Michigan Tech
Posts: 38
|
Style 2.... cuz thats how MTU taught me..... stupid MTU makin me use all those enters and stuff!!!!
|
|
|
04-03-2003, 12:12 PM
|
#36 (permalink)
|
|
Regular Contributor
Join Date: Apr 2003
Location: noWhere, PA
Posts: 104
|
i have always used #2:rock:, i dont like reading #1
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 05:21 AM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|