Tech Off Thread

16 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Best line of code ever

Back to Forum: Tech Off
  • User profile image
    Sampy

    Saw this today in C#:
    // x is some random string

    if (x != null || !"".Equals(x))
       ...

    That rules.

    Second place goes to:

    for(int x=0; x < y; x = ((x) + (1)))
       ...

  • User profile image
    Minh

    You forgot to Set Sarcasm = On, so for a little bit there, I thought you were out of your mind.

  • User profile image
    Manip

    Stop picking at my code! uhh opps [Runs Away]

  • User profile image
    littleguru

    wonderful examples Smiley life is that complex ...

  • User profile image
    draza

    These are worthy of submission to http://thedailywtf.com

    If you haven't checked this site out, you definitely need to Smiley

  • User profile image
    PhrostByte

    I've seen people do a good deal of weird stuff, two of my favorites:

    int i; i^=i; // optimization, makes i = 0, but faster.

    char str[32];
    strcpy(str, "foo");
    strcat(str, "\0"); // set null terminator

  • User profile image
    spod

    the first is sane in assembler( xor eax, eax is a fairly standard pattern ), but any optimizing compiler would generate this from int i=0 anyway.

    One i saw recently was

    // loop forever
    for( unsigned __int64 i = 1; i !=0; i++ )
    {
       // do something that takes about 1/100 sec.


    kind of hard to argue that it'll ever finish but...

  • User profile image
    Rossj

    spod wrote:

    // loop forever
    for( unsigned __int64 i = 1; i !=0; i++ )
    {
       // do something that takes about 1/100 sec.


    kind of hard to argue that it'll ever finish but...


    Won't it finish when it overflows?

  • User profile image
    Maurits

    Rossj wrote:
    spod wrote:
    // loop forever
    for( unsigned __int64 i = 1; i !=0; i++ )
    {
       // do something that takes about 1/100 sec.


    kind of hard to argue that it'll ever finish but...


    Won't it finish when it overflows?


    Yes, in about (UNSIGNED_INT_64_MAX / 100) seconds - a little under six billion years.

  • User profile image
    Dr. Shim

    1 1#9;

    Or for an infinite loop, do:

    1 1

    Fun! It's some silly language called Whenever. It executes code in whatever order, at random times.  Hope I'm not too off-topic, but I could hardly resist. Smiley

  • User profile image
    Sven Groot

    Another stupid programming language: Intercal.
    Statements must begin with DO, PLEASE or PLEASE DO. If you don't use PLEASE often enough, the compiler thinks you're rude and won't compile your program. If you use PLEASE too often, the compiler thinks you're sucking up to it, and won't compile your program. Wink

  • User profile image
    spod

    what about COW...that has to be my favorite...and its turing complete...

    http://www.bigzaphod.org/cow/

    here's some sample COW from the site to generate the fibonacci series

    MoO
    moO
    MoO
    mOo
    [[ main loop ]]
    MOO
    [[ print first number ]]
    OOM
    [[ temp copy of first number ]]
    MMM
    moO
    moO
    MMM
    mOo
    mOo
    [[ store second number off in the first position now ]]
    moO
    MMM
    mOo
    MMM
    [[ move back to temp number ]]
    moO
    moO
    [[ use temp to add to first and store in second in loop ]]
    MOO
    MOo
    mOo
    MoO
    moO
    moo
    mOo
    mOo
    moo
    

  • User profile image
    Maurits

    I like Ook!, personally

    EDIT: fibonacci generator in Ook!
    Ook# .Net

  • User profile image
    AndyC

    Oh please, the only sensible language in todays busy environment is Whitespace http://compsoc.dur.ac.uk/whitespace/index.php

    Smiley

  • User profile image
    spod

    YOu could be onto something here. You've read Bjarne Stroustup's plans for C++ 2000 in this area, right?

    http://www.research.att.com/~bs/whitespace98.pdf

  • User profile image
    MasterPi

    if(function_exists('disfunction')){ 
       settype($i,'genius');
    }

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.