HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpMinor

Username and password creator

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
andcreatorpasswordusername

Problem

This is the first program I have ever written outside of what I am learning in class. I am in my first programming class (ever) in college and I'd like to know if this is any good or if I'm making glaringly bad habits and mistakes. I am aware that some of the code I've written is redundant, but I don't think I've quite learned enough to fix it.

This program was created using Xamarin on my MacBook Pro, so the file structure built into the code is different from Windows and will have to be changed if you try to test it:

```
class if // under method FOR, change the string mainpath path to something windows

using System;
using System.IO;

namespace FileCreator2
{
public class MainClass
{
public static void Main (string[] args)
{
int counter = 1;
string useridtext = "NO VALUE";
string passtext = "NO VALUE";
string mainpath = "NO VALUE";
string answer = "NO VALUE";
string startup = "You have already created a username and password.";

If ifs = new If ();

ifs.FOR (counter, mainpath, startup, useridtext, passtext, answer);
}
}
public class determiner
{
public void FilesExist(string mainpath, string startup, string useridtext, string passtext)
{
pause Pause = new pause();
directory Direct = new directory ();

if (Directory.Exists (mainpath))
{
Console.WriteLine (startup);
}
else
{
Console.WriteLine ("Create your username: ");
useridtext = Console.ReadLine ();

Direct.Create (useridtext, passtext, mainpath);

Console.Clear ();

Console.WriteLine ("Create your password: ");
passtext = Console.ReadLine ();

Direct.Create (useridte

Solution

First off, well done! Many first questions on this site don't even contain code which compiles!

Now for the review:

  • In C#, class names are expected to be in PascalCase. This helps your code look more like the surrounding framework code, thereby being more familiar to other programmers.



  • Likewise, local variables are expected to be camelCase



  • Classes are meant to hold some data and some behavior in most cases. They are typically named with nouns, because they represent objects. As such, delete is not a good name for a class; it's a verb, and a very good choice for a method name, provided it's obvious what is being deleted.



  • On the same token, nouns make lousy method names. Imagine the sentence "I will Files a delete." - that is how your code will be read.



A survey was once made to determine the hardest part of programming. Naming won. Generally, when you extract a method, it should have a name that conveys a bit of what it's doing. Calling a method on something named If does not tell you much about what that code is doing. You'd expect it to return true or false based on some kind of input, whereas yours is simply a wrapper for arbitrary conditional code. Consider what you'd call that step of processing, and use that name.

Overall, good work. Many people take entry level classes and cannot write a working for loop. Just the fact that you are seeking feedback this early on shows a lot of promise.

Context

StackExchange Code Review Q#66654, answer score: 7

Revisions (0)

No revisions yet.