Code that may or may not pass muster
1
Name:
Anonymous
2009-10-01 2:42
I know we've got some computer science students in here, and I know you've written some questionable code at 2:30 in the morning before your project is due. So post it here! Preferably one-liners. Here's mine. I'm interested to see what my prof thinks of it... opinions could differ.
printf("%.1f%c", *e, (0 == (e - matrix + 1) % size)?'\n':'\t');
2
Name:
Anonymous
2009-10-01 2:48
printf
Problem found! printf will bottleneck your code, especially when dealing with matrixen'
3
Name:
Anonymous
2009-10-01 3:08
>>2
Don't worry, anyone spending much time running this program must be looking to waste their time anyway.
4
Name:
Anonymous
2009-10-01 3:41
printf("%.1f%c", *e, ((e - matrix + 1)%size)?'\t':'\n');
Better.
5
Name:
Anonymous
2009-10-01 3:50
>>4
The zero is there so readers know I'm comparing for numerical value. And why didn't you get rid of the extra parens if you're into pointless minimalism?
6
Name:
Anonymous
2009-10-01 4:03
>>5
The compiler takes no heed of extra parens and it will result in exactly the same compiled code. You're comparison on the other hand..
7
Name:
Anonymous
2009-10-01 4:40
>>6
My are comparison will make use of an instruction like x86's JNE.
8
Name:
Anonymous
2009-10-01 5:06
>>7
Several clock cycles slower than using JNZ.
9
Name:
Anonymous
2009-10-01 5:23
>>7
Not everyone uses a toy processor architecture like x86
10
Name:
Anonymous
2009-10-01 6:12
>>9
x86 doesn't has enough power for toys, they use ARM.
11
Name:
Anonymous
2009-10-01 6:20
>>10
doesn't has
english isn't your first language
12
Name:
Anonymous
2009-10-01 6:24
>>11
that's the kind of attitude hitler had
13
Name:
Anonymous
2009-10-01 6:26
>>12
I am not an anti-semite
14
Name:
Anonymous
2009-10-01 6:28
>>11
grammar nazis in MY /prog/???
are we getting raided by gaia or something?
15
Name:
Anonymous
2009-10-01 6:38
>>14
Non-sense, gaia has much more culture and posts are at least 10 times bigger.
16
Name:
Anonymous
2009-10-01 6:40
17
Name:
Anonymous
2009-10-01 7:24
18
Name:
Anonymous
2009-10-01 8:04
>>17
that hurts.
really.
D:
19
Name:
Anonymous
2009-10-01 8:20
printf("%c", ********c);
That was pretty deep
20
Name:
Anonymous
2009-10-01 8:33
one of my favorite beautiful pieces of c is this switch technique:
switch(foo) {
case 1:
s = "one";
if(0)
case 2:
s = "two";
if(0)
case 3:
s = "three";
blah(s);
break
}
21
Name:
Anonymous
2009-10-01 8:35
22
Name:
Anonymous
2009-10-01 8:36
23
Name:
Anonymous
2009-10-01 8:37
>>21
is that the boy twin from rugrats?
24
Name:
Anonymous
2009-10-01 8:38
>>20
what the hell?
i assume that
if(0) functions the same as
break;.
GENIUS!
25
Name:
Anonymous
2009-10-01 8:41
>>24
no, it means it skips the first line of the next case, but then continues. this allows a common section for the 3 cases, but also specific code for each
26
Name:
Anonymous
2009-10-01 8:46
>>25
mind == blown
amazing
27
Name:
Anonymous
2009-10-01 8:51
28
Name:
Anonymous
2009-10-01 8:52
29
Name:
Anonymous
2009-10-01 9:08
>>20
haha
try doing that in haskell. oh wait. U CANT BCUZ HASKELL SUCKS
30
Name:
Anonymous
2009-10-01 9:30
>>20
OH GOD IT'S SO BEAUTIFUL!
31
Name:
Anonymous
2009-10-01 10:04
32
Name:
Anonymous
2009-10-01 10:14
>>29
I know, right? Haskell doesn't even have
goto. What kind of toy language doesn't have
goto?
33
Name:
Anonymous
2009-10-01 10:33
>>32
A language... with call/cc.
34
Name:
Anonymous
2009-10-01 10:39
>>33
call-with-current-continuation-because-yo-momma-said-so
35
Name:
Anonymous
2009-10-01 12:09
ENTERPRISE QUALITY
36
Name:
Anonymous
2009-10-01 12:35
i wrote this today.
i don't think it's actually very bad, but i felt kinda bad about it because i've always been told that gotos are bad mojo.
while((c = getchar()) != EOF){
int i;
for(i = 0; i < str1_len; ++i){
if(c == str1[i]){
goto next_outer;
}
}
putchar(c);
next_outer:;
}
in case you're wondering, what it does is prettymuch the same as tr -d
37
Name:
Anonymous
2009-10-01 13:12
>>32
Inb4 someone writes a Goto Monad
38
Name:
Anonymous
2009-10-01 13:26
>>36
c <- getChar
let str' = str ++ filter (not . flip elem str) [c]
39
Name:
Anonymous
2009-10-01 13:30
>>37
main = runBASIC' $ do
10 PRINT "Already done."
20 GOTO 10
40
Name:
Anonymous
2009-10-01 13:37
>>39
This is why I hate Haskellers >:-|
41
Name:
Anonymous
2009-10-01 15:22
>>37
Well, there already is the
Continuation monad.
42
Name:
Anonymous
2009-10-01 20:14
>>26
I am amazed by
blah(s)
43
Name:
Anonymous
2009-10-02 4:29
>>42
blah(s) is an
[b] EXPERT FUNCTION NAME [/]b]
44
Name:
Anonymous
2009-10-02 12:19
>>43
#<COMPILED-PROCEDURE:BLAH>
45
Name:
Anonymous
2009-10-02 12:21
#<FUNCTION BLAH>
46
Name:
Anonymous
2009-10-02 12:31
>>> blah
<function blah at 0xb801b72c>
47
Name:
Anonymous
2009-10-02 12:36
blah
#<procedure:blah>
48
Name:
Anonymous
2009-10-02 14:39
draw_text(text+ending,font,(10-scroll_text,15+font_height+(i*font_height)+((ani/10.0)*font_height)),color)
sup
49
Name:
Anonymous
2009-10-02 20:40
HWND* dicks = make_print_window(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 400, 400);
50
Name:
Anonymous
2009-10-03 6:00
(define math:cos (get-ffi-obj "cos" (ffi-lib "libc") (_fun _double -> _double)))
Chicken Scheme users: don't even dare pussy out and use the c library.
51
Name:
Anonymous
2009-10-03 17:28
>>49
Ludicrous. I can tell you right now that any API like that would
not pass muster. Nobody would publish it.
52
Name:
Anonymous
2009-10-03 20:26
>>51
take a look at msdn some day
53
Name:
Anonymous
2009-10-03 20:36
>>52
You'd better get your Internet sarcasm detector checked.
54
Name:
Anonymous
2009-10-03 20:37
>>53
You forgot to use [sarcasm] tags
55
Name:
Anonymous
2009-10-03 20:41
>>52
How does someone this dumb know how to use the internet?
56
Name:
Anonymous
2009-10-03 20:54
>>55
say that to my face fucker and
not online and see what happens
57
Name:
Anonymous
2009-10-03 22:06
>>56
I would require your address and what hours you would be available to show me what would happen when I told you that to your face and not online.
58
Name:
Anonymous
2009-10-08 16:19
PHP:
$set = function ($bool) { $var = $bool; };
$var = $set(true);
if ($var == true) { echo 'var is true'; };
59
Name:
Anonymous
2010-11-25 21:01
60
Name:
Anonymous
2010-12-17 1:30
Are you GAY ?
Are you a NIGGER ?
Are you a GAY NIGGER ?
If you answered "Yes" to all of the above questions, then GNAA (GAY NIGGER ASSOCIATION OF AMERICA) might be exactly what you've been looking for!
61
Name:
Anonymous
2011-02-02 22:48