Basic Coding Mistakes
Experienced programmers still make simple coding mistakes. These errors can have serious, far-reaching consequences.
A compilation error is an error that prevents a program from being compiled into machine code that the computer can execute. These errors often result of the programmer mistyping code such as misspelling a keyword or omitting punctuation required by the programming language. These types of compiler errors are known more specifically as syntax errors.
Additional types of compilation errors include using the wrong operator. For example, in some programming languages the command x=1 assigns a value of 1 to the variable x, while the command x==1 compares the variable x to the constant 1. A programmer who uses x=1 to make an equality check in that programming language is making an operator error. Modern compilers often compile questionable code but issue a warning, and some compilers specifically protect the program from syntax errors. Compiler errors are the easiest to detect since they generally occur every time the compiler attempts to compile the program.
Programs with run-time errors can be compiled but they will generate an error when they are executed. This often occurs when the program attempts to perform an impossible operation such as division by zero, which is undefined in traditional arithmetic. Assume for this example that the statement x = y / z is syntactically correct but the value of z is zero when this code is executed. The compiler will compile the code but the code will generate a run-time error. No error will be generated if the value of z is not zero. Run-time errors are more difficult to detect than compiler errors since the occurrence of a run-time error depends on the value of variables at run time.
Additional types of runtime errors include resource errors in which the error causes a resource to exceed its limits, such as an access violation, buffer overflow, or stack overflow. A multi-threading error occurs when executed code in one thread produces a conflict with another thread. This typically occurs in a deadlock where thread A cannot continue until thread B completes, and thread B cannot continue until thread A completes. Performance errors may allow the program to execute, but they may lower the program’s performance to the point that the program is no longer useful.
Logic errors do not generate a specific error, although they do produce a result that the programmer did not intend. Assume for this example the variable String1 is initialized as a blank string and you forget to assign a meaningful value to String1. Assume further that you concatenate String1 to another string variable called String2 that contains a value. A display of this concatenated result will only show the value of String2, not the value of String1 and String2 as you intended. This scenario represents a logic error.
Logic errors are the most difficult to fix since they don’t produce specific error messages. Common types of logic errors include an arithmetic overflow or a rounding error that reduces the precision of a value below the acceptable minimum. Other logic errors include infinite loops and off-by-one errors.
Emmet M is a freelance writer available on WriterAccess, a marketplace where clients and expert writers connect for assignments.
Artisan Talent is a Digital, Marketing and Creative Staffing Firm placing talent in jobs perfectly matched with their skills all over the US. For available jobs, to submit your resume, or learn more about working with Artisan Talent, contact us here.