- Today I want to talk about best practises
when it comes to coding,
or coding conventions in general.
What are they and why are they important
for you to understand?
Let's talk about it in today's video.
This video is brought to you by the
Learn Programming Academy's C Sharp crash course.
Learn the core C Sharp skills you need,
to apply for C Sharp junior developer positions,
in just ten hours,
and obtain a fundamental understanding
of the C Sharp language.
You'll be able to demonstrate industry best practises
in the C Sharp code you write as well.
Visit lpa.dev/YoutubeCSharp
or click the link in the description below.
(upbeat music)
Welcome back! My name is Tim Buchalka
with another programming tip of the day.
And we're talking about programming practises,
best practises or code conventions.
So, let's start off with a definition.
What is a code convention?
Well, think of them as guidelines
for programming in general.
Now, they often address things like programming style,
programming practises
and methods for all aspects of the programming life cycle.
So, with that said,
why would you want to use code conventions?
Well, firstly, first and foremost,
everyone who follows a code convention is actually
on the same page and that's good thing.
And keep in mind that these code conventions
have often been formulated over a period of time,
they've stood the test of time
and they've been created, or contributed to,
by lots of developers.
So, they're pretty stable,
and, you know, they've just come about
from years of actually hard real world experience.
So, don't assume looking at a code convention,
that you necessarily know better.
That's the thing there,
that code conventions have been around for a long time,
and updated and,
particularly if you are using a recent version,
chances are they are going to be pretty accurate.
Now, there are a number
of different types of conventions out there.
Firstly, there's general conventions.
Now, that's applicable to software development in general.
It doesn't target a specific programming language
or style or whatever, it's just sort of general guidelines.
But then we have got code conventions
for specific programming languages,
often put out by the creator of the programming language.
And then we've got company conventions,
for a specific employer who ask their programmers
who come aboard, and are employees of that company,
to follow certain code conventions.
Now, let's look at a few quick examples of code conventions,
I'm not going to go into a lot of detail,
but you can see it's an example here:
Oracle published their best practises
for Java here.
Now, that's actually quite an old document,
so make sure that you're using the latest version,
or that the code convention document
you're using is of the latest version.
These code conventions that I found for Java
date back to 1997, as you can see in the document,
very, very old.
So, no doubt with that particular one,
given that's over 20 years old,
there's probably parts to it , or aspects of it,
that are no longer valid or at least should be re-looked at.
Now, a great place to find coding conventions is Google,
search engine.
There's lots of great material out there
if you take the time to go through and search for them.
But don't blindly assume everything you read
about code conventions is correct.
So, you want to check the credentials of the person,
or company, that's created the code conventions
and if you can't sort of verify, that, sort of,
you know, where they've come from, so to speak,
then look at multiple sources
and try and get some multiple places
that talk about the same types of conventions
and sort of agree on conventions
so that you know you are actually dealing with something
that is actually valid and has been agreed on
by a range of people.
Now, when you start a new programming job,
it's really important to look at the code conventions
and often when you start you'll be told this anyway,
but, depending on the size of the company,
it might be a formal document,
some sort of policy that has been put in place,
and as I said it could be a formal document,
but it may actually just be a Read Me file,
just a simple text file somewhere in the code base,
Or you may even just have to find it,
find out what the code conventions are
by studying the source code,
sort of seeing how they go about writing things
and making sure that your code is very similar.
So, in general, in line with that,
don't come into a new company
and try and code in a completely different way.
So, you want to really understand the code conventions
that are in place, if any, for that company,
study the code base,
and try and make sure your code is using,
or is being written in a very similar way
to the existing code.
And, in general, you never want to actually change code
purely to fix what you think is a code convention violation.
That's a really poor reason to actually change code
and again that could be a really subjective thing.
So, you don't want to be changing things,
especially when you are just starting,
on the assumption that you are doing a good thing there.
So, be really careful of that.
Take your time to read and understand
the conventions and best practises
because by doing that, in general,
this is for the company conventions,
if you're working for them,
but code conventions, in general,
will actually make you a better programmer
because these, again, these practises have been put out,
or these conventions and best practises
have been put together
over large periods of time,
lots of code base, lots of developers,
so the chances are because of that
because it's been so well used by a lot of programmers
that they've thought about the ramifications
of doing things in a certain way
and you can be sure that if you follow those conventions
it's highly likely to be on the right track.
So, make sure you invest some time
in learning code conventions,
it will certainly benefit you and your career.
you've made it to
the end of the video if you're
interested in more programming tips just
like this one click on the top rectangle
over there if you're interested in more
programming tutorials then click on the
bottom rectangle and if you're
interested in subscribing to the channel
and why wouldn't you be click on the
subscribe button up here look forward to
seeing you in another video