Better Programmer (Part 04): How to become a faster developer

25 August 2021, 10:23
Omega J Msigwa
5
3 538

Introduction

Faster development is every developer's dream. Nobody wants to develop a program or a piece of code the whole week or spend too many hours, if not days trying to figure things out when we get stuck in the coding process.

faster developing

Every coder wants to be faster

  • Maybe you watched MQL5 coding video on YouTube that was hard to follow along because you are too slow to catch up with the instructor's speed and you wish to get to that level for yourself.
  • Maybe you've seen some developers with magnificent coding speed on the keyboard, they can write a complex algorithm in few minutes that might take you hours if not days to code.
  • Or maybe you would like to be able to code faster and effectively so that you can deliver jobs faster on the Freelance and be ahead of your competitors.
  • Or maybe you want to impress your spouse/partner by your superman abilities on the keyboard, being able to code with less or no bugs, complex algorithm in a small amount of time.
  • Sometimes you might want to be able to deliver fast updates to products on the Market and fix bugs and errors that your customers have been spamming you on your Email or MQL5 message Inbox.

Pay attention and bring your pen and notebook close to you because I'm about to drop knowledge bombs on how to increase your coding speed while producing high quality work for you and your client 

You don't need any of these to get to your maximum coding speed potential

    • Extensive coding experience.
    • Best mechanical keyboard.
    • To be good at muscle memory keyboard typing.
    • Many gigabytes of RAM, many cores, powerful GPU on your personal computer(PC).

Faster Developer Vs Faster Coder

Before I start dropping those keys, I think it would be better if explain the difference between a Developer and a Coder.

Developer Coder
Developers are more experienced code writers. They are responsible for pretty much everything in the project such as:

Design, work-planning, coding and everything else related to the project.                                                                                                                                                                                                                                                                                                                            
Anyone who can write some code is often referred to as a coder by the people outside of the tech industry. But, usually, coders are considered the least trained or experienced level of programmers (developers). These individuals do not have the same algorithmic knowledge as a programmer or developer, as they are often a beginner in the field, skilled in just one coding language. Coders are usually given the job of writing forthright pieces of code that can easily be delegated by developers.

Being a coder you don't need to know everything Inside the project. For example, a customer on the freelance might want to add a Trailing Stop function inside his EA. A coder can go straight and code it, call it inside the Ontick function then test it once or twice on MetaTrader 5 to make sure it works if it does he/she send it back to the customer

In this article we are going to discuss the broader term of developer — how you can become faster at developing your systems. We are going to study everything in between design, work ethics, tools to use, coding, debugging, etc. 


HOW TO BECOME FASTER AS A DEVELOPER

01: Avoid bugs and bad architecture

Developers think that they spend a lot of time writing code but in reality, we spend most of our time reading code, debugging, and figuring out what to do.

It might take you three hours to debug a piece of code that you coded for 30 minutes, so the more bugs you have the longer it will take you to finish coding your project. Now you know that bugs slow our development process. So, the best thing for us to do is to avoid them as soon as possible.

Bad Architecture + Bugs = it's about the end of the world (just kidding)

Having bugs in your project is bad but failing to debug it or spot them easily just because of bad architecture is even worse. Just look at this piece of code taken from an EA that I was given by someone to fix the bugs.

ouble NPB=ND(m_account.Balance()*PortionPC,2);
if(CbT==0||PortChange<0||(PortChange>0&&NPB>PortionBalance))PortionBalance=NPB;
if(Pb+Ph<0)DrawDownPC=-(Pb+Ph)/PortionBalance;
if(!FirstRun&&DrawDownPC>=MaxDDPercent/100)
{       ET(A,displayColorLoss,"Equity Stop Loss Reached");
        if(PlaySounds)PlaySound(AlertSound);
        return(0);
}
if(-(Pb+Ph)>MaxDD)MaxDD=-(Pb+Ph);
MaxDDPer=MathMax(MaxDDPer,DrawDownPC*100);
if(SaveStats)Stats(false,TimeCurrent()<NextStats,PortionBalance,Pb+Ph);

