Coding Tricks

These are good tricks for coding.

Use Data Structures

See Data Structures section.

Use separate file to declare class / struct or different new data structure (also the functions that handling those objects will be in this file, like list data structure getNext function that returns the next element in the list) , and import/include it in the files that use this structure.

Use object oriented to manage them efficiently.

Optimize Iterating Lists and Arrays

Use map, filter, reduce (this is in Javascript and available in more languages such as Python with different syntax).

Reduce Use Of If-Else Statements

Reduce use of if else statements by doing these steps:

Reduce Use Of Certain Values Multiple Times

Use constant variables.  (Enum is good for this).
You can add "config" file that creates those variables and import the file in other files.

Reduce Use Of Stack Memory

use static for repeated used variables or large arrays (static use data segment and not stack memory, so it will prevent stack overflow error).
You can use heap memory for large arrays.

Handle Errors

Handle errors efficiently:

Debugging

Use the power of debugging.

See more in Debug section.

Reduce Amount Of Typing

Reduce amount of typing with code snippets.

Events

Use events.
For example, in html onclick event - when user clicks a button.

Functions Parameters

Use default values if it is valid structure of the logic of the function.

Split String To Substrings

Use split function (it is available in many programming languages).
For example split "hello world 123" by whitespace (" ") and it will return an array: ["hello", "world", "123"].

Check  Time Taken To Execute Piece Of Code

Use time library:

start = time.now
Some code...
end = time.now
total = end - start

Ternary Expressions

Use ternary expressions to shorten if statements.

Python: True if condition else False
Java: condition ? True : False

GIT

Use GIT version control system to keep track of your work and work with teams efficiently.
See GIT page for more information.

Framework

Software framework is an abstraction in which software providing generic functionality can be selectively changed by additional user-written code, thus providing application-specific software.

It provides a standard way to build and deploy applications and is a universal, reusable software environment that provides particular functionality as part of a larger software platform to facilitate development of software applications, products and solutions.

Software frameworks may include support programs, compilers, code libraries, tool sets, and application programming interfaces (APIs) that bring together all the different components to enable development of a project or system.

Examples of frameworks are Laravel and Angular.

Important note: not every library is perfect. It can contain bugs.

Up Next

No software development process is complete without thorough testing. In the next step, we explore various testing techniques and methodologies to ensure the quality and reliability of your applications. You'll learn about unit testing, flow testing, and other testing approaches that help identify and fix issues early in the development cycle.