Showing posts with label Coding. Show all posts
Showing posts with label Coding. Show all posts

How To Become A Successful Programmer?

Photo by Samuel Zeller on Unsplash

How To Become A Successful Programmer?

I have heard many novice programmers saying I want to get better at programming but there is hardly a slight improvement in their skills. I have observed that most of them say they want to get better but that is just a wish. They do not really mean it. They mere wish to improve their skills. They do not work for it. Your wish does not guarantee that you will become a successful programmer.
Many other people who have developed an interest in computer programming do not know how to reach to a point where they will be called successful programmers. They either keep wandering in the middle of nowhere or just give up. The same response is for them too as it was for the wishers.
Your interest does not guarantee that you will succeed.
Programming is a field which requires intensive work to master. Along with improving your technical knowledge of programming, you need to work on your interest. You need to develop a habit of not giving up. You need to make your brain believe that it is capable of the things it thinks it is not. You need to know how to move forward and how to keep moving forward. You need to convince your inner self that one day you will become the person who they call a successful programmer.
I am not saying that technical knowledge is not necessary at all and you concentrate all your efforts on the non-technical things. What I am trying to say is that in order to get better at programming, a non-technical parallel process will help you. I am calling it a non-technical process for no good reason. You can call it whatever you want just go with the flow.
So what is that non-technical process? It is nothing but a few habits and characteristics. The process is not specific to programming. It can be used for anything you want to achieve. It can be used to make more money, to get a sound health or make your relationships better. The reason I am calling it a process is that you need to keep practicing it. It never ends. Being a successful programmer is your goal and this is the process you need to repeat until you reach your goal.
The process has four key elements which are given below in the order it works for me. If you have a good reason to change the order, please let us know too. There is a comment section at the end of the page. Interact with us, we don't bite.

Four elements of the process:

  1. Burning Desire
  2. Faith
  3. Imagination
  4. Persistence

1. Burning Desire

Desire is defined in oxford dictionary as a strong feeling of wanting to have something or wishing for something to happen. Desire is the first reason why we do anything. It give us a direction to move on. It is desire which motivates us to do something. 
But the desire itself it not enough for success. Desires are often replaced by other desires. In order to achieve what you desire for, you must have a burning desire not just a desire. Such a burning desire which leads to take decision and get up instead of to a state of indecision. You must feel the urge to get whatever you want to. You must develop extreme interest, an interest which could not be diminished by procrastination.

How to cultivate a burning desire to become a successful programmer?

First of all, convince your mind that there is no backing out. Promise yourself that you will never quite. Close all the doors that will help you to escape.
Try to connect with people somehow who are already better than you in programming. Dan Peña, a successful businessman and a multimillionaire says:
Show me your friends and I'll show you your future.
People you surround yourself with always have an influence on your personality. Surround yourself with people better than you to get inspiration and also with the people who are not as good as you. People below you in your circle will help you see your progress and will learn from you. Make new connections on LinkedIn and join programming communities on Facebook, Reddit, etc but keep a balance in your friend zone. Not only surround yourself with only successful people and not only add people who want to learn from you.

Next, reinforce your mind to believe that you are serious with programming, it is not a joke. Surround your self with things which motivates you like print quotes and image of brilliant programming gurus and put them up around your house. Changing desktop and mobile backgrounds to motivating wallpapers really boost the desire.
There is nothing better than reading if you want to get good at something. Of course practice is necessary but reading is the first step. Practice comes next. Read books related to your topic, attend seminars, listen to pod casts etc. Most importantly, do read how did successful programmers get there and what are they doing now. Read their success stories. It will help you not to lose your interest.
There are a lot of ways to keep your desire alive. Search for them and follow them or be creative and create your own ways. There is no wrong or right way. What matters the most is which works for you.

2. Faith

Faith is complete trust or confidence in someone or something. I am talking a religious faith or something. I am talking about faith in your abilities to succeed, self-confidence. You will never ever get the things that you believe you cannot.
The Power of Your Subconscious Mind is a wonderful book by Dr. Joseph Murphy who describe in details how thoughts and believes are imprinted on subconscious mind and how these thoughts gain physical shape in the real world.
Confident people do not hesitate to ask questions. The more you ask, the more you learn. It gives you the ability to say yes to right things and no to wrong and inappropriate things. Confidence makes you able to overcome any sort of fear, fear of failure, fear of success, fear of misfortune, fear of what others think, fear of loss of love and relationship. It is self-confidence and faith in yourself which can make you set your goals high. If you believe that you will succeed, you will.

3. Imagination

If you can imagine yourself where you want to be, you will be there one day. Imagination is considered one of keys to success. All successful people are dreamers. If you can imagine something in your possession, you will have it. Either it is a skill, fortune, good relationship or anything else. Just believe in yourself, work for it and chase you dreams.
Let's make it more related to programming. Powerful imagination helps a lot in logic building. I have told you each concept of programming is a piece of puzzle. If you want to solve a problem, you need to combine these pieces. While you learn the basic concepts of programming, give each concept a unique shape in your imagination. For example, if statement would have one shape and a loop would have another shape. Recall these shapes when you need to solve a problem.
To make the process more interesting, add sounds to it. As the two magnets make a sound when they come together, you imagine similar sounds when you combine two pieces of puzzle successfully.
Programming is not a rocket science. Any combination that might sound perfect might not work in real. Don't give up. Keep trying. Try different combinations. The imagination faculty of mind gets better with practice. The more you practice, the more powerful your imagination becomes. One day you will reach to a point where you will make more than half of the logic to solve a problem while reading or listening to a problem statement.
I would recommend you to read the power of your subconscious mind by Dr. Joseph Murphy. It presents sound proofs the the imagination works and teaches you how to think.

4. Persistence

