Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

CLI Deal Or No Deal

3rd program I've ever made in the language after hello world and magic 8-ball.

Have I picked up any horrible habits in my learning process? How could i make the code shorter? I'm still learning the language so please feel free to tell me how shit I am so I can improve :)

http://pastebin.com/hCw4N5d7

p.s. I know the algorithm to get the banker's offer is retarded and incorrect.
Why are you prefixing things with an underscore?
(Aug 10, 2013 10:38 PM)Xori Wrote:  Why are you prefixing things with an underscore?

to help me visually distinguish them from strings
It is not about the code length. It is about the code readability, which yours suffers greatly at the moment.

A few tips:
  • C# is an object object oriented language, make use of that and don't just stick everything in one class.

  • Each language has its own standards as far as naming things, usually it is a good idea to follow those as it allows people that will read your code to figure out what things are meant to do without even going in your code that much. At this point your underscore usage and PascalCase usage on variables make it hard to follow. You can read more about them at http://msdn.microsoft.com/en-us/library/...26074.aspx or http://www.scribd.com/doc/56782158/All-I...-Standards

  • The usage of goto is not recommended as it produces spaghetti code which is hard to follow or read.



Other than that, your array initializations could be improved. At the moment you are using:
Code
_CaseDisplayRep = new string[26];
_CaseDisplayRep[0] = " 1";
_CaseDisplayRep[1] = " 2";
_CaseDisplayRep[2] = " 3";
_CaseDisplayRep[3] = " 4";
_CaseDisplayRep[4] = " 5";
_CaseDisplayRep[5] = " 6";
_CaseDisplayRep[6] = " 7";
_CaseDisplayRep[7] = " 8";
_CaseDisplayRep[8] = " 9";
_CaseDisplayRep[9] = "10";
_CaseDisplayRep[10] = "11";
_CaseDisplayRep[11] = "12";
_CaseDisplayRep[12] = "13";
_CaseDisplayRep[13] = "14";
_CaseDisplayRep[14] = "15";
_CaseDisplayRep[15] = "16";
_CaseDisplayRep[16] = "17";
_CaseDisplayRep[17] = "18";
_CaseDisplayRep[18] = "19";
_CaseDisplayRep[19] = "20";
_CaseDisplayRep[20] = "21";
_CaseDisplayRep[21] = "22";
_CaseDisplayRep[22] = "23";
_CaseDisplayRep[23] = "24";
_CaseDisplayRep[24] = "25";
_CaseDisplayRep[25] = "26";

A few other options would be
Option A
Code
_CaseDisplayRep = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"," 14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26" };

Option B
Code
_CaseDisplayRep = new string[26];
for (int i = 0; i < _CaseDisplayRep.Length; i++)
{
    _CaseDisplayRep[i] = (i+1).ToString();
}

I could have probably found more things if I actually read the code, but these should get you to the right path. Good luck.
Thank you for your wise words dreamer :)
(Aug 11, 2013 03:36 AM)dreamer66 Wrote:  Option A
Code
_CaseDisplayRep = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"," 14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26" };

Option B
Code
_CaseDisplayRep = new string[26];
for (int i = 0; i < _CaseDisplayRep.Length; i++)
{
    _CaseDisplayRep[i] = (i+1).ToString();
}

I could have probably found more things if I actually read the code, but these should get you to the right path. Good luck.

My Option - C
Code
int[] numbers = Enumerable.Range(1, 26).Select(i => i).ToArray();

OP This way is the cleanest way, but also the hardest to understand. Its Linq.
(Aug 11, 2013 04:01 AM)Cornflower Blue இڿڰۣ-ڰۣ— Wrote:  My Option - C
Code
int[] numbers = Enumerable.Range(1, 26).Select(i => i).ToArray();

OP This way is the cleanest way, but also the hardest to understand. Its Linq.

The Linq way is only for .net 3.5, you don't know what .NET he is using :x

I would go with the for loop to initialize them




Looking trough the code, first things I notice
  • Bad variable naming imo

  • Goto\labels..

  • Bad void naming (eg "_StarterUI()")

  • You should use cases for stuff like this
    Code
    if (round == 1)
        {
        maxRounds = 6;
        }
        if (round == 2)
        {
        maxRounds = 5;
        }
        if (round == 3)
        {
        maxRounds = 4;
        }
        if (round == 4)
        {
        maxRounds = 3;
        }
        if (round == 5)
        {
        maxRounds = 2;
        }

  • Restarting a program by
    Code
    goto Replay;
    Is NOT the way to go, why not just call Main(args); ?



[Image: HJdK32K_x]
lensert.com is the new screenshot utility, try it out now!
OSX & WINDOWS



Possibly Related Threads...
Thread / Author Replies Views Last Post
by HackersNov 11, 2025 09:42 AM 0 206 Nov 11, 2025 09:42 AM
Last Post: Hackers
by HackersDec 11, 2024 05:11 PM 21 535 Dec 11, 2024 05:11 PM
Last Post: padrino
by HackersDec 11, 2024 08:31 AM 23 695 Dec 11, 2024 08:31 AM
Last Post: Hackers