Programming basics: naming convention, indent and white spaces

0

Welcome reader,

We’ll follow where we left off when we’ve talked about variables. When you are behind you screen, there is a lot more going on then just writing lines in the IDE to make you computer do something.  There are a set of rules that you should always stick to make your code clearer. Before, we talked about commenting your code.  Comments are meant to explain the purposes of your program. As an example,  when you’re creating variables, placing comments can help explain what you’re trying to do with those variables. When you’re programming, your instructions will be read by the IDE. Comments will be ignore by the IDE.

There are different ways to comment code. You can place comment on one line. You can also you what I call paragraph commenting. These will come handy when we’ll describe the behavior of methods. You’ll find some commenting examples.


//This is a single line comment

/*

This a paragraph comment. While I'm inside the /**/

all that will be written will be ignored by the IDE

*/

int myIntVariable; //Explain the usefulness of your variable with this comment 

More than just comments, there are other ways to make sure that other programmers who might read your code will appreciate reading it. As you could have seen, when I’m writting my variables, I follow a set of rules which I strongly suggest that you should also follow. This is called the “camelCase” convention. When you’re creating something like a variable or a method (more on methods later), these are the rules that you’ll have to follow.

  • The name of your variable cannot start with a number such as “123MyVariable”
  • The name of the variable should always start with a lower case letter such as “myVariable”
  • When you’re trying to write a composed name, you can either do this : “thisIsTheNameOfTheVariable” or use the underscore to separate either word of the variable’s name like this :  “this_Is_The_Name_Of_The_Variable”
  • Never forget to give a meaningful name to your variable

Finally, even following those set of rules is not quite enough. A good programmer should always indent his code a have a moderate use of white spaces. Well, I’ve just blurred some words that won’t really mean something to you so I’ll explain what I’m trying to tell you. Indenting code is a convention where you place tabs in the blocks of code. As for white spaces, there just meant to make code easier to read. It could all be close together, but that wouldn’t do any good if one must spend some time, trying to decrypt what you’ve wrote.

You’ll find below an example :

/*
The following block of code won't work
It will serve as an example to make sure
that you understand indentation
*/
//indentation
int variable_1=10;
{
   int variable_2=13; //See? There was a tab after the curly brace
}

//white spaces(none)
int variable_3=15;
double variable_4=20.0;
decimal variable_5=0.05m;
short variable_6=56;

//white spaces
/*
Putting white before and after operators(more on them later)
is helpful. Your code does not have to be too cramped
More than just that, separate your variables makes it also easier to read

What I suggest is if you have a set of variables that have a relation
altogether, let them be in a group but after create an empty line and then
resume your coding activity
*/
int variable_7 = 123;

double variable_8 = 234.98;

decimal variable_9 = 0.45m;

First real life project : Managing orders

2

Welcome reader,

This post is a small break from the programming basics serie. I’m going to talk about a real life project I will talk about in this blog. It will be an open source project, which will be accessible from my GitHub account profile.  Before going talking more about the basics, I thought it would be a good idea to talk about what could be achieved when we will put everything that was learned and mastered here in this blog.

You have to create a software application which will store a large number of clients. These clients will make orders and they have to save in a database which must be available a least 95% of the time. Sometimes, special orders takes more time than usual before they come in, when this happens, you can either make it so that when it happens, you automatically send emails to users or u make a query in the database to select users and then send the email. For emails in this situation, you should have templates which would just receive dynamic data so the user of the software has less manipulation to do.

For users, the fun would be to have a self-contained mobile application . What I mean is this:

  • sign in into the app with all our information.
  • Be able to see whats going on in our account.

Moreover, while using a mobile device, such as a phone or a tablet, users would have notification of what going on. Even if emails are sent to the email account, it would even better to select what kind of feedback from the company a customer would like to receive.

In this example, we have a software application which must use a database. The information must be available at least 95 % of the time, so the fail rate has to be really low. The information on the orders must be available online so the users can access it from his mobile device with their app.

In our dev world, there are many ways to complete a task. What I recommend is usually go with what you know so you’ll know what you’re doing while you are doing it. But, in a realm in which things move faster than when oneself blinks his eyes, I think it would be a benefit to try out new technologies in order to gain experience.

For this kind of problem, I have chosen to use:

  1. C# with the object oriented paradigm
  2. Windows Phone (Universal App)
  3. The Android Operating System
  4. Reactive Extension (Rx)
  5. LINQ
  6. The Firebase database

Honestly, I haven’t really experimented the technologies #2, 4 and 6. But I’m not going into this series before we’re ready to do it. So during that time, I’ll get my hands dirty. In the developers community, when someone says getting their hands dirty, it is meant as programming. In order to understand something, we really need to experiment by ourselves, even if the code makes sense to you, I strongly suggest that you at least copy paste it into your IDE and run the application to see how it works on your machine. What would be best is to modify the code, play with it until you truly understand what’s going on.

On the topic of the open source project, I’m going to take you step by step in my solution. This is going a more advanced serie, but bear no fear, if there things that you don’t understand, post comments and I’ll answer you to the best of my knowledge. At first, we will setup our database before going into coding. Then, we’ll design our software application for the company. Then design our mobile app. Afterwards, when the designs are completed, I’ll explain the more complex parts of my implementation, but not all of it. You’ll be able to find the project on my GitHub. Don’t worry, it’ll be commented!

Kevin

Programming basics : variables

0

Welcome reader,

This is the first part of a mini-serie to introduce the basics of programming with C#. Don’t forget to look at my GitHub account. I haven’t decide yet, but surely I will create a project which will resume every topic that I’ve talked about during the Programming basics serie.

So, we’re finally there, will start talking about the programming at last! In this serie, I assume that you’ll have already downloaded your IDE( if you don’t know what’s an IDE, please go read my blog post about IDEs) on your machine. Like I have mentionned before, I’ll be using the Visual Studio Community Edition IDE in this blog.

The introduction to programming start with a fundemental topic : variables. When you are programming, you are telling your machine exactly what you want it to achieve. In order to do so, you have to manipulate data directly on your machine, and when you’ll be running your software application(more of running later), the code that you’ve given will look like this:

0101010 0101 010101 01010

For the untrained eyes, it’s only 0s and 1s. But that is called binary code. This is what your machine use to achieve an operation that you have order it to do.  Even when you are on your user interface of you operating system, you are telling your computer what to achieve for you such as

Opening a folder

Save a file

With the IDEs,  our life is easier, we don’t need to actually manipulate data on the computer with binary code, we use variables. What this means is this: variables points to different parts of the computer memory. In short, variables have a name and a value.They hold different kind of data which can be manipulate and consume by a programmer in order to achieve his goal. Below, you’ll be able to see all the variables that are accessible in most programming languages:

  • byte – 8 bits
  • short – 16 bits
  • int – 32 bits
  • long -64 bits
  • float – single precision 32 bit floating numbers
  • double – double precision 64 bits floating numbers
  • decimal – 16 bits
  • bool – boolean value (true/false)
  • char – holds a character
  • String (it will be discussed in a later post)

From byte to long, these represent integer values such as 0, 100, 200. We have access to different kind of integer values, and when you are programming, you have to choose carefully the exact type you need because each type has its own weight in bit. The more you use, the bigger the software application will be. To understand the difference between the type of integer you can choose, you will find below the range of values each one has:

  • byte [0,255]
  • short [-32768,32767]
  • int [-2147483648,2147483647]
  • long [-9223372036854775808,9223372036854775807]

For example, if you create a software application which will only hold employees ages, using long variables because of their weight. Rapidly, in an application with around a million employees, the software would be heavy to process because you’re using the wrong type of data. In this case, knowing that the human’s span life is around 80 years, using the byte type would be much better. While using variables, you should always use your judgement in order to be memory efficient. Lower, you’ll be able to find an example of a byte variable containing the age of an employee:


byte employeeAge=30;

As you can see, when using a variable, the variable’s name is on the left and the value,which will be assigned, is on the right.  To continue, the float,double and decimal types should be use only when you to consume data which contained the full value of number like 1.25.


int firstValue=1.25; //firstValue will only be 1 because it is an integer
float secondValue=1.25; //secondValue will be 1.25

Console.WriteLine(firstValue);//Will display the value of 1
Console.WriteLine(secondValue); //Will display the value of 1.25

Upward, you can see some code sample showing the use of two variables and C# function(more on functions later) in order to display data to the screen. There’s quite a lot going on in this sample, the part with the double slash is called comments. Comment will be discussed in the next part of this serie. Moreover, as you can see, the names of the variable don’t really represent anything. When using variables, the names you use should always be meaningful. By always doing so, you’ll be able to understand the code you’ve written a while back faster without, or almost, need of comments.

To finish, the char type can only hold a character as a value. A character can be anything such as a alpha or numerical character. The char data is assigned with single quotes. You can see an example below.


byte charVariable='1';