Persistence something that if you don't have, you will never succeed. It does not matter how good you are at logic building, it does not matter how powerful your imagination is, it does not matter you have a burning desire or not. If you are not persistent, you will never succeed.
Jack of all trades, master of none...
In consistency is like a parasite. It eats all your efforts and all your hard work you done. I have listed inconsistency as first in 5 Mistakes That I Have Made. I know how inconsistency pushes one backward. How it downgrades the progress and how it vanish most of the efforts one make. It is like an income tax. You work to make money for yourself and family and the govt takes it share for no reason. There is nobody who is happy to pay taxes.
If you want to be a good programmer, stick to programming. Never change your field. Learning how to code is a tedious task. Take your time to decide one programming language to learn and stick to it. Once you think you know how to code, then start learning other languages.
Remember, each and every concept is like a piece of puzzle. It does not matter what kind of color it has, if it fits somewhere, it will work. Same is the case with different programming languages. All basic concepts work the same in all languages, just the syntax is different. Once you become a master of a programming language, then learning a new language becomes a matter of time. You just need to get familiar with its syntax.

Recommended Readings:

How To Code? Function Overloading

function overloading in programming -img

If you are thinking how does this image relates to the topic, don't think. Keep calm and keep reading.

What is function overloading?

Function overloading is a concept in programming where there are multiple functions with the same name having different parameters. Different parameters mean either the number of parameter is different or the data type or the order of input parameters is different.
If the names of multiple functions are the same then how does a compiler/interpreter recognize which function has been called?
Recall function signature from the previous post. Compiler recognizes each function by its signature and function signature includes function name, number of parameters passed to it, their data type and the order in which they are provided. Each version of an overloaded function is almost same for us but entirely a different function for compiler. It just executes the function to which a call has been made irrespective of it is an overloaded function or not provided that the function call is a legal statement. When a compiler encounters a function call, it decides which function to execute from overloaded candidates on the basis of function signature.

Where to use function overloading?

Let me tell you now how the above image is relative to function overloading. Every screw wrench is used for the same purpose. They all do the same work but with a slight difference. Not every wrench fit for all screw sizes. A certain size of wrench can work only on that size of screw. You know, an overloaded function is like a wrench. For a set of alike problems, different versions of the same functions are more useful.
Whenever there is a group of tasks which are similar to each other but have a slight difference, function overloading come in handy. For example, you have some integer numbers and some floating point number and you are required to write a function which accepts a number and return its cube. Now you have a group of two similar tasks, calculating cube and a slight difference, different types of data. Function overloading in this scenario is considered the best practice.

Why to use function overloading?

Function overloading is considered one of the best practices of programming and programmers are encourage to use it because:
  1. it improves code readability and reduces the effort to remember function names
  2. it is used to implement polymorphism
  3. it makes code maintenance easy
Personally, I love the concept of function overloading when I work with a library. Believe me it saves a lot of time and effort.

Things to remember:

To overload a function:
  1. the name of the functions must be the same
  2. the number of parameters could be different
  3. types of parameters could be different 
  4. or both the number and types of parameters could be different

Next: How To Become A Successful Programmer? 5 Step Process

How To Code? Types Of Functions In Programming

how to code: types of function in programing - img

Types Of Functions In Programming:

In previous post we briefly discussed what are functions in programming and how to use them  in a generic way. Here, you will learn what are different types of functions.
Functions are divided into two categories based on where their definition exists.
  1. Built in functions
  2. User define functions

1. Built-in Functions

Built-in functions are those which are already defined in a library. All you need to do is to import the library and call the function. There is no need to define and declare the required function.

Steps to use Built-in function:

Each and every language has a rich set of libraries developed for specific purposes. It is really hard to remember all of these libraries and functions and there is no need to remember at all. Here are listed some steps that I would suggest you to find a library and its functions for certain task.
  1. Understand both the problem and your solution
  2. Search a library suitable for your need
  3. Find your required function and read its documentation
  4. Use

2. User define functions

As the name suggests, user define functions are those which are defined by the user. 
A user define function is declared by the user (the developer) and the definition is written before a function call is made to it.

Types of Functions:

Recall the input/parameter and output/return from previous post. Based on these 2 features, functions are of 4 types:
  1. Functions with no input no output
  2. Functions with only input
  3. Functions with only output
  4. Functions with both input and output
types of functions in programming
Functions are like puzzle pieces. You can use it the way you want.

1. Functions with no input no output 

As far as I know, this type of function is used in very rare cases. It does not accept any input parameter and does not return any output value. But it does not mean it is useless. It depends upon your creativity how you use it.

How to use?

I use this type only when I need to display fix information for user or for debugging. It could also be used in combination with global variables which is considered the worst practice or with constants.

2. Functions with only input

Function with only input is declared and defined with a certain number of input parameters but no return value. It takes values from other scopes in the code but does not transfer the result to any other scope.

How to use?

The output value could be directly printed on screen, written to a file, stored in a reference parameter or passed to another function as input.
Again, it is your creativity how you use it.

3. Functions with only output

Functions with only output have only return value type and no input parameters. 

How to use? 

The input for this type of functions does not come from another scope. Either the global values or constant values are used (not recommended) or input is created by internal processing. For example input could be read from a file or any other function with a return value.

4. Functions with both input and output

It allows us to pass the parameters to the function while calling the function. This type of functions will return some value when it is called. Data Type of the return value depends on the return type of function declaration.

How to use?

This type of functions are fully dynamic functions which provide maximum control to the developer. It is most widely used type of function. Decoupling, one of the best programming practices is easily achieved using functions with both input and output.

Next: Function Overloading

How To Code? Functions in Programming

what is a function in programming
unsplash-logoFabian Grohs

What is a function in programming?

A function in computer programming is just a block of related and reusable code which performs a single task or activity.
Function is also called method, procedure, sub-routine etc. I will try to cover each and every aspect of functions here. I have divided this post into two sections. One section explains the structural components and the other explains non-structural components. I am categorizing these things because I think it will help you better understand functions. These categories are not official. Tell me in the comments whether you liked the categorization or not. Based on your response, I will update this post.

Structural Components: 

There are four structural components of a function:
  1. Name
  2. Body
  3. Input
  4. Output

1. Name:

Function name is the same as a variable name. It follows the same conventions a variable name follows. Special characters and spaces are not allowed in function name. Name of a function is used latter in the code to call/execute the function. Name of a function should reflect the type of task it is performing. That's it. There is no rocket science. Just follow naming conventions.

2. Body

Body of a function consists of the lines of code which you want to execute whenever the function is called. It could be of any size, depends on your problem and your logic. But the body must contain only those lines which are related to each other and solve a single, independent sub-problem of your problem. Read the definition again, the block of code must be reusable. For example, you have to write code for some kind of mathematical equation like
c = a2 + b3
    Here, calculating square is one sub-problem while cube is another sub-problem. There will be two separate functions for each.

    3. Input

    The code in function body performs some operation and it might need data to operate on. In above example, you will need to specify the number you want to take square of. Same is the case with the cube function. The best approach to give input to a function is to use parameters. Parameters are also called arguments and are given during function call. For now, just remember that input to any function is given via parameters. I am going to explain it latter in this post.

    4. Output

    The output of a function is the result that we get after execution of the function. It could be in the form of a value or set of values, screen prints, files or combination of any of these or any other format. If the output value of a function is needed at the point where the function is called, then return is used. Although, it is not necessary for a function to return some value but in order to transfer data from one scope to another, return is used. An opening and closing brackets make a scope. Variables declared inside a scope are accessible only in that scope and its sub-scopes. It is often called lifespan of data/variables.

    Non-Structural Components:

    1. Function Definition
    2. Function Call
    3. Function Declaration (it is optional in many programming languages that's why it is on 3rd

    1. Function Definition

    Function definition contains two things: 
    • function signature
    • function body
    • Function Signature 
    Function signature consists of function name, types and numbers of parameters (input) and type of return value (output). These three things as a whole are called function signature because compiler or interpreter differentiate between functions using their signatures. If you are complete beginner and can't fully understand what I am trying to say, just believe me and remember that function signature contains function name, number of parameters and type of each parameter and return/output value type and it is used by compiler to recognize the function. These information will help you in function overloading.

    In order to define a function, you have to give it a name (should be meaningful) first. You need to specify the number and type of parameters if there are any. Parameters are placeholders for the input values which the function expects from function call. A parameter is defined the same way a variable is defined. It has a type and a name. The value then comes from function call.
    In mathematical equation example above, the square function could take float value or integer value but not a character value. Type and number of parameters are specified during function definition.
    •  Function Body
    Function body is just a block of code which performs the actual task you want it to do. Make sure, each function you define is an independent unit. What is meant by independent unit? It means that you can move each function to another project and it works there with no or little modifications. Try not to use any global variables inside a function. Provide all the input data using parameters and get the result using return value or reference parameters.

    2. Function Call

    Function call is a statement which specifies the name of the function to execute and values for input parameters defined in function definition. It also gives you the value which is returned by a function. You can store that value in a variable or use is directly as you use variables. For example a function which returns integer value can be used anywhere where integer variable could be used.
    Values that you mention in function call are copied to parameters in the function definition. Note that the sequence and type of values must the same as it is in the function definition.

    3. Function Declaration

    Function declaration is only one statement which specifies the function signature. It is function definition without a body. It is optional in many languages but still you should have an idea what it is. You might need it at some point.

    why do we use functions in programming?

     Functions are used because functions:
    1. are reusable units
    2. reduces code size
    3. makes debugging easier
    4. helps to make the code more modular
    5. makes the code easier to maintain
    Next: Types Of Functions In Programming


    Subscribe to our YouTube channel:

    How to Code? Learn These 5 Basic Concepts of Programming


    How to code: 5 basic concepts of programming
    unsplash-logoLewis Ngugi
    If you are intrigued by the title and you are reading this, it means that you are interested to learn how to code. You might have heard people saying that programming is a God gifted skill and not everybody is blessed with it or programming is not for people like you or me or whatever. Believe me, that's bullshit. Computer programming is the most interesting and the easiest skill to acquire in computer sciences. At least, I think so. It is said that one can do almost everything with programming and its true. If you can do everything with something, it then definitely worths a lot of your time.
    A question arises here that how much time one should dedicate daily to learn how to code fast and effect? I would say 8 hrs if you are on your own. To reduce the time and effort you need to learn programming, you should benefit from those who have experience and are good at it.
    As far as I think, you can boost up your learning process if you learn the basics well. Different authors have a different opinion about what are the basic concepts of computer programming. They are also right. Everyone has own perspective. Here I have listed 5 of the basic concepts of computer programming. I am sure it will save you pretty much time and effort.
    I am not saying that you will become an expert in programming after reading this post. I am just helping you to get started, to give you a push. You will get an idea of what are the basics of programming and how these basic concepts work. In order, to get a full understanding of how to code I would recommend you to read 3-5 books of programming fundamentals.

    Programming Fundamentals

    1. Variables, Constants, and Arrays

    Anything that you write in your code is stored in computer memory slots. Each slot has a unique address. To read from and write to a memory location, its address is used. But it is hard to work with numbers like 0x19a823f2... this is how memory addresses look like. Naturally, humans are good at working with names than numbers. That's why a genius (idk who but God bliss him/her) thought that why not to use real world names to deal with computer memory. Variables, constants and Arrays and other similar things are named memory locations. Each offers a different approach to handle memory read/write operations.
    You need to remember only 3 things about variables and related terms.
    1. It is a memory location.
    2. It has a name.
    3. It has some data.
    Remember, a variable is always a variable. Irrespective of the language that you are using, every variable will have the above-mentioned properties. Once you declare a variable with a name suppose x, a constant or an array the operating system selects one or more memory slots (depends on the type of variable) and attach your given name to these slots. Anywhere you use that x in your code, the mighty Operating System resolves it into the memory address it is attached to. Hope it makes sense.

    Where to use?

    Use them wherever you have to read/write some data to/from memory again and again in your code.

    Constants are the same as variables but you cannot change its value once it is initialized.

    Where to use?

    Use constants when you have to write data only once and read many times.

    An array is just a sequence of memory addresses. It has a name, data type and data. The only difference is that it is just a sequence of memory slots. To use a specific slot in this sequence, indexes are used.
    It has also been observed that human remember the things which they see more than the things that they hear. For your convince, a video is included below which further explains the concept.

    Where to use?

    Use arrays whenever you have a sequence of the same kind of data.

    2. Conditional Statements

    Conditional statements (the decision is taken based on some condition(s)), also called control statements (control the flow of execution of your code) or if statements (have if keyword in syntax). We will use the term if statement onward.
    If statements come to the game when there are multiple choices available and one is to be selected based on a given condition. When there are multiple paths of execution if statements are used to direct the execution flow to one of the paths. It decides whether to execute a block of code or not.
    The easiest way to know where to use if statements are to look at your problem statement and identify if word. Any condition following the if word will be your if condition. Real world conditions are depicted in code by using variables and expressions. e.g if a person is at least 18 years old, show him the content (some age-restricted content).
    There are different varieties of conditional statements suitable for different scenarios.
    • if statement:

    Single if with one conditional expression and a single block of code. Decides whether to execute a piece of code or not.

    Example: if something happens to do something.
    • if-else statement:

    single if with one else. Has two blocks of code to choose from for execution based on only one conditional expression.


    Example: if something happens then do something otherwise do something else.
    • if-else-if statement:

    It is the same as if-else but with multiple conditions. Each condition following the first condition is written with the keyword else if. It has more than 2 blocks of code to choose from for execution.

    Example: if something happens then do something if something else happens, do something else and keep it going.

    Yes, I know, the examples are extremely dumb. Just tried to be more generic. If you have better examples, write in comments. I will include it.if-else-if statement : imgif and if-else statements : img

    3. Loops

    A loop is something which starts from one point, goes around and ends back on starting point. If there is a block of code which you see is consecutively used several times, add it to a loop. Note the word consecutively here. We will refer to it in the next section.
    When a block of code is written inside a loop body, it executes again and again. The execution control starts from the first statement of the loop body and progress until it reaches the end. In the end, it returns back to the start of the body. But wait, when will stop executing? Never?
    A loop is similar to if statement with an extra feature. The body of a loop is executed again and again based on a conditional expression. If the condition is true, the body is executed, otherwise not. The control returns back to check the condition every time it finishes executing the block of code until the conditional expression evaluates to false. That's why a dynamic conditional statement (not officially called dynamic) is required in loops.
    There are 4 widely used variations of loops in popular programming languages like JavaScript, Python, C++, Java. All the variations do the same thing, execute code repeatedly. However, each variation comes with a slight modification suitable for different scenarios.
    1. For Loop

      For loop is mostly used as a counter. Like if you want to execute a block of code several times, for loop is the best choice.

      Keyword: for

      Components: 

      1. initialization
      2. conditional expression
      3. condition update statement
      4. body
        the conditional expression is mandatory and the other two are optional.
    2. While Loop

      If you want to run a block of code repeatedly while a condition remains true, go for while loop. You make for loop work like a while loop by ignoring its 1st and 3rd component.

      Keyword: while

      Components:

      1. conditional expression
      2. body
      Both of the components are mandatory.

    3. Do-While Loop

      The do-while loop comes in handy if you need a block of code at least once whether the condition is true or false. After the first iteration, it works like a while loop. However, in while loop, the condition is evaluated first before its body is executed and in do-while, the condition is evaluated at the end of iteration. Unlike while and for loops, two keywords are used in do-while.

      keywords: do, while

      Components:

      1. body
      2. condition
        both components are required.
    4. For-Each Loop

      For-each loop is more suitable for situations when you have a list of elements and you want to execute some code for each element of the list. For example, you have a list of some sort of geometrical shapes and want to change the color of each object, use for-each instead of for and while.

      keywords: for-each has a syntax similar to for loop in almost all languages. Some languages use each keyword in combination with for and some use : operator.

      Components:

      1. condition
      2. body
      both of the components are mandatory.
    types of loops in programming

    4. Functions / Methods:

    an activity that is natural to or the purpose of a person or thing.
    Here, we are not talking about the function of a person or things but a function of a block of code. The reason to include the above definition is to present an analogy between functions in the real world and functions in programming.
    You know what is the function of a printer, don't you? It prints electronic information on a paper. Printing is a sequence of related events. A printer pulls a paper from its tray, prints the queued information on it and pushes it smoothly. Similar to this, a function in programming is a block of code which performs a sequence of related operations. That's it.

    Components:

    1. Function Name
    2. Parameters
    3. Return type
    4. Body
    5. Function Call
    All the 5 components are mandatory except parameters. A function must have a name which is used to call it, a body which is executed on each call, and a return type which is the type of data a function produces as a result. Parameters are optional. The same naming conventions are followed which are used for variables. 
    If a function needs input data from another scope then it is given either as a parameter or globally. There are many ways to exchange data between the function body and the rest of the code. Function call necessary for function execution. If there is no call to a function, it will never execute.

    When to use functions?

    If you have a piece of code for something and you need it more than in one places in your program, enclose it in a function and call it everywhere you need it.
    Functions and the upcoming topic deserves more of our time. I will write separate posts for each in detail.

    5. Class and Objects:

    You might have heard that class is a blueprint and an object is an instance of a class. I have read it like a lot time in books and blogs and it was the most confusing statement for me ever. Class and Object are the base concepts of Object Oriented Programming. If you a beginner (most probably you are if you are reading this), it will take you some time and some effort to understand what actually class and objects are and how to better use them. You will get some help from here and a lot more in the coming posts.

    What is a Class?

    In real-world problems we have several physical and non-physical objects like if you are working on a game, your main character is an object, a weapon is another object, enemies are separate objects. All have some features and functions. Based on their functions, we can categorize these objects. We can put all the similar objects in one category. For example, Weapons are similar to each other while different from humanoid characters.
    In OOP, such categories become classes. In the above example, the weapon is one class while the enemy is another class.
    In functions, a number of operations which belong to a single event are combined and used again and again with just one function call. Same is the case with classes. Functions which perform operations related to a single category or type of objects are combined into a single class. Obviously, these functions need some data to operate on, so the related data is also encapsulated with these function within the class.

    What is an Object?

    Can you sleep inside a blueprint of your house? Never. The map/blueprint must first be brought into a physical shape. You have to bring it into existence. It will occupy some space on earth. Yes, don't shout. I know people are trying to live on Mars but it may never happen. But there are crazy inventors are still alive. who knows. Anyhow, same is the case with classes. Once you create a class, it does not occupy any space in computer memory (RAM). So you cannot use it. Sorry.
    Unless and until at least one object of that class is created. 
    The object is used to access methods and data of a class. An object is created almost the same way a variable is created. It has a type (class name) and a name. The same naming conventions are followed to create an object of a class which is followed for functions and variable.

    Machine Learning Libraries for JavaScript - 2019

    Photo by Franck V. on Unsplash
    Machine learning has seen enormous growth in recent years. It is actively transforming every industry all around us. From autonomous vehicles to chess players, a simple path following robots to Sophia and from recognizing horrible handwritten text to extremely intelligent new Google Assistant, Machine Learning is everywhere. Thanks to Big Data, high power CPUs, giant GPUs and of course to researchers who brought ML from something to everything. For raising reality straight out of a fantasy (sounds filmic. Doesn't it?). Thanks for saving us from the thing that most of the real human being hate. I'm talking about the holy MATHS. Ok, enough.

    The blessed and the noble human (researchers and innovators) are working hard to come up with more accurate and efficient techniques which work in a constrained environment. One of the major efforts of ML & JS communities is to let us implement ML in JavaScript using JavaScript machine learning libraries. If you are a JavaScript Ninja and want to dive into machine learning or you are a machine learning expert and have a strong desire to try out JavaScript, we present here some JavaScript libraries which you may find interesting. The libraries are listed irrespective of any rating or importance or anything. Choose on your personal preference.

    Brain.js

    Brain.js is an open source library developed for Neural Networks. Creating neural nets and training them is a math-intensive job which requires a lot of work even if you are a math genius. Brain.js simplifies the entire process by limiting the API to just a few function calls. All you need is to just install the library and start using it. The library can be used with Node.js as well as in the browser. It can train neural net models asynchronously and also supports streams, Ellman networks and blocked recurrent network devices as well.

    TensorFlow.js

    TensorFlow.js is a JavaScript version of papular machine learning library, TensorFlow developed and supported by Google. It provides easy to use API to create, train and implement different machine learning modules. It allows you to train a new neural network or retrain an existing neural net without leaving the browser. If you love Keras and want to try out TensorFlow, try TensorFlow.js Layers API and you will feel comfortable. And above all, it has a comprehensive tutorial set which will help you get started with no or little trouble. Check out the official tutorials here.

    Keras.js

    Keras.js is also an open source framework for implementing machine learning models in web browsers. Both Keras.js and TensorFlow.js have many things in common, such as both provide GPU support using WebGL and provide a high-level API which hides abstractions provided by backend frameworks. Keras.js can be used with Node.js too but only in CPU mode. 
    The library officially offers a rich set of demos, written in Vuejs. Check out the following cool list of examples:
    • Basic Convnet for MNIST
    • Convolutional Variational Autoencoder, trained on MNIST
    • Auxiliary Classifier Generative Adversarial Networks (AC-GAN) on MNIST
    • 50-layer Residual Network, trained on ImageNet
    • Inception v3, trained on ImageNet
    • DenseNet-121, trained on ImageNet
    • SqueezeNet v1.1, trained on ImageNet
    • Bidirectional LSTM for IMDB sentiment classification

    STDLib

    STDLib is open source JavaScript libraries which provide a robust set of mathematical and statistical functions which can help you to create high-performance machine learning models and other libraries as well.
    The library is equipped with data visualization tools to help its users to analyze their data and get a better understanding. In order to perceive meaningful insights from data in a more manageable way, the library offers utility functions which are used to group, filter, map and transform data even in browsers as well as on servers. To get a quick review of the library, go to the documentation page here. Although the given list of categories over there has some design issues and looks pretty boring but the detail pages are very user-friendly and informative.

    ml.js

    If you are looking for a complete package of tools for JavaScript/Node.js either for math work or machine learning job, ml.js is for you. It is a set of open-source tools for numerical analysis and machine learning. I would say ml.js is a swiss army knife for The JavaScript developers. It provides you with utility tools for data manipulation and libraries for running different machine learning models on browsers and of course on Node.js environment. The package offers a separate library for neural nets, KNN, K-means clustering, Naive Bayes, and regression and decision tree and random forest and PCA and ... Go to the docs, please.


    The must have books for JavaScript in 2019

    Photo by Greg Rakozy on Unsplash

    JavaScript has been a favorite language to developers throughout recent few years. It was initially supported by web browsers but soon after its release, server side implementations of the language were introduced by different organizations like Netscape, Microsoft and the open-source Node.js. It is not only used for designing webpages but for databases, server scripting and for mobile and desktop applications too. One of the most prominent reasons to learn JavaScript is its enormous community and its products. There are a number of cool JavaScript libraries which makes the life of a developer very easy. ECMA International has introduced the ECMA2017 standards which are quite effective and saves enough amount of time. With all this, the community has made large efforts to bring Machine Learning and JavaScript together. Taking all these into consideration, JavaScript seems worth our time.

    If you are a beginner or an intermediate JavaScript developer, we suggest you some books which you might find helpful.

    1. Eloquent JavaScript, 3rd Edition: A Modern Introduction to Programming

    This books takes you from the scratch to an intermediate level. It adapts the learning by doing approach by providing you with exercises and full-chapter projects. Once you get some hands on experience, the book will teach you best programming practices for clarity and code debugging which really makes a difference. Once you get enough proficient with the language, the book teaches how to interact with web browsers and manipulate DOM in effective way. The end chapters introduces its reader to the server-side scripting using Node.js.

    2. JavaScript: The Good Parts

    The book is also a beginner’s guide assuming no prior knowledge of the language. The book give you a detailed look at the basic parts of the language like syntax, functions, and data structure and control etc. After giving a walk through the essentials, it makes a smooth transition towards a little hard topics like regular expressions and AJAX. Apart from the technical stuff, this book make a clear difference between the good parts (good practices/style) and the bad parts (bad practices) of the language and encourage you to utilize the good parts in an efficient manner.

    3. JavaScript: The Definitive Guide: Activate Your Web Pages (Definitive Guides)

    This book is recommended for intermediate JavaScript developer. The 6th edition of this book covers HTML5 and ECMAScript 5. Although ECMAScript 5 was introduced in 2009 which is pretty old now, the latest is ECMAScript 2017 (I Love It), but the book gives a comprehensive introduction the basics. Like most of the books, the real beauty lies in the chapters dedicated to the best practices of web development.

    4. Secrets of the JavaScript Ninja

    The book is written by John Resig, the creator of the most famous JS library (JQuery), for an intermediate developer. It revise the basic concepts thoroughly, but it focuses on other key JavaScript concepts like closures, prototypes, objects and promises. APIs for DOM, events and timers are covered in great details. The part which I love of this book the testing and cross-browser development. It will prepare you to dig deeper in debugging hacks. The second edition of this book is rewritten to cover ES6 and ES7 concepts.

    5. You Don't Know JS: Scope & Closures

    The author of this book has put an adequate amount of energy to show you the inner working of the two core JavaScript concepts, scope and closure. It tells you how to analyze variables and follow up nested scope. It is a brief but an extensive guide to look deeper into functions, patterns and scope based hiding. The most attractive part of this book is its introduction to building your own libraries.

    7 Things You Need To Know about Programming: The Art of Programming

    courtesy of SafeTrac

    Is it enough to learn a single programming language and live with it?

    Like working in a single language for the entire life? Oh C’mon

    My answer is big NO. I mean not at all. A single language can work pretty much everywhere but one language that performs well somewhere does not mean that it will perform that much good elsewhere. There is always a better choice available.

    For example JavaScript works best in web applications but it won’t work the way Python woks for Data science. I hope you got the point.

    To get your hands on a well-paid job, or to make an attractive freelance profile or to pursue further studies in computer you should master one and get familiar with at least 3 languages.

    Let’s throw the blue collars, white collars, t-shirts and whatever out of the scope of this article and focus on students only.

    If you have read my previous post, if you haven’t then I would recommend you read it first, then you should have got the idea that it is pretty handy to end up with many choices. But in terms of programming, how could someone manage all the stuff? How to switch to a new language? Does it take as much long as it took to learn the first language?

    No, it is easier than you think.

    How? We cheat.

    If you can work in a single programming language it means that you can work in other languages too. It will take you approximately 2 weeks or so to learn a new language but there is a learning approach which helps to achieve such an amazing result. 

    Without any further ado, let’s dive in.

    In order to increase your learning curve exponentially, you should know the fact that there are many things common in almost all programming languages. Learn one and master all. I will list a few here:

    1. Data structures
    2. Conditional statements
    3. Iterators / Loops
    4. Functions
    5. Class and Object
    6. Inheritance
    7. Polymorphism

    In all enlisted terms above, the common thing is the concept and the difference is the syntax. To build a program you will need to make an algorithm and to create an algorithm you will use pseudo code which has no syntax but concepts. Google can surely tell us syntax for all languages, then why we would waste our own natural storage? And believe me nobody remembers syntax. If you don’t believe me then go and watch live programming sessions. You will get your answer.

    It’s time to work with the list. 

    1. Data structures

    The most common thing is all computer languages is Data Structure. A variable will always be a variable and an array will always be an array, every time, everywhere. What is a variable? A name of memory location. What is does? Stores data. What data? The data you give it. I mean the common thing is its functionality, to store value. The difference is the limitations that different languages impose. For instance, Java does not allow you to put a string data in an integer variable but JavaScript allows. Same is the case with other data structures.

    2. Conditional Statement

    The switch statement, if and nested if else structure are conditional operator are conditional statements. The common thing is the overall structure. They all have a test condition, a true block and a false block. If the condition is true, true block runs and if the condition is false, the false block runs. The difference is their syntax.

    3. Iterators / Loops

    Every language that I have ever SEEN uses loops for repeated execution of a block of code. You will never see a loop used for something else. All you need is to feed this to your mind that anywhere you need some repetitive execution, the choice is loop. Whether you are working in java or python or a super complex alien computer language.

    4. Functions

    Functions, methods, procedures or whatever you call it is a way to avoid writing some code again and again and again. The purpose of functions is to save you time, space and money. Functions save money? It does not make any sense.

    Time is money.

    Jokes apart. Functions have 4 things in common. A name, input parameters, return data and a call to the function. That’s it. Although different languages have different rules for naming functions but almost in all languages functions do the same job.

    5. Class and Objects

    If we go with the traditional boring definitions then class is a blue print and an object is an instance of class. Class have methods and variables and we need to create object to use the class members, excluding static members.

    You will have to create objects if you need to use the functionality provided by the class whether you are working in CPP or Java or whatever else Object Oriented language. This is the common thing.

    The difference is in the syntax. Like new keyword is used to create object in Java while in CPP new isn’t needed.

    6. Inheritance

    Where there is a will there is a way and where there is OOP there is inheritance. The parent child business.

    Inheritance is a common concept of OOP where a child class inherits some properties or behavior from another parent class. The story is the same everywhere, a child parent relation. The difference is in the syntax. Also, some languages allow one type of inheritance while others allow the other type. 

    For instance, C++ allow single, multiple and multi-level inheritance and Java does not allow its users to use multiple inheritance. Although Java developers cheat with java for multiple inheritance but this is off the topic.

    7. Polymorphism

    Polymorphism means many forms. In OOP, a function have the same name but different implementations. It sounds like function/method overloading but it has nothing to do with function overloading.

    Overloaded functions belong to the same class, having the same name but different parameters. Polymorphic functions belong to different classes. To achieve polymorphism, it is necessary to have more than one classes while for method overloading a single class is necessary. 
    Above theory is common in all object oriented languages. The difference is the way how polymorphism is used.

    In C++, virtual keyword is used in combination with inheritance (inheritance is necessary) however in JAVA, you do not necessarily need to use inheritance. Interface is enough.

    Conclusion:

    Finally, we are at the end. I tried to be specific, to the point. I will write in details about each of above. To summarize, invest more of your time in understanding the concepts of programming rather than the syntax of a language. Once you master all these, it will take you less than a month to learn a new language.

    The above list is not complete. I mean we can add more things but for brevity, I picked these few very basic building blocks of programming.

    Happy coding…

    What is Multithreading? JAVA Multithreading Tutorial


    It is almost end of 2017. The computer has evolved throughout its age from a simple, huge machine which was used for just simple numerical calculations to a small and swift electronic device which is affecting almost every aspect of our life. There are a lot of efforts involved in these enhancements in both hardware and software. Powerful hardware has been invented, and robust software techniques have been designed to improve hardware efficiency. One of these methods is multithreading and this is what we are going to talk about.
    Multithreading is the ability of a single processing unit to execute multiple programs concurrently, apparently supported by the operating system. Multithreading is achieved either by multithreaded architecture or by software techniques or by both. All processors and OSs today support multi-thread execution.
    We are talking about multithreading but what actually a thread is? A thread is a single unit a single processor can execute. The group consists of the shortest sequence of programmed instructions that are independently managed by operating system. Do not confuse thread with process and multithreading with multiprocessing. A running program, code to which processor is currently assigned is called a process while a thread may be the subpart of a process. A single process can have more than one threads. Multiple threads can share the same resources such as memory while processes do not share any resource with each other.

    Advantages of multithreading:

    Responsiveness: 

    In a one-thread process, if the main execution thread blocks on a long-running task, the entire application can appear to freeze. By moving such long-running tasks to a worker thread that runs concurrently with the main execution thread, it is possible for the application to remain responsive to user input while executing tasks in the background. So multithreading can allow an application to remain responsive to user input.

    Faster execution: 

    Multithreading allows parallel execution and parallel execution leads to improved CPU performance.

    Lower resource consumption:

     Different threads of the same process share same resources.

    Better system utilization:

     In a single thread execution, resources can remain idle for some time. Multithreading technique does not allow any resource to be blocked and make use of it by a thread which requires the resource.

    Simplified sharing and communication: 

    Threads can communicate through data, code, and files they already shared. Unlike processes, threads do not require a message passing or shared memory mechanism to perform inter-process communications.

    Parallelization: 

    Applications running on multi-core or multi-CPU systems can use multithreading to divide the data and tasks into independent subtasks and let it run in parallel or concurrently.

    The life cycle of a Thread:

    A thread goes through different stages of its life cycle. It can be in one of the following states.
    NEW – A thread that is just created and not yet started.
    RUNNABLE – A thread in execution is in this state.
    BLOCKED – a thread that is waiting to gain access to some resources is in BLOCKED state of the life-cycle.
    WAITING – A thread is in WAITING state if it is waiting for another thread to complete execution.
    TERMINATED – A thread that has completed its execution.

    Java multithreading example: 

    In Java, multithreading can be achieved in multiple ways. We are going to talk about 3 methods here.
    1. By implementing Runnable interface.
    2. By extending Thread class
    3. By creating Thread object

    1. By implementing Runnable interface:

    MyThread.java
    public class MyThread implements Runnable{
    
     int threadNum;
     int t;
     
     public MyThread(int threadNo) {
      this.threadNum = threadNo;
      t = 10;
     }
     public void run() {
      for (int  i = 0; i < 10; i++) {
       System.out.println("thread#" + threadNum + " : " + t);
       t = i;
      }
     } 
    }
    MainClass.java
    
    public class MainClass {
     public static void main(String[] args) {
      ExecutorService application = Executors.newCachedThreadPool();
      application.execute(new MyThread(1));
      application.execute(new MyThread(2));
     }
    }
    

    2. By extending Thread class:

    MyThread.java
    public class MyThread extends Thread{
     int threadNum;
     public MyThread(int num) {
      threadNum = num;
     }
     
     public void run () {
      for (int i = 0; i < 10; i++)
      System.out.println(i + " at thread: " + threadNum);
     }
    }
    
    MainClass.java


    
    public class MainClass {
    
     public static void main(String[] args) {
      MyThread t1 = new MyThread(1);
      MyThread t2 = new MyThread(2);
      
      t1.start();
      t2.start();
     }
    
    }
    

    3. By creating Thread object:

    
    public class MainClass {
    
     public static void main(String[] args) {
      Thread t1 = new Thread(new Runnable() {
    
       public void run() {
        for (int i = 0; i < 10; i++)
         System.out.println("thread 1 running");
       }
       
      });
      Thread t2 = new Thread(new Runnable() {
    
       public void run() {
        for (int i = 0; i < 10; i++)
         System.out.println("thread 2 running");
       }
       
      });
      
      t1.start();
      t2.start();
     }
    }
    
    If you have any question, ask in the comments. I will try to respond ASAP.

    5 Tips for Computer Science Students

    5-tips-img
    You are in college now so I am skipping the basics the go to class do your homework study for tests stay out of the hospital. These are not all important pieces of advice but I am sure you have heard them. Instead, let’s talk computer science. Here are some tips I have specially collected by talking to students who wish they’d heard them when they were students. Listen up.

    1. Seek help when you need it. Your classes are going to get harder, they are going to test your knowledge but that’s why you are there for. Some people find attending office hours or seeking extra help to be embarrassing. But these resources are there for a reason. Taking advantage of the help you are offered will not only help you prepare for future classes and learn the material better but a lot less harmful than bad grades or any other consequences of struggling.
    2. Don’t let yourself intimidated by large projects. The best thing to do, sit down a day at the assignment and break it up into smaller tasks. A lot of times it’s looking at the smaller tasks that help you realize the solution and even if it does not, you’ll only have to face one small problem at a time instead of a huge and overwhelming one.
    3. Error can be unpredictable for don’t procrastinate even if you see the solution right away. You still can’t really predict the types of errors you are going to face. It’s time to compile or if there’d logical errors when you run it. Sometimes it may be the slightest error that can be the hardest to catch. So make sure you leave yourself enough time to tackle it.
    4. Silly errors are no small things is computer science. One silly error can ruin the entire program and likewise, you are great. It is not uncommon for computer science classes to skip partial credit. If your code does not work you make it nothing for it. A more compassionate professor might throw you off 50% but the truth is that one little missing semicolon that you were too tired to find before returning your homework can be all it takes to turn an A into an F. So, don’t miss the semicolon.
    5. Stop and compile regularly. If you compile your projects on regular basis, you can solve errors as they appear and locating them would be easy because they could only appear since the last time you compiled. I know it can be annoying to get your program to a stopping point or you can do this but it’s definitely worth it. The alternative is getting all the errors at the end and there could be a lot of them. All hidden throughout your code, the code you wrote who knows how long ago and make sure you test sample code before you use it. There is nothing worse than just assuming that it works only to find out it’s the source of your problem and the one place you didn’t look.

    Subscribe for more.

    JSON with JAVA – Introduction to JSON – Part2

    JAVA SE does not have any internal package for processing JSON data. We have to import an external library. There are many libraries available. You can choose any. I will use Json-simple1.1 here. This makes our first step, importing the lib.

    Importing the lib

     Click here and download the zip file containing the jar library and follow the following steps to import it into eclipse.
    1. Extract the zip file.
    2. Right Click on the project folder in the package explorer, hover over Build Path and click on Configure Build Path.
    step2-img
    3. You will see a nice window. Go to the Libraries tab and click on Add External JARs.
    step3-img
    4. Navigate to the extracted jar folder, select the library and press open/ok.
    5. Press ok again and you are done.

    Exploring the lib

    The library contains parser and data structures to process the given JSON formatted string. The parser parses the JSON data from string/Reader to its own readable form. The data structures consist of JSONObject and JSONArray Classes which store JSON Objects and JSON Arrays respectively. The library has a bunch of other classes and methods but we will confine ourselves to only these three classes (JSONParser, JSONObject, JSONArray). Within these classes, we will use few methods. Why? Because it is just to get you started with JSON. Ok, Whatever. Let’s get started.

     JSONParser

    Constructor

    public JSONParser()

    Public methods

    public Object parse (Reader);
    public  Object parse (String);
    public Object parse (Reader, ContainerFactory);
    public Object parse (Reader, ContainerHandler);
    public Object parse (String, ContainerFactory);
    public Object parse (String, ContainerHandler);
    public Object parse (Reader, ContainerHandler, Boolean);
    public Object parse (String, ContainerHandler, Boolean);
    Above mentioned methods do the same work with different approaches. We will use parse (String) in our code just to make it work easily.

    JSONObject and JSONObject

    We will initialize these two classes from the JSONParser object and use their following methods:
    public Object get (Object); // to read
    public Object put (Object, Object); // to write to a JSON object
    public boolean add (Object) // to write a single entry at the end of a JSON array
    public Boolean add (int, Object) // to write a single entry at int index of a JSON array
    public Boolean addAll (Collection) // to write a collection of entries to a JSON array
    public Boolean addAll (int, Collection) // to write a collection of entries at int index of a JSON array
    To read from JSON you should know that the structure you are reading from JSON is whether a JSONObject or JSONArray and what is its name or index. We will have to pass this information in the get method.

    Writing Code

    Reading from JSON file “example.json”

    • Preparing the file to read from

    File file = new File("example.json");
    FileReader fr = new FileReader(file);
    BufferedReader bfr = new BufferedReader(fr);
    String jsonString = "";

    while (bfr.ready()) {
    jsonString += bfr.readLine();
    }

    • Initializing parser

    JSONParser parser = new JSONParser();

    • Obtaining the root element

    JSONObject rootObject = (JSONObject) parser.parse(jsonString); // we know that the root element of our file is a JSON Object that why parsing the result to JSONObject

    • Getting the hobbies Object

    JSONArray hobbies = (JSONArray) rootObject.get("hobbies");

    • Extracting the favorite books array

    JSONArray favBooks = (JSONArray) rootObject.get("fav_books");

    • Traversing the JSONArray

    for (int i = 0; i < favBooks.size(); i++) {
    JSONObject favBook = (JSONObject) favBooks.get(i);
    System.out.println(favBook.get("name") + " by " + favBook.get("author"));
    }


    Get the full source code here.

    Writing to JSON file “example2.json”

    • Getting the file ready to write

    FileWriter fwriter = new FileWriter(new File("example2.json"));
    BufferedWriter bfwriter = new BufferedWriter(fwriter);

    • Initializing and populating ArrayList

    ArrayList<String> fruits = new ArrayList<String>(); // Collection of entries
    fruits.add("Apple"); // populating collection
    fruits.add("Orange");
    fruits.add("Peach");

    • Initializing JSONObject and JSONArray

    JSONArray jArray = new JSONArray();
    JSONObject jObject = new JSONObject();

    • Populating the objects

    jArray.addAll(fruits); // collection added to json array
    jArray.add(0, "Srawberry"); // a single entry added at 0 index

    jObject.put("fruits", jArray); // JSON array added to JSON object

    • writing to file

    bfwriter.write(jObject.toJSONString());

    Get the full source project here.

    Give us your feedback by commenting and by participating in the survey. You are doing great, keep it up, see you in the next post.

    Introduction to JSON – Part 1

    json-img
    JSON is a data interchange format, frequently used for data exchange between clients and servers across the web. I am dividing this short tutorial series into three parts just to make it easy for you to understand. Part 1 is an introduction to JSON. It shows what is JSON, its structures are and how to write a JSON document. Part 2 explains How to process JSON in JAVA. The last part includes JSON Serialization. Hold your breath, a lot is coming up.
    JSON, short for JavaScript Object Notation is a lightweight format which makes data exchange more than easier. It is also used to store data. JSON is language independent. For example, you can make a JSON Object in java and send it to a C# program which will gracefully handle it. JavaScript object can be converted into a JSON object and vice versa.
    A JSON document can have two structures.

    • JSON Object: A name value pair or a key value pair. Names/Keys are only strings however values are of various types. Name and value are separated by a single colon (:). JSON Object is contained within the curly braces.


    Name : Value,
    }

    • JSON Array: An ordered sequence of values stored in square braces separated by a comma.

    [
    Value,
    ]
    Types of Values: These types should be familiar to you and may not need any explanation. A value can be a

    1. String
    2. Number
    3. Bool (True/False)
    4. JSON Object
    5. JSON Array

    A JSON value can also be null.
    The file which contains JSON data is stored with .json extension. Following is an example document named Example.json. Study it and identify different structures and value types.
    Example: Example.json
    {
    "first_name": "Salman",
    "last_name": "Ahmad",
    "gender": "male",
    "age": 22,
    "hobbies": [
    "video games",
    "drawing",
    "music"
    ],
    "fav_books": [
    {
    "name": "The Shallows",
    "author": "Nicholas G. Carr"
    },
    {
    "name": "Brain Bugs",
    "author": "Dean Buonomano"
    }
    ]
    }
    Next is How to process JSON data in JAVA. We will use this example in our code. See you there.

    Translate