What's the craziest code you ever read?
Katie Nelson

Katie Nelson @katnel20

About: Welcome tag moderator AKA Unofficial DEV cheerleader. While most of my friends are found on SnapChat or Tic-Toc, you can find me here. And I OOP, but I’m not a VSCO girl.

Location:
New England (GMT -4:00)
Joined:
Oct 10, 2019

What's the craziest code you ever read?

Publish Date: Oct 21 '19
11 13

A while back, I saw some JavaScript where every var and function in the file was named after a type of fruit.
It look something like:

grapes.forEach(function(grape) {
  if(grape < 10)
      apple += orange;
});

We decided to name the unknown coder Fruitcake, although the code was running as expected.
The crazy part was having to read it all to see how it actually worked in order to just add a single new feature.

Has anyone else come across something like this?

Comments 13 total

  • Fulton Browne
    Fulton BrowneOct 21, 2019

    This code for a robot drive

            float FrontLeft = -gamepad1LeftY - gamepad1LeftX - gamepad1RightX;
            float FrontRight = gamepad1LeftY - gamepad1LeftX - gamepad1RightX;
            float BackRight = gamepad1LeftY + gamepad1LeftX - gamepad1RightX;
            float BackLeft = -gamepad1LeftY + gamepad1LeftX - gamepad1RightX;
    
            FrontRight = Range.clip(FrontRight, -1, 1);
            FrontLeft = Range.clip(FrontLeft, -1, 1);
            BackLeft = Range.clip(BackLeft, -1, 1);
            BackRight = Range.clip(BackRight, -1, 1);    
            motorFrontRight.setPower(FrontRight);
            motorFrontLeft.setPower(FrontLeft);
            motorBackLeft.setPower(BackLeft);
            motorBackRight.setPower(BackRight);
    
  • Austin S. Hemmelgarn
    Austin S. HemmelgarnOct 21, 2019

    Do entries for the International Obfuscated C Code Contest count?

    In all seriousness, I've yet to see code that is more intentionally obtuse than some of the entries there (unless you count esolangs, in which case almost anything written in INTERCAL takes the cake in my opinion), with Toledo Nanochess being a particularly famous example, though my favorite example is the 1998 winner:

    #include                                     <math.h>
    #include                                   <sys/time.h>
    #include                                   <X11/Xlib.h>
    #include                                  <X11/keysym.h>
                                              double L ,o ,P
                                             ,_=dt,T,Z,D=1,d,
                                             s[999],E,h= 8,I,
                                             J,K,w[999],M,m,O
                                            ,n[999],j=33e-3,i=
                                            1E3,r,t, u,v ,W,S=
                                            74.5,l=221,X=7.26,
                                            a,B,A=32.2,c, F,H;
                                            int N,q, C, y,p,U;
                                           Window z; char f[52]
                                        ; GC k; main(){ Display*e=
     XOpenDisplay( 0); z=RootWindow(e,0); for (XSetForeground(e,k=XCreateGC (e,z,0,0),BlackPixel(e,0))
    ; scanf("%lf%lf%lf",y +n,w+y, y+s)+1; y ++); XSelectInput(e,z= XCreateSimpleWindow(e,z,0,0,400,400,
    0,0,WhitePixel(e,0) ),KeyPressMask); for(XMapWindow(e,z); ; T=sin(O)){ struct timeval G={ 0,dt*1e6}
    ; K= cos(j); N=1e4; M+= H*_; Z=D*K; F+=_*P; r=E*K; W=cos( O); m=K*W; H=K*T; O+=D*_*F/ K+d/K*E*_; B=
    sin(j); a=B*T*D-E*W; XClearWindow(e,z); t=T*E+ D*B*W; j+=d*_*D-_*F*E; P=W*E*B-T*D; for (o+=(I=D*W+E
    *T*B,E*d/K *B+v+B/K*F*D)*_; p<y; ){ T=p[s]+i; E=c-p[w]; D=n[p]-L; K=D*m-B*T-H*E; if(p [n]+w[ p]+p[s
    ]== 0|K <fabs(W=T*r-I*E +D*P) |fabs(D=t *D+Z *T-a *E)> K)N=1e4; else{ q=W/K *4E2+2e2; C= 2E2+4e2/ K
     *D; N-1E4&& XDrawLine(e ,z,k,N ,U,q,C); N=q; U=C; } ++p; } L+=_* (X*t +P*M+m*l); T=X*X+ l*l+M *M;
      XDrawString(e,z,k ,20,380,f,17); D=v/l*15; i+=(B *l-M*r -X*Z)*_; for(; XPending(e); u *=CS!=N){
                                       XEvent z; XNextEvent(e ,&z);
                                           ++*((N=XLookupKeysym
                                             (&z.xkey,0))-IT?
                                             N-LT? UP-N?& E:&
                                             J:& u: &h); --*(
                                             DN -N? N-DT ?N==
                                             RT?&u: & W:&h:&J
                                              ); } m=15*F/l;
                                              c+=(I=M/ l,l*H
                                              +I*M+a*X)*_; H
                                              =A*r+v*X-F*l+(
                                              E=.1+X*4.9/l,t
                                              =T*m/32-I*T/24
                                               )/S; K=F*M+(
                                               h* 1e4/l-(T+
                                               E*5*T*E)/3e2
                                               )/S-X*d-B*A;
                                               a=2.63 /l*d;
                                               X+=( d*l-T/S
                                                *(.19*E +a
                                                *.64+J/1e3
                                                )-M* v +A*
                                                Z)*_; l +=
                                                K *_; W=d;
                                                sprintf(f,
                                                "%5d  %3d"
                                                "%7d",p =l
                                               /1.7,(C=9E3+
                                  O*57.3)%0550,(int)i); d+=T*(.45-14/l*
                                 X-a*130-J* .14)*_/125e2+F*_*v; P=(T*(47
                                 *I-m* 52+E*94 *D-t*.38+u*.21*E) /1e2+W*
                                 179*v)/2312; select(p=0,0,0,0,&G); v-=(
                                  W*F-T*(.63*m-I*.086+m*E*19-D*25-.11*u
                                   )/107e2)*_; D=cos(o); E=sin(o); } }
    

    Which is a flight simulator for X11.

    • Katie Nelson
      Katie NelsonOct 21, 2019

      That code is pretty!

    • Fulton Browne
      Fulton BrowneOct 21, 2019

      that is AWESOME

      • Austin S. Hemmelgarn
        Austin S. HemmelgarnOct 21, 2019

        There have been a number of other interesting entries over the years. I can't find it right now, but I distinctly remember one older entry that was valid C89, FORTRAN77, and Bourne shell script which did the same thing in all three languages.

  • Ryan
    RyanOct 21, 2019

    This hello world program in Brainf*ck confused me when I first saw it.

    +[-[<<[+[--->]-[<<<]]]>>>-]>-.---.>..>.<<<<-.<+.>>>>>.>.<<.<-.
    
  • Shannon Crabill
    Shannon CrabillOct 21, 2019

    Now I'm hungry, thanks.

  • NovemberKilo
    NovemberKiloOct 22, 2019

    Yung code nung ka oofficemate ko

  • Ardalan
    ArdalanOct 22, 2019

    var multiDArray = [[7,8], [3,4], [1,2], [5,6]];
    multiDArray.sort(function(a,b){
    return a[0] - b[0];
    });
    console.log(multiDArray); //returns [[1,2], [3,4], [5,6], [7,8]];

    You want to perform an operation on each element inside an array, in ascending order.
    The forEach() method allows you to perform a callback function on each element of the array, in ascending order.

    var myArray = [9, 2, 7, 6, 8, 5, 3];
    myArray.forEach(function(element, index, array){
    console.log(element + ' element'); //returns 9, 2, 7, 6, 8, 5, 3
    console.log(element + ' index '); //returns 0 ,1, 2, 3, 4, 5, 6
    .....
    });

    You need an array of only the elements that meet some certain criteria.
    var myArray = [9, 2, 7, 6, 8, 5, 3];
    var elementsOver5 = myArray.filter(function(element){
    return element > 5;
    });

    You want to reduce the elements into a single value.
    var numArray = [1,2,3,4,5,6];
    var reducedValue = numArray.reduce(function(prev, current){
    return prev + current;
    });

    You need to find either the largest or smallest number in an array.
    var numArray = [2,2,3,6,7,7,7,7,8,9];
    console.log(Math.max.apply(null, numArray));

  • Hee Z
    Hee ZOct 22, 2019
    try {
    
    } finally { // should never happen 
    
    }
    
  • Mohammad Hossein Moayeri (Web Programmer)
    Mohammad Hossein Moayeri (Web Programmer)Dec 16, 2019

    no , I haven't. But when programmers work as a team, they should write the variables,constants and etc with proper names , so that when their coworkers & even themselves see the code, they could grasp a slight understanding of what's happening inside the code. unfortunitely it's impossible to define a global standard for writing proper variable names

  • Madza
    MadzaJan 26, 2020

    The Game of Life by Linus Akesson:

                                Linus Akesson presents:
                       The Game Of Life implemented in Brainf***
    
           +>>++++[<++++>-]<[<++++++>-]+[<[>>>>+<<<<-]>>>>[<<<<+>>>>>>+<<-]<+
       +++[>++++++++<-]>.[-]<+++[>+++<-]>+[>>.+<<-]>>[-]<<<++[<+++++>-]<.<<[>>>>+
     <<<<-]>>>>[<<<<+>>>>>>+<<-]<<[>>>>.+<<<++++++++++[<[>>+<<-]>>[<<+>>>>>++++++++
     +++<<<-]<[>+<-]>[<+>>>>+<<<-]>>>[>>>>>>>>>>>>+>+<<     <<<<<<<<<<<-]>>>>>>>>>>
    >>[-[>>>>+<<<<-]>[>>>>+<<<<-]>>>]>      >>[<<<+>>  >-    ]<<<[>>+>+<<<-]>[->[<<<
    <+>>>>-]<[<<<  <+>      >>>-]<<<< ]<     ++++++  ++       +[>+++++<-]>>[<<+>>-]<
    <[>---<-]>.[- ]         <<<<<<<<< <      <<<<<< <         -]++++++++++.[-]<-]>>>
    >[-]<[-]+++++           +++[>++++        ++++<     -     ]>--.[-]<,----------[<+
    >-]>>>>>>+<<<<< <     <[>+>>>>>+>[      -]<<<      <<   <<-]>++++++++++>>>>>[[-]
    <<,<<<<<<<->>>> >    >>[<<<<+>>>>-]<<<<[>>>>+      >+<<<<<-]>>>>>----------[<<<<
    <<<<+<[>>>>+<<<      <-]>>>>[<<<<+>>>>>>+<<-      ]>[>-<-]>++++++++++[>+++++++++
    ++<-]<<<<<<[>>>      >+<<<<-]>>>>[<<<<+>>>>>      >+<<-]>>>>[<<->>-]<<++++++++++
    [>+<-]>[>>>>>>>      >>>>>+>+<<<<      <<<<<      <<<<-]>>> >>     >>>>>>>[-[>>>
    >+<<<<-]>[>>>>       +<<<<-]>> >       ]>> >           [<< <        +>>>-]+<<<[>
    >>-<<<-]>[->[<      <<<+>>>>-]         <[ <            < <           <+>>>>-]<<<
    <]<<<<<<<<<<<, [    -]]>]>[-+++        ++               +    +++     ++[>+++++++
    ++++>+++++++++ +    +<<-]>[-[>>>      +<<<-      ]>>>[ <    <<+      >>>>>>>+>+<
    <<<<-]>>>>[-[> >    >>+<<<<-]>[>      >>>+< <    <<-]> >    >]>      >>[<<<+>>>-
    ]<<<[>>+>+<<< -     ]>[->[<<<<+>      >>>-] <    [<<< <    +>>       >>-]<<<<]<<
    <<<<<<[>>>+<< <     -]>>>[<<<+>>      >>>>> +    >+<< <             <<-]<<[>>+<<
    -]>>[<<+>>>>>      >+>+<<<<<-]>>      >>[-[ >    >>>+ <            <<<-]>[>>>>+<
    <<<-]>[>>>>+<      <<<-]>>]>>>[ -    ]<[>+< -    ]<[ -           [<<<<+>>>>-]<<<
    <]<<<<<<<<]<<      <<<<<<<<++++ +    +++++  [   >+++ +    ++++++[<[>>+<<-]>>[<<+
    >>>>>++++++++ +    ++<<<     -] <    [>+<- ]    >[<+ >    >>>+<<<-]>>>[<<<+>>>-]
    <<<[>>>+>>>>  >    +<<<<     <<      <<-]> >    >>>>       >>>[>>+<<-]>>[<<+<+>>
    >-]<<<------ -    -----[     >>      >+<<< -    ]>>>       [<<<+> > >>>>>+>+<<<<
    <-]>>>>[-[>> >    >+<<<<    -] >     [>>>> +    <<<<-       ]>>> ]  >>>[<<<+>>>-
    ]<<<[>>+>+<< <    -]>>>     >>           > >    [<<<+               >>>-]<<<[>>>
    +<<<<<+>>-                  ]>           >     >>>>>[<             <<+>>>-]<<<[>
    >>+<<<<<<<                  <<+         >      >>>>>-]<          <<<<<<[->[<<<<+
    >>>>-]<[<<<<+>>>>-]<<<<]>[<<<<<<    <+>>>      >>>>-]<<<<     <<<<<+++++++++++[>
    >>+<<<-]>>>[<<<+>>>>>>>+>+<<<<<-]>>>>[-[>     >>>+<<<<-]>[>>>>+<<<<-]>>>]>>>[<<<
    +>>>-]<<<[>>+>+<<<-]>>>>>>>[<<<+>>>-]<<<[     >>>+<<<<<+>>-]>>>>>>>[<<<+>>>-]<<<
    [>>>+<<<<<<<<<+>>>>>>-]<<<<<<<[->[< <  <     <+>>>>-]<[<<<<+>>>>-]<<<<]>[<<<<<<<
    +>>>>>>>-]<<<<<<<<<+++++++++++[>>> >        >>>+>+<<<<<<<<-]>>>>>>>[-[>>>>+<<<<-
    ]>[>>>>+<<<<-]>>>]>>>[<<<+>>>-]<<< [       >>+>+<<<-]>>>>>>>[<<<+>>>-]<<<[>>>+<<
    <<<+>>-]>>>>>>>[<<<+>>>-]<<<[>>>+<        <<<<<<<<+>>>>>>-]<<<<<<<[->[<<<<+>>>>-
     ]<[<<<<+>>>>-]<<<<]>[<<<<<<<+>>>>>      >>-]<<<<<<<----[>>>>>>>+<<<<<<<+[>>>>>
     >>-<<<<<<<[-]]<<<<<<<[>>>>>>>>>>>>+>+<<<<<<<<<<<<<-][   lft@df.lth.se   ]>>>>>
       >>>>>>>[-[>>>>+<<<<-]>[>>>>+<<<<-]>[>>>>+<<<<-]>>]>>>[-]<[>+<-]<[-[<<<<+>>
           >>-]<<<<]<<<<<<[-]]<<<<<<<[-]<<<<-]<-]>>>>>>>>>>>[-]<<]<<<<<<<<<<]
    
            Type for instance "fg" to toggle the cell at row f and column g
                       Hit enter to calculate the next generation
                                     Type q to quit
    
Add comment