//+-----------------------------------------------------------------+
//|                                                                 |
//+-----------------------------------------------------------------+
double StepAB=InitialAB*(1+StopTradePercent),StepSTB=m_accout.Balance()*(1-StopTradePercent), NextISTB=StepAB*(1-StopTradePercent);
if(StepSTB>NextISTB){   InitialAB=StepAB;
        StopTradeBalance=StepSTB;       }
        
double InitPortion=StopTradeBalance*PortionPC;
if(PortionBalance<InitPortion)
{       if(CbT==0)
 {      AllowTrading=false;
        if(PlaySounds)PlaySound(AlertSound);
        Print("Portion Balance dropped below stop trade percent");
        MessageBox("Reset EA, account balance dropped below stop trade percent on "+Symbol()+Period()," Warning",48);
        return(0); }
        else if(!ShutDown&&!RecoupClosedLoss)
        {       ShutDown=true; if(PlaySounds)PlaySound(AlertSound);
                Print("Portion Balance dropped below stop trade percent");
                return(0);              }
}

Just look at how bad the architecture is. It's no wonder there are bugs in the code. As you can see the code is hard to understand easily at glance, even if you are the one that wrote the code in the first place.

You will be so unlucky (just like me), if someone hires you on the freelance to fix bugs then you see more than 10000 lines of code all like the code above (It has been more than 3 weeks now and I still haven't finished).

My point here is as that. Always be consistent with your coding patterns, the way you name functions, create variables and so on, choose the one you are comfortable with and make sure they are easy for you and everyone-else to use.


02: Learn to fast debug

We have seen on the first point that bugs slow us down and feeds on our time. Debugging is a long topic to cover all of it in this article. I recommend everyone to read the article Debugging MQL5 Programs to learn more about debugging.

To be fast we need to learn how to debug very quickly here are some of the quick tips.

01: Use the MetaEditor CodeStyler .

This is like baby steps towards debugging, this amazing tool can not debug itself but can help change our code appearance and make code clear and easy to read.

02: Print and Comment more.

To find out what is not working we need to print and comment more code in suspicious areas.

Always find bugs in areas that they can not be found.

03: Do not try to change anything before you clearly understand how it works.

I'm sure this happened to you before, whereas you deleted a piece of code so that you can get your system to working then you realize later on that the code you deleted has nothing to do with your system bugs, so now you got to use another time writing code again and there is no guarantee that you won't expose your system to other bugs along the process. 

Before deleting anything read it on the documentation if it is a built-in-function or a method. If you are not sure, ask about it on the forum. I would personally copy all the code in the text file when I'm not sure about the right thing to do, that way I can be flexible changing code and testing new things out and refer to the primary code when I found out what was the error.


03: Libraries are created for specific use

When working with a library it is essential to use provided classes to their intended purpose, trying to force our way because we are too lazy to implement something clean is a sure way to disaster.

If you are using the Standard Library, it is a good practice to instantiate and reference members of the library in the best manner that is clear, easy, consistent, and probably the way recommended by professional library developers.

For example, instead of referencing the library Trade Classes in lazy ways and unclear names that are not even consistent just like this one,

#include <Trade\AccountInfo.mqh> //Class for working with trade account properties
#include <Trade\SymbolInfo.mqh>  //Class for working with trade instrument properties
#include <Trade\OrderInfo.mqh>   //Class for working with pending order properties
#include <Trade\OrderHistoryInfo.mqh>  //Class for working with history order properties
#include <Trade\PositionInfo.mqh>   //Class for working with open position properties
#include <Trade\DealInfo.mqh>       //Class for working with history deal properties
#include <Trade\Trade.mqh>          //Class for trade operations execution
#include <Trade\TerminalInfo.mqh>   //Class for getting the properties of the terminal environment
//--- 
CAccountInfo       ac;
CSymbolInfo        symb;
COrderInfo         orders;
CHistoryOrderInfo  hist_orders;
CPositionInfo      pos;
CDealInfo          _clos;
CTrade             my_trade;
CTerminalInfo      info;

Instead, reference all the libraries in a consistent easy to understand manner and the best way to do it is to reference it in Class member format of reference  m_*** -stands for members of a certain class

just like this,

#include <Trade\AccountInfo.mqh> //Class for working with trade account properties
#include <Trade\SymbolInfo.mqh>  //Class for working with trade instrument properties
#include <Trade\OrderInfo.mqh>   //Class for working with pending order properties
#include <Trade\OrderHistoryInfo.mqh>  //Class for working with history order properties
#include <Trade\PositionInfo.mqh>   //Class for working with open position properties
#include <Trade\DealInfo.mqh>       //Class for working with history deal properties
#include <Trade\Trade.mqh>          //Class for trade operations execution
#include <Trade\TerminalInfo.mqh>   //Class for getting the properties of the terminal environment
//--- 
CAccountInfo       m_account;  //members of account info
CSymbolInfo        m_symbol;   //members of symbolInfo
COrderInfo         m_order;    //mambers of OrderInfo
CHistoryOrderInfo  m_orderhistory; //members of Orderhistory info
CPositionInfo      m_position; //members of position info
CDealInfo          m_deal;     //members of deal info
CTrade             m_trade;    //members of trade info
CTerminalInfo      m_terminal; //members of terminal info

Also, don't forget to put comments at the end of the library reference so that you can be reminded what the reference is all about the next time you try to access it when you code. 

Also, in order to speed up our ability to code we should prefer using ready-made Standard libraries for handling our tasks rather than trying to implement everything from scratch. These libraries were created by professional programmers to make our MQL5 code DRY (Don't repeat yourself) and to speed up the development process. I encourage everyone to use them, not to mention other good libraries out there on the codebase and some on the market. 

Who do you think codes faster between these two;

Everything from Scratch Coder(Probably a NOOB) Standard Library User coder
double SymbolAsk(string symbol)
{
        if (symbol == "") symbol = Symbol();

        return SymbolInfoDouble(symbol, SYMBOL_ASK);
}

double SymbolBid(string symbol)
{
        if (symbol == "") symbol = Symbol();

        return SymbolInfoDouble(symbol, SYMBOL_BID);
}

int SymbolDigits(string symbol)
{
        if (symbol == "") symbol = Symbol();

        return (int)SymbolInfoInteger(symbol, SYMBOL_DIGITS);
}

double SymbolLotSize(string symbol)
{
        if (symbol == "") symbol = Symbol();

        return SymbolInfoDouble(symbol, SYMBOL_TRADE_CONTRACT_SIZE);
}

double SymbolLotStep(string symbol)
{
        if (symbol == "") symbol = Symbol();

        return SymbolInfoDouble(symbol, SYMBOL_VOLUME_STEP);
}

double SymbolMaxLot(string symbol)
{
        if (symbol == "") symbol = Symbol();

        return SymbolInfoDouble(symbol, SYMBOL_VOLUME_MAX);
}

double SymbolMinLot(string symbol)
{
        if (symbol == "") symbol = Symbol();

        return SymbolInfoDouble(symbol, SYMBOL_VOLUME_MIN);

}


#include <Trade\SymbolInfo.mqh>
CSymbolInfo   m_symbol; 

input string Input_symbol = "EURUSD";
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
     string symbol = Input_symbol=="" ? Symbol() : Input_symbol;
      m_symbol.Name(symbol); //Sets symbol name for our CSymbolInfo class object
//---
   return(INIT_SUCCEEDED);
  } 
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
      m_symbol.RefreshRates(); //Refresh to Get the Last quote 
      double    SymbolAsk = m_symbol.Ask();
      double    SymbolBid = m_symbol.Bid();
      double    SymbolDigits = m_symbol.Digits();
      double    SymbolLotSize = m_symbol.ContractSize();
      double    SymbolLotStep = m_symbol.LotsStep();
      double    SymbolMaxLot = m_symbol.LotsMax();
      double    SymbolMinLot = m_symbol.LotsMin();
  }



















Standard library users are 3X+ more productive than non-users and not to mention they have less code in their programs which means fewer bugs.


04: Avoid convoluted code

I hope in your coding career you have seen something like the code below in somebody's EA

        if(LbT>0)
        {       BEb=ND(BEb/LbT,Digits());
                if(BCa<0)BEb-=ND(BCa/PipVal2/(LbB-LbS),Digits());
                if(Pb>PbMax||PbMax==0)PbMax=Pb;
                if(Pb<PbMin||PbMin==0)PbMin=Pb;
                if(!TradesOpen)
                {       FileHandle=FileOpen(FileName,FILE_BIN|FILE_WRITE);
                        if(FileHandle>-1)
                        {       FileWriteInteger(FileHandle,TbF);
                                FileClose(FileHandle);
                                TradesOpen=true;
                                if(Debug)Print(FileName+" File Written: "+TbF);
                        }
                }
        }

It might be easy the moment you write this block of code but it won't be easy to read it the moment you want to debug it, chances are high you will forget some of the variables if not all of them so you will have to start referring to them again. Just think how time-wasting that activity is!

Writing complex algorithms will make people hate you and you will confuse yourself.

Forcing all logic to appear in one place is disgusting, wanting to have too many operations in a single function will slow our development process since we have to carefully arrange our code and make sure everything works as well.

