C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-17-2002, 06:05 PM   #1
Code Goddess
 
Prelude's Avatar
 
Join Date: Sep 2001
Posts: 9,664
mmmm C#

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
__________________
My best code is written with the delete key.
Prelude is offline   Reply With Quote
Old 03-21-2002, 12:15 AM   #2
Something Clever
 
ginoitalo's Avatar
 
Join Date: Dec 2001
Posts: 187
This looks ok, (quasi C++ style)

Code:
class Print{

     public static void printNumber ( int n ){
         while ( n != 0 ) {
               Console.Write ( n % 10 );
               n /= 10;
          }
       Console.WriteLine();
     }

}
ginoitalo is offline   Reply With Quote
Old 03-21-2002, 03:00 PM   #3
Unregistered
Guest
 
Posts: n/a
Code:
class Print
{
     public static void printNumber(int n)
{
         while (n != 0) 
          {
               Console.Write(n % 10);
               n /= 10;
          }
       Console.WriteLine();
     }

}
  Reply With Quote
Old 03-25-2002, 09:31 AM   #4
Just one more wrong move.
 
-KEN-'s Avatar
 
Join Date: Aug 2001
Posts: 3,232
Quote:
Originally posted by Unregistered
Code:
class Print
{
     public static void printNumber(int n)
{
         while (n != 0) 
          {
               Console.Write(n % 10);
               n /= 10;
          }
       Console.WriteLine();
     }

}
that's dreadfully ugly. I just code like I usually do in C.
__________________
Gays can't love like real people

entropysink.com -- because arses weren't designed for running websites.
-KEN- is offline   Reply With Quote
Old 03-28-2002, 09:15 PM   #5
Registered User
 
CompiledMonkey's Avatar
 
Join Date: Feb 2002
Location: Richmond, VA
Posts: 438
Prelude, that's about the same code you'd use if doing the same thing in Java. It makes things much easier for a Java guy (like me) when the syntax is so similar.

I'd structure the code like this...

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);
	}
}
CompiledMonkey is offline   Reply With Quote
Old 03-28-2002, 09:21 PM   #6
S­énior Member
 
Join Date: Jan 2002
Posts: 982
>Prelude, that's about the same code you'd use if doing the same thing in Java

hmmm, I didn't realise Java imposed a particular style of code formating.
Sorensen is offline   Reply With Quote
Old 03-28-2002, 09:24 PM   #7
Registered User
 
CompiledMonkey's Avatar
 
Join Date: Feb 2002
Location: Richmond, VA
Posts: 438
Not the format in particular, but the actual code itself. Just a few changes. Example, instead of "Console.Write(n % 10);" it would be "System.out.println(n % 10);". Most of the code from this certain app could be "ported" like that.
CompiledMonkey is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mmmm beer -JM General Discussions 10 08-05-2005 05:22 PM
Mmmm, thats good antifreeze! RoD A Brief History of Cprogramming.com 1 04-03-2003 07:32 PM
text rpg adventure BuRtAiNiAn FlY Game Programming 13 07-20-2002 02:25 PM
Checking for connected workstations. Unregistered Windows Programming 3 06-22-2002 02:07 PM
IDE For C++ zzido Windows Programming 5 05-23-2002 01:16 PM


All times are GMT -6. The time now is 04:45 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22