Post: My first program C# :)
05-16-2013, 01:37 PM #1
Dr. Tiga
Little One
(adsbygoogle = window.adsbygoogle || []).push({}); Hello NGU,
So today i bought C# for dummies, and with my previous java knowledge i made a little program. Im posting it here to hear some feedback on my coding style, and/or if you like the program.

Text:
You must login or register to view this content.

.Exe:
You must login or register to view this content.

~IcedTiga

The following 2 users say thank you to Dr. Tiga for this useful post:

Pichu, slim355

The following user groaned Dr. Tiga for this awful post:

Dhaax.
05-16-2013, 02:27 PM #2
Master Ro
I make food
Originally posted by IcedTiga View Post
Hello NGU,
So today i bought C# for dummies, and with my previous java knowledge i made a little program. Im posting it here to hear some feedback on my coding style, and/or if you like the program.

Text:
You must login or register to view this content.

.Exe:
You must login or register to view this content.

~IcedTiga



Using goto tags can create spaghetti code. I recommend to never use them :p

Why are you outputting null strings to the console also? You can use \n instead.

    
string[] wordsToOutput = { "Options:", "Change Password - 1", "Change Username - 2", "Logout - 3" };
string outputStr = null;


for( int i = 0; i < wordsToOutput.Length; ++i )
outputStr += wordsToOutput[i] + "\n";

Console.WriteLine(outputStr);


Or you could just hardcode the string into the string parameter for Console.WriteLine();

This is just teaching you some new methods :p
Last edited by Master Ro ; 05-16-2013 at 02:33 PM.
05-16-2013, 02:29 PM #3
Pichu
RIP PICHU.
Looks good, could use a little cleaning up with the text on the cmd screen but other than that; it's a start.

---------- Post added at 07:29 AM ---------- Previous post was at 07:28 AM ----------

Originally posted by Master
Using goto tags can create spaghetti code. I recommend to never use them :p


I actually disagree with that. I find them highly useful but when overused or not properly commented, then it can cause issues.
05-16-2013, 02:41 PM #4
Dr. Tiga
Little One
Originally posted by Master
Using goto tags can create spaghetti code. I recommend to never use them :p

Why are you outputting null strings to the console also? You can use \n instead.

    
string[] wordsToOutput = { "Options:", "Change Password - 1", "Change Username - 2", "Logout - 3" };
string outputStr = null;


for( int i = 0; i < wordsToOutput.Length; ++i )
outputStr += wordsToOutput[i] + "\n";

Console.WriteLine(outputStr);


Or you could just hardcode the string into the string parameter for Console.WriteLine();

This is just teaching you some new methods :p


Originally posted by Pichu View Post
Looks good, could use a little cleaning up with the text on the cmd screen but other than that; it's a start.

---------- Post added at 07:29 AM ---------- Previous post was at 07:28 AM ----------



I actually disagree with that. I find them highly useful but when overused or not properly commented, then it can cause issues.


Thx guys :P, i did clean up my on screen writing a lot xD its very clean now. However i really like goto and i think ill keep using it, thx anyways Master Ro
05-16-2013, 10:10 PM #5
Master Ro
I make food
Originally posted by Pichu View Post
Looks good, could use a little cleaning up with the text on the cmd screen but other than that; it's a start.

---------- Post added at 07:29 AM ---------- Previous post was at 07:28 AM ----------



I actually disagree with that. I find them highly useful but when overused or not properly commented, then it can cause issues.



We all have our preferences Smile. I just think that when a programmer is reading a piece of code and sees a goto, he has to go back up and find the specified block. For me it gets really tiring after a while. I just think it makes the code somewhat less readable.

:p
05-16-2013, 10:18 PM #6
Pichu
RIP PICHU.
Originally posted by Master
We all have our preferences Smile. I just think that when a programmer is reading a piece of code and sees a goto, he has to go back up and find the specified block. For me it gets really tiring after a while. I just think it makes the code somewhat less readable.

:p


Well, that's why you name the goto something relating to what it is going to. You also can add a comment.

It's no different than adding a function, you have to go and find that function to know what's inside of it. All this does is just reiterate through code based upon what is being interpreted.
05-16-2013, 10:21 PM #7
Master Ro
I make food
Originally posted by Pichu View Post
Well, that's why you name the goto something relating to what it is going to. You also can add a comment.

It's no different than adding a function, you have to go and find that function to know what's inside of it. All this does is just reiterate through code based upon what is being interpreted.


Finding functions is different. You have methods in different classes and find them based on that. If you have a bunch of goto tags in one variable scope, it gets hard to read. I'm not saying the goto tags itself are bad, I'm just saying it creates bad habits.

Winky Winky
05-16-2013, 11:22 PM #8
Dr. Tiga
Little One
Originally posted by Master
Finding functions is different. You have methods in different classes and find them based on that. If you have a bunch of goto tags in one variable scope, it gets hard to read. I'm not saying the goto tags itself are bad, I'm just saying it creates bad habits.

Winky Winky


Well to find a goto heading u can easily use ctrl f xD
05-17-2013, 02:07 AM #9
Pichu
RIP PICHU.
Originally posted by Master
Finding functions is different. You have methods in different classes and find them based on that. If you have a bunch of goto tags in one variable scope, it gets hard to read. I'm not saying the goto tags itself are bad, I'm just saying it creates bad habits.

Winky Winky


It really doesn't. Well then again, anything can cause bad habits, if we want to nitpick, accessors and modifiers; get/set, standard naming conventions, etc.

goto is in there for a reason, to be honest though if I was using win forms; I would not use them but since it's console; yes, they are very helpful. It's no different than using it as if you are using batch.

There is use for everything, it depends on how you go about it.
05-18-2013, 10:40 AM #10
QuantumDev
Can’t trickshot me!
Looks like a good beginner's program. Well Done Happy

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo