Intodrucing and my way of writing code

in #introduce6 years ago (edited)

Hy folks,

My name is Sebb. Or FuSSeL. As you want to call me. I am 31 years old and on the day livestock trucker and in the night hard working coder, beloved husband and father.

I am coding since i am 11 in several languages. C, C++, C#, Java, Basic, Visual Basic.Net for Windows, Linux and Android.

What information can you gather here?

With my post you will get information about interesting DiY Projects, Coding Tutorials, Tutorials about coins and many interesting stuff.

I hope I will not bore you to death and that you can bring along a whole heap of information that will make your everyday life and life easier or just funnier.

My way of writing readable code

First of all, a good dev can understand every code! If you read the code lines and don't understand what they do, you should take a good coding book and refresh your knowledge of the langauge. Thats my opinion about the topic and i can see many people in front of my inner eye, smashing their hands on their forehead and thinking, "that's not what i want to hear!"

Of course there are many ways of writing code. But i also think that everyone has it own way of written code which he understands the best way.

But how can you help newbies to understand your code quickly?

For myself there are three points to keep code readable.

  1. Describe the code blocks work
  2. Keep code clocks clear
  3. Write comments for more complex code lines

Please remember, that i am talking about my way of writing code. This is not a written law.

1. Describe the code blocks work

//############################################



//Functionname: dblCalcSomething



//Parameters:   int foo | double bar = 3.1415



//Description:  Does something funny with the



               given parameters

First of all the name of the function.

This is an example how i start a new function or block of code. I always start with a prefix of the functions return in small letters. I do that because i often forget if the function returns a value and what kind of datatype it is. After that i give a short hint of what the function will do. In this case it calculates something with the given parameters. To keep it more readable for me it starts with a capital letter. And last but not least one upto three words what the returned values is. PlayerXPos for example. Every new word i always start with a capital letter, because in this way it is more read- and understandable.

Parameters

This section will be short. This line only tells me how many parameters the function need, which datatype they are and if the is optional or better if the parameter not need to be set, because it has a given standart value.

Description

On the last part of a code block header i describe with less word what the function really does. For example, "Calcualtes the Players X Position." I always indent the words of a new line, to keep  the text and the heading seperate.

2. Keep code blocks clear

There are fantastic ways of writing short code. For Example

if(bPlayerUp == true) iPlayerXPos--;

Using this shortcut in this way is good read- and understandable code. You immediately under what this line does.
It checks if the variable is true and decrements the players x position to go upwards the screen.

if(bPlayerUp == true) {

  iPlayerXPos--;

  sendPlayerPosToPlayers(iPlayerXPos, iPlayerYPos);

}

As soon as you need to do more then a normal increment or decrement, or more than 20 chars of code, you should do the block in brackets. And i always write the open bracket after the command as you can see above.

void doAnything() {

if(true) {

while(true) {

That is also something where i think the code is more readable and i think there is no need to let the open bracket stand alone in a separate line. Letters also feel lonly ;)

3. Writing comments to more complex code blocks

Yeah, that is a topic where i am also very very messy with. I always try to write comments on complex lines, but when i want to write them, i don't find the right words to describe it. Most of the time i am working alone, so the header comments for my functions are enough to get back in touch with the code. 

So that's the way i work. I think i bored you enogh for the first time, but i future there will be more and better content of knowledge.

So happy coding and see you later


If you are interested in hiring me 

xbtfreelancer

Sort:  

@pxlfussel, congratulations on making your first post! I gave you an upvote!

Please give me a follow and take a moment to read this post regarding commenting and spam.
(tl;dr - if you spam, you will be flagged!)

Nice work!
This is a very good description :)

thanks, and sorry about the big spaces between the lines , i think it is a steem it problem xD

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.034
BTC 64058.80
ETH 3150.15
USDT 1.00
SBD 3.99