To wrap up, variables have a meaningful name and a value. When using variables in your software application, you should make sure to always use the right type in order to be memory efficient.

Kevin

Integrated Development Environment (IDE)

0

I can assure you, this is the last post I’m writting before you’ll finally be able to dive into programming. On the plus side, this post is meant to help you with coding. To be able to program any software, a programmer needs an integrated development environment (IDE).

Before, .NET applications were only able to be used on the Windows operating system. But since a great event that happened a few days ago, .NET became an open source project! Hearing this was a source of great joy for us, .NET developers. This means that now you’re not force to have the Windows operating system on your machine, you can now have it on either Linux or Mac OS X.

You have a great selection of IDE to create a software using .NET. Below, you’ll be able to find a small list of IDEs you could use.

  • Visual Studio
  • Xamarin
  • ReSharper
  • SharpDevelop

For my case, I’ll be mostly using Visual Studio, the Community Edition. Some IDEs can be expensive to buy, but this edition is not only free, but gives you the ability to create various kind of apps like :

  • Video games
  • Mobile application
  • Web application

You’ll be able to find the Visual Studio Community Edition here : http://www.visualstudio.com/news/vs2013-community-vs.  Now, we are all set to be able to create awesome stuff!

Kevin

Software Version Control & Git

0

Before going into coding, I wanted to talk about software version control and the perks of using it in your daily life. The version control, simply, is a repository (storage location). In the repository, the source code, and other files,  from a software project. Every changes made to the software project will be track along with the user’s name who made the change.

While using version control, users are allowed to roll back to previous versions of the project. This means that if ever a version in the repository was problematic, a given user would be able to select a working version. The repository are needed, I would say vital,  when doing a collaborative development work. Being able to track what each and everyone did on the team is a huge bonus. Plus, since it is online, there’s no need of having a dedicated server which would have to contain all the information of the project.

For developers, a software is never done. The project is always growing, we always want to find different ways to improve a software and make it better. While doing so, they’ll want to compare previous versions to understand the many changes that happen in a software. Like it was mentioned earlier, every version is tracked so, it easy to perform such a task.

I’m telling you about this because I consider this as an important subject to talk about in the dev world. Plus,  while I’m talking about different topics in this blog, when I’ll create mini-series to go deeper into a subject, the software application will be available to you, the reader. There are different ways to exploit the software version control. In my case, I’m using https://github.com/.

With GitHub, after you’ve created your account, you’ll be able to create public and private repositories. The benefit of creating your repositories in the private mode is to just allow  yourself and the allowed collaborator to access your software project. When you create a public repository, any given user will be able to access your project.

To have an easy access to any versions of a GitHub project, I’ll introduce you to an user interface of GitHub : SourceTree. It is a software that can be used by Windows and OS X users. With the SourceTree software, you’ll be able to “clone” a repository with the HTTPS url link from the project. You’ll be able to find the software with this link http://www.sourcetreeapp.com/

This being said, you’ll have accessed to my public repositories with link https://github.com/Kavignon. In brief,  repositories are tracked storage location which provide users the ability of reverting on a different version of a project or any file of the project. At first, you can ask yourself why you’re actually doing this, but later you’ll see you can’t live without it! It is really helpful!

Kevin

First post

1

Hi everyone,

This is my first post in wordpress. I’ve created this website in order to help developers to dive into the great world of .NET! Thing is, it is so vast that it can be bothersome to try to find exactly what you want to achieve with .NET.

About everything can be achieved with .NET: you can create desktop application, web applications and services, mobile applications and so on. This blog will focus on helping you to get a better understanding of .NET.

At first, I will show you the core fundamentals of programming with C# and VB.NET. In order to achieve projects,it is my belief that people should have a good foundation of the basics before they can try to get into the different current hypes like voice enabled mobile apps or create a web-based video game.

I’d like to introduce myself. My name is Kevin Avignon, I’m a Java and C# developer. I started my path in the tech world about two years ago. I started programming with C# but I’m currently doing my IT engineering bachelor with Java. I’ve been in love with the .NET world since I first wrote my C# console application. I’ll do my best to make sure that in time, you’ll love it as much I do.

I have topics that I’ll want to mention in this blog because either I consider them really important or because I have an interest in them.  If ever there was a topic that was not on this website and you’d like me to talk about it, please make sure to let me know by commenting on my posts or posting your question in the Ask Kevin tab.

Let’s dive in into the world of .NET together and  I hope you’ll enjoy the ride !

Kevin