in this video we're going to discuss my
top 10 best practices for c-sharp
developers now these are things that I
do on a consistent basis to make my code
better now I've got a lot more than 10
best practices but I think that if you
master these 10 you'll set yourself up
for success on the other hand if you
ignore these best practices you will
almost assuredly get into trouble in
fact when students approach with a
broken application the most likely cause
for their issue has to do with not
filing one of these best practices
before it started though I want you know
to stick around till the end when I
built this list I actually identified
two more best practices they're very
important they are a bit different
though so I've added them on as bonus
best practices so let's jump right in
with best practice number one name
things well here I have the new product
window which will actually create both
the product and the solution you get
this by us hitting the new project
button here now in here by default the
name of the project is console
application eight and the solution name
is console application eight those are
horrible names and the reason why is
because you don't understand what that
really does so for example what's the
difference between console application
eight and console application six you
just don't know and so instead we need a
name this something more intelligent so
I start with the project name let's call
this console UI now what does that
project name tell us what it tells us
this is the console part of the
application and that it's a user
interface now does it tell us what that
user interface does not really we know
it's a console we don't know what it
does so for example it's not the
guestbook console user interface but in
this case we're doing a demo and so we
don't have a real specific purpose for
our application so I can call that
console UI in fact console UI can be a
fine name for it if you like good naming
is hard to do but I encourage you to
take the time to really think what's
your piece or whatever you're going to
be developing is going to do in this
case it's our project and so what's our
project gonna do and start thinking that
through and develop a name out of that
that makes sense next is our solution
name and a solution name really should
not match our project name one of the
most basic reasons why you shouldn't do
that is because then you don't know
what's the solution versus what's the
project two different things shouldn't
have the same name I know Microsoft
defaulted this way I I wish they
wouldn't but because they do we have to
make sure that we pay attention and
change the solution name in this case
and I call this solution c-sharp
best practices
and also notice my naming convention I'm
using what's called Pascal keys here
which means that every word gets a
capital letter so
c-sharp
best and practices so CSB P that's a
great naming convention that most people
seem to use in the industry and it's
also encouraged with Microsoft and what
we do we use Pascal casing for our
project names our solution names our
class names our file names and
most other things the only thing we
don't use pascal casing for is our
variables and our parameters and we'll
look at that a minute and there are of
course other little exceptions but we
talked about in general now the other
end note here is I did not say c-sharp
and put the the hash tag of pound sign
here like that and that is identifies
one more thing you should do in naming
and that is you shouldn't include
special characters or spaces in some
instances they will allow you to put
spaces in there and not throw an error
but just avoid it because it will cause
some headaches down the road that you
just weren't
so no spaces no special characters avoid
numbers if at all possible try and use
words instead
there are cases where numbers are
appropriate I wouldn't lead with numbers
and
try to avoid numbers in general so
that's solution naming and project
naming I'll hit OK
and now notice that Microsoft uses these
same naming conventions with a capital
first letter for each of their class
names their namespace names and their
method names will see more naming as we
go I'll point out as we do some naming
but that's pretty much wraps up the
naming but before we go I want to add
one more
project to our solution
and this time to a class library again I
will name it well in
this case I actually named it library at
the end and the reason why is because
it's a class library and so my personal
convention this is not one that is
necessarily best practice but it's it a
good idea at least think through my
personal convention is to add library on
the end of every class library and
here's the reason for that if I go into
console UI and add a reference to this
helper library
the project's solution helper library I
will only check this box here to add
that reference if the name includes
library you see it doesn't say in here
anywhere this is a class library it just
says here's one of the projects in your
solution so if I were to do is in
Reverse the wrong way and add a
reference in my class library to my
console application which is something
you shouldn't do but if I were to do
that it says console UI now that UI
tells me it's a user interface I don't
add references to user interfaces
therefore
the wrong place and I had canceled so if
I'm in the right place for references in
the console you I had a reference it
says library I know it's just a double
check to make sure that I know this is a
class library
the other thing I note is when I created
that class library it automatically
create a class for me called class one
now I really dislike that Microsoft does
this we don't need to have a default
class in here especially not one named
class one whenever you see a one at the
end of a name your first instinct should
be to make sure you get it out of your
application so in this case instead of
trying to rename this I just delete it
and the reason why is because if there's
ever a problem with which way I rename
it I don't want to end up with a file
name called class one even if the class
itself is something different or any
other weird issues
therefore whenever I create a class
library I delete class one and
that's the basics for naming my second
best practice is to add one class per
file let's look at what I mean over here
in the helper library if I right click
and say add
class let's add the person class I
like a public
now this file here person dot CS
holds the person class but what if I
wanted to add another class let's say
the ghast class I
could say
public class guest
putting the guest class here is possible
this is fine as far as c-sharp goes it's
valid code but if you look over here on
their right where does the guest class
reside
you can't really find it now you can
argue well but this makes sense for me
because but here is what I would
encourage for a best just don't do this
instead
create a new class file for every class
so now you have a public class guest
once an egg apology a public class guest
in the guest file now just by looking at
the file structure we know that the
person class resides in the person file
and the guest class resides in the guest
file this also illustrates one of our
naming best practices again notice that
I call this guest a singular and
person that's also singular that is
because this class represents one
instance of a person so for example if
this class had a first name and a last
name value that was storing per person
each instance would represent one person
so Tim quarry would be one instance of
that class whereas Joe Smith would be a
separate instance of that class
therefore the class name is singular so
we have good naming conventions and we
have one class per file let's move on to
best practice number three use
properties not public variables let's
take a look at our person class we have
open here if we want this class to store
data and when I expose that data to the
outside world we want to create a
property now I use this snippet prop
brop and tab twice to create an auto
property
this is the proper way to create a
variable type object that will present
data outside this class so for example
if we're in the program CS
project and we were just say
person let's add the using statement
there so person
first user equals new person first user
dot first name
equals Tim
we're now using that property now if you
wanted to you could say public string
last name that
is a public variable
if you want back we're at program dot CS
and said first user dot last name notice
first of all that the
first name has a little wrench next to
it whereas last name has that little
blue square next to it because these two
are different the first name is a
property the last name is a public
variable
now you can use these in a similar
manner and
some instances you couldn't tell a
difference between a two in how you use
them however this is not a good practice
do not use public variables the entire
explanation of why is the bad thing is
outside scope of this video however I
can tell you there are instances where
you'll run into where you can't use a
public variable the way you want to
instead you need to create a public
property
so now first name and last name are both
public properties and also takes care of
the basics of our person class
all right best practice number four
methods should do one thing the key
there is they should do one thing and
one thing only let's go back to our
example and move over to program CS
and
let's scope out what this program should
actually do it's going to wipe out our
test data from our previous example
let's cope how this program is supposed
to do it's going to start by
capturing a number of users
let's go of people's capture a number of
people's
names and
then
and
loop through and say hide them so it's
first going to capture a bunch of names
and then next it's going to loop through
each name and say hide them really
simple stuff but that's the overall goal
of this program and in fact let's put
these comments let's move these up here
instead
and we'll also fix that formatting
now it is a sample application so it's
not going to do a whole lot of
real-world stuff but instead it's just a
demo to show we could do with it now the
temptation here is to put all the code
inside static void main in fact let's
just kind of demo that so first let's
create a
list of person
I'll call it people
and
again back to our naming for a minute
this is a variable it's a private
variable and so I name it using camel
case and camel case says that the first
letter the first word is lowercase but
every word after that the first letter
is capitalized so for example if I had
two words here say people who I like
that would be how would be written now
since it's only one word it's all
lowercase
also note that it's plural people as in
more than one and the reason for this is
because this variable is a list of type
person zero or more people next let's
add a couple of sample records now
typically this is where you actually
capture the people's information but
we're going to beginning stages of
building this application and so you
want to have sample data in there try
things out so let's just go ahead and
create some sample data so
people dot add
new person
and we'll just copy that row a couple
times
and there we go we've had three people
to our list
next we'll create our for each loop
and we're going to say let's just do a
console.writeline that says
hello
person that first name space
person dot last name
and so it's going to happen with that is
we're going to first create the list of
people add the people to the list and
then loop through each person to list
and say hello and their full name of
course just completeness
consul don't rely on the end so that the
application can pause and let's see
what's on the screen and let's again
this is the bad way of doing things to
the poor example but let's go ahead and
demonstrate what this would look like
so hit start and
it says hello Tim Corrie hello Sue Storm
and hello Jill Jones
but I said this is the Badly of doing
things the poor way of doing things and
why is that well again our best practice
is that methods should do one thing and
one thing only well this static void
main right here is a method what's its
job well right now it's job is to create
a list and people the list loop three
person say hello to each person and then
pause the operation that seems like more
than one job so let's refactor this in
order to make it a little easier to work
with and also so that this static void
main only has one job and that job will
be to quarterback the application you
see the console application static void
main is where we start and where you
finish meaning the application starts by
calling static void main one static void
main is done the application closes so
its job is just run the application and
so
what we're going to do is take out any
tasks or pieces that don't align with
that just running the application let's
start here with this list of person
let's actually take this out of here and
put it above
and we'll actually be specific here and
say private
so this is a private list of person
called people but it lives at this level
it lives the same level as static void
main only to make a static as well
so now we have our list outside of
static void main declared so that any
method can call this people list and use
a people list well what methods need to
call that well let's create a new method
for these three rows right here
let's call this
private static void
meaning we only want people to call this
that are inside this same class program
this is we do for all of our methods
instead of a console application
void means it returns nothing and we'll
call it
set up sample theta and this goes back
again to our naming we keep coming back
to the naming best practice
notice I call this setup sample data now
what do you think the method called set
up sample data does well it sets up
sample data in this case these are the
three sample records we'll put them
there and now up here we can call set up
sample data
next let's get rid of this loop here so
let's create a private static void
I'll call this greet all the people
again why you think this does well it's
going to greet each person
so we'll take this for each and put it
down here and
then up here
you will say greet all the people
so now our
static void main is just the quarterback
it calls methods until it's done calling
methods and then it says okay paused let
you see things and we're done so that's
its job the setup sample data method has
one job setup sample data the greet all
the people method has one job loop
through the people and greet them now
this is a simplistic example but notice
how easy it is to read what static void
main does
set up sample create the people done and
then look at each method and see how
simple each of these are they're very
very simplistic because they have one
job and they do it well when you break
things down as it may seem
simple it may seem silly but the reality
is it makes for much easier to read code
which makes it much easier to debug
also note that right now I'm using
sample data
well I won't be using sample data all
the time in the future I will capture
user information so instead of deleting
this code or commenting it out I just
comment out this method and now it's no
longer being called I can call a new
methods called ask for people
information or something like that but
then if I want to test this application
maybe I found a bug and I don't want to
go through and add all the data in order
to populate it in order to then try out
the bug all thing to do is come back
here and say let's use a sample data
again it makes it very easy to switch
from debug mode into a production mode
just comment or uncomment a method and
you have or don't have your sample data
and this example really leads into the
next couple of best practices so let's
look at best practice number six that's
practice number six is keep it simple
and what I mean by that is
you really shouldn't write complex code
in fact if you find code that's really
really complex and you think man is
really cool pause for a minute think it
through is there an easier simpler way
of accomplishing the same task so for
example in this code here I could have
had all the code inside static void main
like I used to that was a little more
complex because you had to read all
those lines of code to figure out what's
happening in the application whereas now
it's very simple to know what each piece
does let's look down here as well down
here I'm using a four each well if for
each is a very very simple statement it
says for each person in the people list
that's pretty understandable whereas you
could say
for I equals 0 I is less than
people dot count an i plus plus and then
do a
console.writeline
say hello
people I
first name
space
people I
last name
like so
this right here and this right here are
really the same thing the difference is
that this one down here is a lot more
complex
I'm creating a new variable I'm counting
on making sure it's less than the count
because the count is zero based and so
if you have three items in the array
it's 0 1 2 therefore if the count is 3
then really we have to go less than 3
because the 1 says 3 isn't actually 3
it's a 4th one give the complexity okay
try to figure out which place here in
the array all this kind of stuff is
complex there's an easier way of doing
this that's simpler it's also easier to
read what's even worse is when people
get these great ideas on how to make
this for loop even cooler for example
saying things like I is people dot count
minus 1 and where I is
greater than or equal to 0
instead of I plus plus is I'm is - guess
what that would work too it actually
count through the array backwards or
through the list backwards but guess
what that's even more complex we don't
want to do that if at all possible
let's stick with the very simplistic and
easy to use for each
so there's there's simplicity in making
small methods that do one thing and it's
also simplicity in what you choose to
use or not use
and I get this question a lot from new
beginners in software development they
asked me questions that are really
questions that only a a senior level
developer should even be thinking about
a simple example might be they ask me
about abstract classes and they might
say well how do I use an abstract class
and generally my advice is why are you
even asking because typically if you're
asking about abstract class it's because
you read about it or learned about it in
some type of type of tutorial but you
have no clue why it's even useful and it
is good to learn about these things and
learn their usefulness but that really
isn't something you need to do until
after you've mastered a lot more topics
my advice is
master the basics because the reality is
the basics are what you're going to need
to use most of the time the complexity
that somebody's larger or broader topics
bring in like abstract classes or
virtual interfaces the complexity they
bring in often doesn't
help you and sometimes it really hurts
the readability to understandability of
what's going on in your code so for the
sake of the next person who's going to
read your code try and keep it as simple
as possible it makes it much easier to
understand and much easier to debug the
next best practice is number seven be
consistent this is one that often gets
misunderstood the first part of
consistency is doing things the same way
you always do them for example down here
I have a for each and I said var person
in people I could have said
person person and people either one
works
so if I was going to do another for each
loop I
wouldn't say
person
like so now obviously I wouldn't have to
4-h loops right after each other to do
the same thing but notice how this one
uses var and this one uses person that's
an inconsistency if I'm going to do it
one way I'm going to do that same way
each time
the same is true for how I name things
for example helper library
well if I am going to add new class
library I will call it something library
I won't call it something code file
because I establish that I always name
my class libraries with an extension of
library so that's the first part of
consistency and
programming especially in c-sharp is all
about attention to detail so that's one
of those details that really help in the
process and the reason why is the best
practice is because that way it's much
easier to visually spot an issue if
something is different that normally is
you can look at that and see why is this
different and may identify a problem but
the other part of consistency is
conforming to it ever standard you are
working with so for example if you're
working in a company where you're
working on an existing application you
may love my idea of this library being
the end name of any class library but if
your company already has three class
libraries and each of them ends in code
bin that you can't you shouldn't name
your class library with a ending of
library you should name it with the
ending of code bin now sure that's not
what I recommend
if you're starting out fresh but if
you're working an existing system you
need to pattern your code off of the set
standard for the rest of the code so as
consistency first in how you do things
doing it the same way every time but
then part of that consistency is doing
the things the same way that the rest of
your team does and so sometimes you
actually do things in a way that's
quote/unquote worse then what you know
you could do and that's actually better
and it sounds wrong but really fitting
in with a current code base is more
important than forcing your way or your
style in the new parts now that being
said I do say that if you can enact
change it's a good thing so for example
if you can say hey I've looked at our
coding standards and these things bother
me or these things should be I think
should be different if the whole team
gets on board with that that's something
you can work to evolve your codebase to
take into account but don't just blindly
make your own choices and say well I'm
following best practices because you're
not so be consistent but be consistent
inside your organization or your code
group now as next best practice is going
to ruffle some feathers number eight is
use curly braces for if statements and
what I mean by that well let's let's
take this example here actually I cut
this out for now and I'm going to say if
person dot first-name equals
Tim
I'll paste it back in and say
instead of hello Tim quarry I'm going to
say hello mr. Corey I
could say else
just use the regular hello first space
last name so hello is through store more
load Jill Jones now notice that I don't
have any curly braces after my if or my
else this is accepted practice in a lot
of areas the idea is that if you don't
have curly braces the next line and only
the next line is attached to that item
so for example this line right here is
attached to the if whereas this line is
attached to the else so if person dot
first-name equals Tim we're going to say
hello mr. Corey otherwise we're going to
say hello Sue Storm or hello Jill Jones
now here's the problem with this and
this is where it really bugs me
especially when you're first starting
out but even later if you decide you
know what I want to say something else -
Tim wears a Hello mr. Corey and then the
next line we're going to say how you
doing typically you think well I'm going
to say
how are you doing now you may notice
that the indentation is weird and you
say well I'll just go ahead and tab that
the eat if you don't doesn't really
matter
notice is red squiggly here it actually
tells me expected a closing curly brace
and if I were to run this I have build
errors
and let's what those errors are curly
brace except expected well even if it
put one there that's not like a help me
because it still says I've got something
else expected because I just closed the
for each and that's not right
so what's the problem here well the
problem is that this is no longer
associated with the if statement it will
always run
in fact if we didn't have this else
statement here we'd have no error and
let's run this hello mr. Cory how are
you doing how are you doing how you
doing I have three how are you doing I
have three people why is that well
because
if the person's first name is Tim I say
hello mr. Cory at first line but this
next line isn't associated with the if
statement it runs every time therefore I
ask everyone how doing including Tim Sue
and Jill
if I had curly braces
it'd be very easy to understand that I'm
only asking
Tim how am i checking to him and if it
is Tim that I ask I say how are you
doing
so I do that I only get hello much to
Cory how are you doing once because the
other two Sue and Jill don't get asked
how they're doing
with curry races is very easy to
understand what the scope is of that
particular statement now you may say
well I only have one line and that's
true but maybe tomorrow you want to add
that second that second line in and I
know this there's some controversy I
know some people really love having that
one-liner with no curly braces in there
my thing is this it doesn't hurt
anything now I know it's a little less
typing to do it the one-liner way but
here's a thought use a snippet I have
tab twice look what happened
it gave me not only my parens but also
my curly braces in fact if I were to say
person dot first name double equals Tim
and I hit enter now my cursor is even
between those curly braces and so I
didn't have to type without anyways so
my encouragement to you is to use the
curly braces for every if statement
don't try and shortcut it and do the
one-liners again these aren't
requirements these are best practices in
fact these are my best practices it's
definitely an opinion
our next best practice is number nine
concatenating strings with dollar sign
so what I mean by this well I've already
demoed it once here and what this does
is it takes the this part of the string
hello mr. in space and then it adds in
using these curly braces it adds in a
piece of c-sharp code so all of this
gets joined into one string because I
put a dollar sign in front of the double
quotes a different way of doing this
let's do this right above I could have
said double quotes hello mr. space and
double quotes plus
person dot last name
and that is functionally equivalent as
far as the outcome at least with this
the difference is the memory consumption
that this takes versus this
this right here is an efficient process
this right here is a very inefficient
process whenever you're talking about
adding strings together my encouragement
is if it's all in one line so for
example if you were going to say
string test equals
hello space plus person dot first name
plus space plus
person dot last name plus
excellent exclamation point like that if
you're doing some of this we are
building a string in all in one line or
in a couple lines and then you are
splitting that back out or using that my
encouragement is instead to do the
dollar sign methodology so string
better test equals dollar sign deep
we'll hit double quotes then you
semicolon just to complete that line
then come back and say hello space curly
brace person that first name pretty race
closed space curly brace
person dot last name close curly brace
and then exclamation point
now first of all this is a little easier
to read but it's also more efficient
than this is now we used to use string
dot format we still can but this dollar
sign
method has really taken over the string
dot formats place it's just really easy
to do it's really efficient the other
part though strings being efficient or
inefficient is in loops let's just
create a
private static void
string demo method
this is just for demo personal purposes
let's say we're going to create a string
we call it just ass not a great name but
it's good for demo we'll start it off
with this empty string and then we have
this for loop where we're going to say
that let's go to 100,000 so this is
obviously a contrived example but in
this example we're going to loop through
a hundred thousand times and add to
string
just a simple high hill plus space the
end of it will say it's going to say hi
hi hi hi hi a hundred thousand times
this will be horribly inefficient just
to prove this let's just do a
console.writeline where we say date time
dot now
dot -
long time string now this is not the
most efficient way of timing your
methods is just for demonstration
purposes but if we were to run this so
let's go ahead and put this method up
here now actually even comment out my
other methods
just so we're doing a good test
I'll call that let's make sure you have
everything taken care of it's going to
write out
the start time and it's going to write
out the end time in between we're going
to do this for loop where we append
something to s
if you rerun this
and still thinking there we go it took
approximately six seconds now in
computer terms that's forever
especially since this application is
very very simple it doesn't do a whole
lot now so you may say well this s
equals s plus is private problem instead
we could say plus equals and that does
something very similar it takes the
value of s adds hi to it and stores that
that new value back into s it's the same
rule same basic thing if we were run
this it's still about six seconds so
that wasn't the problem so instead if
you're going through a loop like this
the better practice if it's very very
large now if you're going through a loop
of five things eight things this prize
isn't worth it but if you're not sure or
if the loop might get larger use a
string builder a
string builder now go into all the
details of string builder but basically
it's a instantiated class and so you say
string builder the name equals new
string builder and then here instead of
doing an hour plus equals you would say
SB dot append
hi
now this is going to take hi and append
it to our string our string will look
the exact same as this s variable would
have looked now the only difference of
string builder is when you want to be an
actual string you have to say dot two
string so if down here I want to say SB
dot two string in order to get the
string equivalent
but we're not printing out we're just
storing it let's run this application
if you catch that same exact time let's
just show off let's do a million so 10
times as many as this method right here
10 times as many it still doesn't show a
difference in our start and end time so
whereas this method will have taken
approximately a minute probably this
method still does it within the same
second and we keep going adding zeros on
here and I'll tell you a while before
you see any difference there's a little
bit of a difference there with 10
million let's do a hundred million
okay so a hundred million it took two
seconds that as compared to a hundred
thousand taking three times as long so
as you can see how you deal with strings
and adding strings together is important
in the case of just adding a string
together for one line use the dollar
sign methodology if you're going to do a
loop where as a number of strings you
add together like this as example
instead use a string builder and that
will make your application much more
efficient and the last of our top 10
best practices for c-sharp is
avoid global variables I'm not only
going to demo this but basically the
idea is that when you first start out
you think man I have to have this
information everywhere and so you make
everything
global meaning you allow everyone to see
your variable across all different
classes and programs because you think
well I need to I need for the person
cloudlet guest class to see my list of
person called people and really the
answer is no you don't if the guest
class for whatever reason need to see a
list that was somewhere else you can
pass that list along it will even pass
efficiently so if you get tempted to a
global variable think of how you can do
a different way now there's some times
you say well but I have certain setup
information for example where my text
files are that I store log information
in that kind of information needs to be
accessible across the entire application
well in that kind of case you would use
the app config file and store
information in here there's two reasons
for that one is everywhere has access to
this file and two you can change this
file at runtime meaning you don't have
to recompile your application to change
the values here now the bonus here is
that this information doesn't live in
memory see if you have a lot of global
variables you clog up a lot of memory
that really isn't necessary you need to
adopt the idea of just in time meaning I
don't worry about information until just
when I need it and then I ask for it I
get it I use it I throw it away that's
how Microsoft deals with all of our
variables for example this variable s
right here if I were to be using this
and let's just uncommon stew pretend
like I am let's take out a few zeros
just in case I accidentally run this if
I were to use this variable here by the
time we get to here that variable is
gone Microsoft had said we declare it
right here we use it in this for loop
but by the time are done for loop we
don't use it again therefore I can get
rid of it at this point in the code
right here line 48 might that's very
efficient about that kind of thing so if
we create a public variable a global
variable that everyone can see the whole
application can use Microsoft can't get
rid of it therefore it stays in memory
and clogs things up now before we go on
there are some of you I they're going
nuts right now you've probably yell at
your screen and saying you missed one I
went through the entire top ten list and
didn't do number five so let's get back
to number five number five is use the
public modifier only when necessary and
this actually ties into our global
variables idea notice here on my methods
I have private static void set up sample
data private static void string dental
method why are these methods private
well because there's no need for them to
be public what's the difference well a
public method can be seen by other
classes outside of this class right here
if I make them private only this class
can access them well as no need to set
up sample data for this class outside of
this class therefore it's private and
what I'd encourage is you think a
private first mindset the idea that by
default you make everything private and
then only change things the public when
you say yep I need to have access to
that outside of this class for example
in the person class we have this
property first name and it's been called
last name well we'd have access to these
properties outside of the person class
therefore they're public so those are my
top 10 best practices for c-sharp
developers number one name things well
number two use one class per file number
three use properties not public
variables number four methods should do
only one thing number five but when we
skipped use public modifiers only when
necessary number six keep it simple
number seven be consistent number eight
use those curly braces for if statements
number nine concatenate strings using
that dollar sign method and number ten
avoid global variables but wait don't
forget I've got two more they're really
bonus best practices and these two
aren't really code related necessarily
but I find that they're very very
important in our first bonus best is
never trust the user I know that sounds
pessimistic I know it sounds
antagonistic but trust me don't trust
them if you ask a user for their age you
will expect back a number so if you ask
a person for their age and they say 21
you expect the number to 1 but some
users and not all of them but there will
be a user they will type out
twe and T Y space o ne now that's a
number and that's their H but it's not a
numeric value they've given you back
it's a string that represents a numeric
value so if you were expecting a number
back in you're going to be disappointed
this is the type of information that
blows up projects if you trust that the
users are going to give you good input
you will only test your application
using good input instead to build your
application as though the users are out
to get you and try to figure out what
they might do that's unexpected and then
make sure your application can handle it
so that's bonus best practice number one
never trust the user and the second
bonus best practice is plan before you
build whenever I demo a full application
where I build out from start to finish a
project and I've got one coming up soon
for this channel but whenever I do that
I spend a lot of time at the very
beginning laying out the plan now I know
your first instinct is to start coding
in fact that's often my first instinct I
look at a project and I say ooh I know
how to do that or I know how to do most
of that or I know how to do this part of
that and so I'll go off and start
writing code the problem is that you
back yourself into a corner if you don't
plan before you build I'm a certified
project manager it's one of the things
that I am and the project management
guide the guide that tells project
managers how to manage a project in
general has this layout for the five
major steps of a project and those major
steps are
initialization and then planning
executing monitoring and then wrapping
up or closing the project so onto those
five major areas the first one is just
saying things up or you know getting the
initial requirements but then number two
is planning under that the project
management guide lays out 21 steps that
have to happen before you can move to
the next phase which is actual execution
of the plan so 21 steps have to happen
before you execute when you execute
there are only seven steps now you see
that relationship as private managers
we've learned that in planning you make
the project easier this is doubly so
when it comes to writing code if you
just start writing code you will not
think through all of the different areas
in my start-to-finish projects or demos
I go through the five steps of planning
before we even start writing code before
you open up visual studio we go through
the five steps of planning and if you
want to see that in more depth I would
say subscribe to this channel but also
get on my mailing list and you'll link
down below in the description to get on
a mailing list because on the mailing
list you'll get
first-hand updates of when new things
come out and one the new things that's
coming out really soon is my start to
finish mini course for YouTube and in
that I go through developing application
from an idea all the way through to a
fully working application and in there
we'll go over those five steps to plan
out your application these are the same
five steps I use in my day job these are
the five same steps that I've used for
years because they're that important and
of all the best practices in this entire
video the one that's most important the
one that I would encourage you if you
take away one thing it's this plan
before you build so that's it that's my
top ten they're a bonus too and like I
said these are only the top ten I have a
lot more best practices but these the
top ten I look back at all the time so I
have a question for you which best
practices do you think should we add
this list or which ones do you think man
that one really helps me out go ahead
and leave a comment down below and let
me know I love to start a discussion on
that also don't forget to subscribe if
you haven't already and make sure you
get on that mailing list and I really
push that mailing list not because I
want to spam you in fact I really try
hard not to send any more emails than is
absolutely necessary but what I do is I
give out bonuses every once in a while
to my subscribers to my email
subscribers one of the upcoming bonuses
is that when I release that
start-to-finish course I'm also going to
be giving away or releasing a
bonus package along with it and that
bonus package will allow you to download
the videos it will give you a companion
guide and a whole bunch of other fun
stuff now that's gonna be a small cost
but if you're on my mailing list you'll
get a discount so just make sure you
keep an eye on that make sure you sign
up and also start the dialogue via email
if you have questions if you have
suggestions for new videos please let me
know that's all for this video I hope it
was helpful for you and as always I am
Tim quarry
you