Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Code that may or may not pass muster

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');

Name: Anonymous 2009-10-01 2:48

printf
Problem found! printf will bottleneck your code, especially when dealing with matrixen'

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.

Name: Anonymous 2009-10-01 3:41

printf("%.1f%c", *e, ((e - matrix + 1)%size)?'\t':'\n');

Better.

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?

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..

Name: Anonymous 2009-10-01 4:40

>>6
My are comparison will make use of an instruction like x86's JNE.

Name: Anonymous 2009-10-01 5:06

>>7
Several clock cycles slower than using JNZ.

Name: Anonymous 2009-10-01 5:23

>>7
Not everyone uses a toy processor architecture like x86

Name: Anonymous 2009-10-01 6:12

>>9
x86 doesn't has enough power for toys, they use ARM.

Name: Anonymous 2009-10-01 6:20

>>10
doesn't has
english isn't your first language

Name: Anonymous 2009-10-01 6:24

>>11
that's the kind of attitude hitler had

Name: Anonymous 2009-10-01 6:26

>>12
I am not an anti-semite

Name: Anonymous 2009-10-01 6:28

>>11
grammar nazis in MY /prog/???
are we getting raided by gaia or something?

Name: Anonymous 2009-10-01 6:38

>>14
Non-sense, gaia has much more culture and posts are at least 10 times bigger.

Name: Anonymous 2009-10-01 6:40

>>14
IHBT

Name: Anonymous 2009-10-01 7:24

>>14
You're not clever.

Name: Anonymous 2009-10-01 8:04

>>17
that hurts.
really.
D:

Name: Anonymous 2009-10-01 8:20

printf("%c", ********c);

That was pretty deep

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
}

Name: Anonymous 2009-10-01 8:35

>>20
|⌒彡
|冫、)
|` /

Name: Anonymous 2009-10-01 8:36

>>21
lol hy

Name: Anonymous 2009-10-01 8:37

>>21
is that the boy twin from rugrats?

Name: Anonymous 2009-10-01 8:38

>>20
what the hell?
i assume that if(0) functions the same as break;.
GENIUS!

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

Name: Anonymous 2009-10-01 8:46

>>25
mind == blown
amazing

Name: Anonymous 2009-10-01 8:51

>>25
thats gay

Name: Anonymous 2009-10-01 8:52

>>27
your gay

Name: Anonymous 2009-10-01 9:08

>>20
haha
try doing that in haskell. oh wait. U CANT BCUZ HASKELL SUCKS

Name: Anonymous 2009-10-01 9:30

>>20
OH GOD IT'S SO BEAUTIFUL!

Name: Anonymous 2009-10-01 10:04

>>20
sweet bro

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?

Name: Anonymous 2009-10-01 10:33

>>32
A language... with call/cc.

Name: Anonymous 2009-10-01 10:39

>>33
call-with-current-continuation-because-yo-momma-said-so

Name: Anonymous 2009-10-01 12:09

ENTERPRISE QUALITY

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

Name: Anonymous 2009-10-01 13:12

>>32
Inb4 someone writes a Goto Monad

Name: Anonymous 2009-10-01 13:26

>>36
c <- getChar
let str' = str ++ filter (not . flip elem str) [c]

Name: Anonymous 2009-10-01 13:30

>>37
main = runBASIC' $ do
    10 PRINT "Already done."
    20 GOTO 10

Name: Anonymous 2009-10-01 13:37

>>39
This is why I hate Haskellers >:-|

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List