I have to admit my first reaction to C# was hostile. Being a card carrying member of the 'Java haters' club the syntax was a big turnoff for me at first glance. Now that I've studied a bit of C# I'm warming up to it, and what I first believed to be a wasteful syntax isn't quite as wasteful as I first thought ( Believing C# to be a Java ripoff ).
Here are two quickie programs that show size differences between C# and my beloved C.
Code:
// C# code
using System;
class Print
{
public static void printNumber ( int n )
{
while ( n != 0 ) {
Console.Write ( n % 10 );
n /= 10;
}
Console.WriteLine();
}
}
class ProgramDriver
{
public static void Main()
{
Print.printNumber ( 45678 );
}
}
Code:
/* C code */
#include <stdio.h>
#include <stdlib.h>
void printNumber ( int n )
{
while ( n != 0 ) {
printf ( "%d", n % 10 );
n /= 10;
}
printf ( "\n" );
}
int main ( void )
{
printNumber ( 45678 );
return EXIT_SUCCESS;
}
I still don't like how the functions ( methods ) float in space while C's functions are completely left justified. It forces me to use a GNU bracing style to maintain somewhat decent readability.
Does anyone have ideas for a C# bracing style that works well? This textbook code just doesn't do it for me ( I hate textbook code )
Code:
// Yucky yucky
class Print
{
public static void printNumber ( int n )
{
while ( n != 0 )
{
Console.Write ( n % 10 );
n /= 10;
}
Console.WriteLine();
}
}
At the moment I'm using three bracing styles according to indention level. Class level indention ( fully left justified ) gets an Allman style, method level ( first level in, very floaty ) practically demands GNU to look good, and for the processing level ( if..else's, loops, switches, etc.. ) I maintain my K&R bracing.
-Prelude