PDA

View Full Version : I have a code review on Monday



baseline bum
04-19-2013, 10:39 PM
Can you guys help me optimize this? The entire project is centered around this piece of software I have been designing for a couple of months now:



// File: evenodd.c
// To compile: gcc -std=c99 -O3 -fomit-frame-pointer -fstrength-reduce -o evenodd.o -c evenodd.c

#include "evenodd.h"
#include <stdbool.h>

// is x odd?
bool is_odd(int);


// assumes x >= 0
bool is_even(int n)
{
if (n == 1) return false;
else return is_odd(n-1);
}

bool is_odd(int n)
{
return (n == 1)? true : is_even(n-1);
}


Any help would be appreciated.

ElNono
04-19-2013, 10:46 PM
:lmao

baseline bum
04-19-2013, 10:48 PM
:lmao

What are you laughing at? You know how many people strive for O(n) perforamnce in their algorithms?

ElNono
04-19-2013, 10:49 PM
#define is_odd(a) ((a) & 1)
#define is_even(a) !is_odd(a)

baseline bum
04-19-2013, 10:55 PM
#define is_odd(a) ((a) & 1)
#define is_even(a) !is_odd(a)

:cry No type checking. :cry

Unacceptable. Niggas think I'm scheming or some shit?

ElNono
04-19-2013, 10:56 PM
i've been writing csharp code lately and damn do I miss macros...

It's also retarded that nullable types are also not boolean...

object a = null;

if (a) <--- Error!!! You gotta do 'if (a != null)'
{
// blah
}

ElNono
04-19-2013, 11:00 PM
Also, can you believe Win8 Metro doesn't have standard date/time pickers or a calendar control?

XAML is also this Frankenstein construction you get the feeling was thought out by an amateur in some Indian backroom.

Which is amazing considering it's from the same people that wrote Intellisense for Visual Studio which is pretty much the shit.

ElNono
04-19-2013, 11:05 PM
Another gem: no built in support for timezones... you either work on 'local' time or UTC time...

I can't tell you how much shit I had to write on top of the actual project. And still have a long ways to go.

baseline bum
04-19-2013, 11:17 PM
i've been writing csharp code lately and damn do I miss macros...

It's also retarded that nullable types are also not boolean...

object a = null;

if (a) <--- Error!!! You gotta do 'if (a != null)'
{
// blah
}

Did you used to work at my company? This is a piece of legacy code that I got tasked with maintenance on.



// File: app.c
// To compile: gcc -O3 -fomit-frame-pointer -o app app.c

#include "stdio.h"
#define e 3
#define g (e/e)
#define h ((g+e)/2)
#define f (e-g-h)
#define j (e*e-g)
#define k (j-h)
#define l(x) tab2[x]/h
#define m(n,a) ((n&(a))==(a))

long tab1[]={ 989L,5L,26L,0L,88319L,123L,0L,9367L };
int tab2[]={ 4,6,10,14,22,26,34,38,46,58,62,74,82,86 };

main(m1,s) char *s; {
int a,b,c,d,o[k],n=(int)s;
if(m1==1){ char b[2*j+f-g]; main(l(h+e)+h+e,b); printf(b); }
else switch(m1-=h){
case f:
a=(b=(c=(d=g)<<g)<<g)<<g;
return(m(n,a|c)|m(n,b)|m(n,a|d)|m(n,c|d));
case h:
for(a=f;a<j;++a)if(tab1[a]&&!(tab1[a]%((long)l(n))))return(a);
case g:
if(n<h)return(g);
if(n<j){n-=g;c='D';o[f]=h;o[g]=f;}
else{c='\r'-'\b';n-=j-g;o[f]=o[g]=g;}
if((b=n)>=e)for(b=g<<g;b<n;++b)o[b]=o[b-h]+o[b-g]+c;
return(o[b-g]%n+k-h);
default:
if(m1-=e) main(m1-g+e+h,s+g); else *(s+g)=f;
for(*s=a=f;a<e;) *s=(*s<<e)|main(h+a++,(char *)m1);
}
}