If you need certain kinds of operations, consider creating independent functions which can do it only so that it'll be easy for you to finish one thing then move on to the other.


05: Avoid distractions.

"Be aware when distractions come your way you'll know it's a distraction when you stop doing what you were supposed to be doing and find yourself pondering things that have no value."
— Beverly R. Imes

Keep your phone on silent (if not turning it off at all) and do not pull it up to check your likes and shares on your Social Media photos. You will be so ineffective if you do so. If you are in a noisy disturbing home then find a place to go sit and finish your project.

If it is important enough for you, you will shut out all distractions: shut the door, turn off your phone, turn off social media, lock in Focus and get the job done.

I think this is the biggest challenge that we have to overcome as developers in the modern world where you are one click away from seductive beautiful models on Instagram and cute cat videos on Snapchat.

It is tempting when things are tough on your project when you can't figure out the right code to implement, to take a break and see what's going on on social media, or to just go out and chill out.

It's not that I'm against the breaks and chilling with friends no don't get me wrong, I do not code 24/7 though I got too many MQL5 and web developing projects waiting for me. But I believe that everybody should stick to a schedule that works for them. If it's not time to check social media, do not do so. If it's coding time stick to that only until the end of the session (no matter how confusing or tough things get) I'd rather prefer to extend coding sessions if I had nothing important to do after that.

Distracted coders can code for 5 hours or more something that focused programmers can code for 45 minutes


06: Reading documentation and Learning

After finding the solution to your problem on the forum, do not copy and paste it rushing out thinking you will finish your project faster this way (I touched this in my First Article). Make sure you understand how to code the solution for yourself. It is hard to work with copied code when something goes wrong especially when it has bugs since you don't personally understand it.

I encourage every coder to read the documentation frequently, especially on things that we don't know already or we are not yet comfortable with.

How does this increase our developing speed ?

The more you know about the MQL5 language, the more comfortable it becomes and the more comfortable (easy) it gets, the faster you will be at it, as a programmer. It is always a struggle to find the right code to effectively bring your idea into reality (Program), this is where most of our time is wasted. I sure hope you can tell how hard it is to code even simple things if you are not knowledgeable much on a particular activity such as coding Indicators, Scripts, Expert Advisors, etc.  This is where experience kicks in.

So how to get the experience? My answer is always simple: learn and try different things out

Those who know much about the MQL5 language have endless options on how to turn their idea into effective and meaningful code. They know where to use


07: Spaced repetition

