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

antipython fags: REKT

Name: Anonymous 2015-02-07 23:59

The formatting or appearance of code determines how quickly and easily the reader can understand what it does. A compiler will see no difference between this...

// Example 1: unformatted code.
public class Functions
{
public static int fibonacci(int n)
{
if (n < 2)
{
return 1;
}
return fibonacci(n-2) + fibonacci(n-1);
}

public static void main(String[] arguments)
{
for(int i=0;i<10;i++)
{
print(“Input value:”+i+” Output value:”+power(fibonacci(i), 2)+1);
}
}
}

...and this...

//Example 2: formatted code.

public class Functions
{
public static int fibonacci(int n)
{
if (n < 2)
{
return 1;
}
return fibonacci(n-2) + fibonacci(n-1);
}

public static void main(String[] arguments)
{
for (int i = 0; i < 10; i++)
{
print(“Input value:” + i +
” Output value:” +
power(fibonacci(i), 2) + 1);
}
}
}

...but the second example will be more easily understood by the reader.

Name: Anonymous 2015-02-08 8:31

Lambda fibs are quite lovely with python's one-line lambda syntax.

print ((lambda f: (lambda x: x(x))(lambda y: f(lambda a: lambda b: y(y)(a)(b))))(lambda f: lambda s: lambda i: (lambda pr: pr(lambda a: lambda d: a))(s) if i == 0 else f((lambda s: (lambda p: p(lambda a: lambda d: d))(s)())(s))(i-1)))((lambda f: (lambda x: x(x))(lambda y: f(lambda a: lambda b: y(y)(a)(b))))(lambda f: lambda a: lambda b: (lambda a: lambda d: lambda f: f(a)(d))(a)(lambda : f(b)(a+b)))(0)(1))

try calling it with a number :-)

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