ElNono
04-20-2013, 12:00 AM
lol Hello Word... those obfuscated codes are too much, tbh :lol

ElNono
04-20-2013, 12:03 AM
#define \
D(s)"<<"#s">>"
#define q(s)p(#s)
#define S " endobj "
#define Y "endstream"S
#include <stdio.h>
#define o(s) b[s]=_;\
p("%u 0 obj",s);
#define E for (c=d;c < 123;c++)
#define DANCE "trailer "D\
(/Root 3 0 R /Size %d) "\nstartxref %u %%%%EOF\n*/"
#define p(s, ...) _+=printf(s, ##__VA_ARGS__)
#define C "<</Type/Page /Parent %d %d R /Resources <<\
/ProcSet[ /PDF/Text]/Font <</U"D(/Subtype/Type1/BaseFont\
/Courier) " /T<</Subtype/Type3 /FontBBox[0 0 10 10]/FontMatrix[\
%f 0 0 %f 0 0]/FirstChar %d/LastChar %d/Encoding<</Differences[%d"
typedef int N;typedef char*Nyan;typedef char A;N a,b[64],d=65,_,v
[32]={84,0,64,282,90,74,330,85,93,173,167,176,80,208,8 1,13,7,87
,160,346,32,128,170,218,16,26}; Nyan w[]={"+*-(,&-&","+*,&-&"
,"+*.&/&","+*/*/+","+*())'('" ,"+**&)&","+*(&'&","+*'*'+",
"","+,./","+,-,./","+--,+*" ,"","+,(/","+,),(/","+-),+*"
,"10 0 d0 ","8 7 2 2 re " ,"+*+.'`'@'mi +/+/(mi"};Nyan
nyan(Nyan _,N y,A n){
N g=v[~-y%32];Nyan
s=w[g>>n&3|n*2];
for(a=0;*_=*s++;
a++,_++,*_++=32)
{*_+=*_-32?10:0;
if(a%2&&*_/16==3
){if(g>>8)*_=105-*_;
_++;*_++=32;*_=~-a&&a-13
?108:109;}}return n?n-9?nyan
(_,y,n-2):_:nyan(_+=~y&' '?sprintf
(_,17[w]):0,y,9);}N main(N c){A e[256];
p("/*%%PDF-1.3%%*/")-2;q(#include<stdio.h>\n);
q(#define o *_++&& *_-41\n#define);p(" endstream ");q
(main(){for(;*_++; *_-40?:putchar(o?*_:o?10:41));\n)
;q(#define endobj return 0;}\n);q(typedef int ET;/)
;q(*);o(1)*b=~(p(D (/Length 2 0 R)"stream\n"))
;for(p("BT 12 818" " Td/%c 12 Tf 12 TL%%%c/"
"static char*_=\"" " \\\n",7[v],*v/2);c=
getchar(),~c;c-10? p("/%c 12 Tf(\\%o)"
"Tj",v[~-c%' '<25[ v]&&!~-(~-c/'@')?0
:7],c):(p("()'"))) ;p("%%\";\nET ");*
b-=~_;p(Y"/*");E{a =nyan(e+sprintf(e,
16[w]),c,6)-e;o(c- 59)p(D(/Length %d)
"stream\n%s"Y,a,e) ;}o(2)p(" %u"S,*b);
o(3)p(D(/Pages 4 0 R)S);o(4)p(D(/Count
1/MediaBox[0 0 595 842]/Kids[5 0 R])S)
;o(5)p(C,4,0,6e-2, 6e-2f,d,122,d);E p(
"/%c",~-c/6+~14?c: d);q(]>>/CharProcs<<)
;E if(~-c/6+~14)p( "/%c %d 0 R",c,c+~58);
for(q(>>/Widths[), c=59;--c;p(" 10"));a=p
("]>>>>>>/Contents 1 0 R>>"S);for(p("xref\
0 %d ",--d);c<d;p("%010u\
%05d n ",*(c+++b),NULL));
return!(p(DANCE,d,a));}


:lmao

baseline bum
04-20-2013, 12:25 AM
Oh my god, the output of that dancing man program given that hello world as input :lmao

http://i.imgur.com/JbfRDzb.png

ElNono
04-20-2013, 12:36 AM
it says you can compile the PDF with gcc and it works too :lol

baseline bum
04-20-2013, 12:43 AM
it says you can compile the PDF with gcc and it works too :lol

gcc made me rename it to a .c file and then its output was the original c file: say the dancing program is named dance



parker@lolmexico:~/Desktop$ ./dance <app.c >app.pdf
parker@lolmexico:~/Desktop$ cp app.pdf foo.c
parker@lolmexico:~/Desktop$ gcc foo.c
parker@lolmexico:~/Desktop$ ./a.out
// File: app.c
// To compile: gcc -O3 -fomit-frame-pointer -o app app.c

#include "stdio.h"
#define e 3
#define g (e/e)
#define h ((g+e)/2)
#define f (e-g-h)
#define j (e*e-g)
#define k (j-h)
#define l(x) tab2[x]/h
#define m(n,a) ((n&(a))==(a))

long tab1[]={ 989L,5L,26L,0L,88319L,123L,0L,9367L };
int tab2[]={ 4,6,10,14,22,26,34,38,46,58,62,74,82,86 };

main(m1,s) char *s; {
int a,b,c,d,o[k],n=(int)s;
if(m1==1){ char b[2*j+f-g]; main(l(h+e)+h+e,b); printf(b); }
else switch(m1-=h){
case f:
a=(b=(c=(d=g)<<g)<<g)<<g;
return(m(n,a|c)|m(n,b)|m(n,a|d)|m(n,c|d));
case h:
for(a=f;a<j;++a)if(tab1[a]&&!(tab1[a]%((long)l(n))))return(a);
case g:
if(n<h)return(g);
if(n<j){n-=g;c='D';o[f]=h;o[g]=f;}
else{c='\r'-'\b';n-=j-g;o[f]=o[g]=g;}
if((b=n)>=e)for(b=g<<g;b<n;++b)o[b]=o[b-h]+o[b-g]+c;
return(o[b-g]%n+k-h);
default:
if(m1-=e) main(m1-g+e+h,s+g); else *(s+g)=f;
for(*s=a=f;a<e;) *s=(*s<<e)|main(h+a++,(char *)m1);
}
}parker@lolmexico:~/Desktop$

ElNono
04-20-2013, 01:22 AM
thats pretty cool :lol

MannyIsGod
04-22-2013, 04:22 PM
Fucking nerds.

MannyIsGod
04-22-2013, 04:22 PM
I'm fucking happy if I can actually get matlab to run my simple scripts.

baseline bum
04-22-2013, 06:28 PM
It was approved for our library, as my function cut the stack depth from O(n^2) (prev version) to O(n) while still maintaining fast O(n) timing.

TDMVPDPOY
04-23-2013, 08:13 AM
surprise u clowns still in the programming business...

DarrinS
04-23-2013, 09:22 AM
Also, can you believe Win8 Metro doesn't have standard date/time pickers or a calendar control?

XAML is also this Frankenstein construction you get the feeling was thought out by an amateur in some Indian backroom.

Which is amazing considering it's from the same people that wrote Intellisense for Visual Studio which is pretty much the shit.



XAML is pretty much a ripoff of SVG. Just as C# is just a ripoff of Java. Or maybe just heavily influenced.

With Win8, I really can't tell where MS is headed with their development platform.

DarrinS
04-23-2013, 09:30 AM
I'm fucking happy if I can actually get matlab to run my simple scripts.

I love Matlab. Been using it since late 1980's. I'm on ver R2012b now.

DarrinS
04-23-2013, 09:37 AM
i've been writing csharp code lately and damn do I miss macros...

It's also retarded that nullable types are also not boolean...

object a = null;

if (a) <--- Error!!! You gotta do 'if (a != null)'
{
// blah
}


Some parts of the language are pretty dumb, but I have to admit, it is very readable. Also, LINQ is very powerful.

MannyIsGod
04-23-2013, 10:26 AM
I love Matlab. Been using it since late 1980's. I'm on ver R2012b now.

I love it too. I just am terrible at writing scripts to get what I want done. Its probably just a practice/familiarity thing so hopefully I will get better over time.

DarrinS
04-23-2013, 10:41 AM
I love it too. I just am terrible at writing scripts to get what I want done. Its probably just a practice/familiarity thing so hopefully I will get better over time.

They also have a very good user community -- very friendly and willing to answer all types of technical questions.

baseline bum
04-23-2013, 04:22 PM
I love it too. I just am terrible at writing scripts to get what I want done. Its probably just a practice/familiarity thing so hopefully I will get better over time.

You ever seen OCW's quick Matlab course, Manny?

http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-094-introduction-to-matlab-january-iap-2010/

Pretty cool shit, especially the assignment on plotting the Mandelbrot set. There is another one that looks like a more full course:

http://ocw.mit.edu/courses/mathematics/18-s997-introduction-to-matlab-programming-fall-2011/

ElNono
04-23-2013, 05:06 PM
XAML is pretty much a ripoff of SVG. Just as C# is just a ripoff of Java. Or maybe just heavily influenced.

With Win8, I really can't tell where MS is headed with their development platform.

The problem with XAML, IMO, is that's a little monster. It has, as you said, a lot of SVG stuff, but also some of HTML and then they took all their controls and stuffed it in there too.

Copying a template for a simple button is this long turd of XML, with hordes of visual states and a third of the shit is either poorly documented or not documented at all.

I suspect Blend was supposed to make all of this easier by making it 'visual', but it simply moved the turd from a text view to a tree view.


Some parts of the language are pretty dumb, but I have to admit, it is very readable. Also, LINQ is very powerful.

Do you use LINQ that much outside of the type converters?

DarrinS
04-23-2013, 05:14 PM
The problem with XAML, IMO, is that's a little monster. It has, as you said, a lot of SVG stuff, but also some of HTML and then they took all their controls and stuffed it in there too.

Copying a template for a simple button is this long turd of XML, with hordes of visual states and a third of the shit is either poorly documented or not documented at all.

I suspect Blend was supposed to make all of this easier by making it 'visual', but it simply moved the turd from a text view to a tree view.


I suppose it's like any markup language. If you put all the styles inline, and don't use something like CSS, it can get pretty nasty. I tend to make my xaml very simple and let others to the "styling".




Do you use LINQ that much outside of the type converters?


You can do a lot of stuff with arrays using LINQ like set operations. The cool thing is, it is very generic and will on arrays of all types (even arrays of your own objects). The LINQ syntax takes some getting used to.

ElNono
04-23-2013, 07:15 PM
I suppose it's like any markup language. If you put all the styles inline, and don't use something like CSS, it can get pretty nasty. I tend to make my xaml very simple and let others to the "styling".

I do keep separate XAML files. It's still nasty, IMO. Good for you that you can drop off the styling to somebody else. No such luck here.


You can do a lot of stuff with arrays using LINQ like set operations. The cool thing is, it is very generic and will on arrays of all types (even arrays of your own objects). The LINQ syntax takes some getting used to.

That's what I noticed. This current project uses a sqlite backend, so we let the DB do all the filtering for us, and don't have to muck much with arrays at all. Outside of the syntax, it's pretty similar to NSPredicate on iOS/Cocoa.

DarrinS
04-24-2013, 09:22 AM
Elnono,

Are you developing a Silverlight app? Just curious.

ElNono
04-24-2013, 12:40 PM
Elnono,

Are you developing a Silverlight app? Just curious.

Windows Store App. I'm porting over our flagship iOS app, but obviously it's a full re-write and it has to have the Win8 looks.

DarrinS
04-24-2013, 12:54 PM
Windows Store App. I'm porting over our flagship iOS app, but obviously it's a full re-write and it has to have the Win8 looks.

Cool. I'd like to get into mobile development.

ElNono
04-24-2013, 02:58 PM
Cool. I'd like to get into mobile development.

Well, this version is for Tablets/Desktops (RT/Metro). We're not targeting Windows Phone at the moment.