"Humans more easily remember or learn items when they are studied a few times over a long period of time (spaced presentation), rather than studied repeatedly in a short period of time."
— Hermann Ebbinghaus

This is how we learned everything we know by doing it over and over again slowly until it becomes second nature. Our memory in our brains is limited and will only keep what we regularly use, so if we want to retain something in our mind we should do it regularly. We should learn to use this to our advantage.

How?

Since one of the reasons causing us to be slow is our ignorance on that particular subject, we should always look for areas that we need to improve, (some of them are discussed in this Article) once we found those areas we should continuously strive to improve in those areas until we become exceptionally good. This goes well when trying to learn and master a particular skill such as Machine LearningSelf Adaptive Algorithms, etc.


08: Keyboard shortcuts and MetaEditor setup

Keyboard Shortcuts

Keyboard shortcuts are fun and can save you a lot of time when it comes to writing code on the keyboard. I'm a pro on this and I like it when it comes to teaching coders my productive keyboard shortcuts on MetaEditor.

Learning keyboard shortcuts is life-changing when it comes to typing code and I think using the keyboard instead of a mouse should be adopted by every developer since we spend most of our time on our keyboard so we need to be good at it.

Here are a few of my favorite shortcuts on a Window PC (For Mac and Linux ) I'm not so sure but Mac users can replace CTRL with COMMAND;

SHORTCUT USAGE
 F4 Shift Between MT5 and Metaeditor
 F7  Compile Code 
 CTRL+F7  Compile all Opened documents 
 CTRL+C Copy Selected Code 
 CTRL+V Paste selected Code 
 CTRL+X Cut selected Code 
 CTRL+Z Undo changes in the code  
 CTRL+Y Redo changes in the code
 CTRL+A Select all code 
 CTRL+END move cursor to the last line of code in your document 
 CTRL+HOME move cursor to the first line of code in your document 
 SHIFT + Directions(LEFT,UP,RIGHT,DOWN) Select code toward that direction   
 TAB Increase Indent of the selected code 
 SHIFT+TAB Decrease Indent the selected code  
 CTRL+ Backspace Delete the whole word in a line 
 HOME move cursor to the beginning of a line 
 END move cursor to the end of a line 
 CTRL+ ? 
//--- Put a code separator to the next line
 CTRL+>
//+------------------------------------------------------------------+
//|           Add this to the current line and the next two          |
//+------------------------------------------------------------------+
 CTRL+"
// adds two forward slashes to the beginning of a line  
 CTRL+, Apply styler to your current document 
 CTRL+F4  Close the Current document 
 CRL +F5 Start/Resume debugging on history data 
 CTRL+T Open / Hide toolbox 
 CTRL+D Open /Hide Navigator
 ALT+G  Go to Variable/Function declaration 
 WINDOWS+T To navigate then apps on the taskbar just in case I want to Open
 Internet browser(CHROME) and search about a problem 
 CTRL+F  Open the Find search box
 CTRL+S  Save the current document 
 CTRL + Directions  Jump in the code spaces (word to word) spaces in that direction
 CTR + +   Navigate forward
 CTRL+ -  Navigate backward 
 CTRL+SHIFT+U  make a selected code(incase a word) Uppercase 
 CTRL+U  make a selected code(incase a word) Lowercase

MetaEditor Setup

It is also important to have the best MetaEditor Setup that favors writing code faster. Let's look at some of the settings that I recommend everybody should try.

These boxes should be checked

  • Insert () and closing }]" ' This will help to avoid those (unexpected end of program, unbalanced parentheses) errors that might be difficult and to catch in too much line of code.
  • Highlight matching brackets (This will remind you which function or which block you are in)
  • Highlight current line (It might be confusing to get to where you were coding the last time, setting this option will help you get there quickly at glance or you have to do is keep scrolling the code and the current line will be highlighted)
  • Clipboard history (for seeing your copy and paste history you will be able to copy different lines of code and access them easily )

Other settings are choosing the right font size for your eyes ability and distance between your eyes and PC no need to set small font size that you can hardly see.

You can play with the settings to find more settings to make you faster go to Tools>Options.


09: Learn to Google

Learning to do the correct google search is a time-saving activity and can speed your coding speed. Chances are high that you will stumble upon many problems while coding and you would need an immediate solution but knowing where to find the solutions is not enough you also need to know how to effectively search for the solution.

Doing a google search is enough for you to get quick right answers to your questions right?  WRONG  

Let's see an example of how the average google user coder that got stuck into reading an array from a binary file uses google to search for the solution.

The first thing that most people do is go to google and search for something like how to read an array in a binary file here is what they get

how to google search MQL5

Note: The total amount of results is more than 98 million. 

See the web is full of garbage and time-wasting sites that if you are not careful you will end up wasting your time and your private data will be stolen by hackers. The search term is too vague to get the specific immediate result that we need. For us to get the results we want we need to be very clear and specific.

There are too many search tips for those wishing to go deeper on this subject I recommend watching this short video. I'm going to talk about two tips only. 

01: Specific site to search

There is no better place to get the solutions concerning MQL5 than MQL5.com whenever you do a google search consider MQL5.com as the site you want Google to search for your answers.

Add  site:MQL5.com at the end of your search term, and this results of the search

search results from mql5

Only 568 Results are returned this time all coming from MQL5.com (The  site: URL) Commands google to only search in the specified site.

02: More specific

MQL5.com is still a vague site to search if you are very clear with what you want since it is a large site, There is a way that I always use for my self but It is not recommended by google but it works I've been using it ever-since, but the key here is you have to know which part of MQL5 you want your results to be prioritized for example Articles, Forum, Codebase, etc. You may prefer results from:

  •  Article section if you want to learn deep about a subject.
  •  Forum if you want a quick solution 
  •  Codebase if you want to see what others coded before.

Search in this format MQl5 + followed by section + then a search term, example in this case 

MQL5 forum how to read an array in a binary file here is the result

clear but vague MQL5 search

This method is specific but still, we haven't commanded google to a specific site (The website you are currently in only), the best thing would be to add site:MQL5.com the final search term is now forum how to read an array in a binary file site:MQL5.com Google will return 399 results this time.


Conclusion

That's enough for this article, I'm still working on other tips to increase our programming speed and boost our productivity. There are more tips to come on the next articles since there are many of them. I recommend every coder to practice these habits and ways daily

Thanks for reading, I would like to hear some of the tips from you in the discussion section of this article.

Best Regards.

Last comments | Go to discussion (5)
Yaness LeRoi225

très super, très riche tes articles.

hâte de lire d'autres a venir 

Omega J Msigwa
Yaness LeRoi225 #:

très super, très riche tes articles.

hâte de lire d'autres a venir 

Thank you

Combinatorics and probability theory for trading (Part I): The basics Combinatorics and probability theory for trading (Part I): The basics
In this series of article, we will try to find a practical application of probability theory to describe trading and pricing processes. In the first article, we will look into the basics of combinatorics and probability, and will analyze the first example of how to apply fractals in the framework of the probability theory.
Better Programmer (Part 03): Give Up doing these 5 things to become a successful MQL5 Programmer Better Programmer (Part 03): Give Up doing these 5 things to become a successful MQL5 Programmer
This is the must-read article for anyone wanting to improve their programming career. This article series is aimed at making you the best programmer you can possibly be, no matter how experienced you are. The discussed ideas work for MQL5 programming newbies as well as professionals.
Graphics in DoEasy library (part 79): "Animation frame" object class and its descendant objects Graphics in DoEasy library (part 79): "Animation frame" object class and its descendant objects
In this article, I will develop the class of a single animation frame and its descendants. The class is to allow drawing shapes while maintaining and then restoring the background under them.
Patterns with Examples (Part I): Multiple Top Patterns with Examples (Part I): Multiple Top
This is the first article in a series related to reversal patterns in the framework of algorithmic trading. We will begin with the most interesting pattern family, which originate from the Double Top and Double Bottom patterns.