1721576156

Mistakes made by inexperienced programmers with codes and programming languages


### 1. Not understanding the fundamentals of the language: + Mistake: Using a language without understanding its peculiarities and basic syntax. + Consequence: Frequent bugs and inefficient code. ### 2. Ignoring the importance of comments: + Mistake: Not adding explanatory comments to the code. + Consequence: Difficulty in maintaining and understanding the code in the future. ### 3. Not following naming conventions: + Mistake: Using confusing or inconsistent variable, function and class names. + Consequence: Code that is difficult for other developers to read and understand. ### 4. Failure to handle exceptions properly: + Mistake: Not implementing error and exception handling. + Consequence: Applications that fail unexpectedly without providing useful feedback. ### 5. Underestimating the importance of testing: + Mistake: Not writing unit or integration tests. + Consequence: Undetected bugs that can cause problems in production. ### 6. Copy and paste code without understanding: + Error: Copying code from sources such as Stack Overflow without understanding what it does. + Consequence: Introducing bugs and security vulnerabilities into the code. ### 7. Not versioning the code: + Error: Not using version control systems such as Git. + Consequence: Loss of change history and difficulty collaborating with other developers. ### 8. Writing code without modularity: + Error: Creating monolithic functions and classes without separation of responsibilities. + Consequence: Code that is difficult to maintain and scale. ### 9. Not optimising performance: + Mistake: Ignoring code optimisation practices, such as choosing efficient algorithms. + Consequence: Slow applications and excessive consumption of resources. ### 10. Falta de documentação: + Erro: Não fornecer documentação para o código ou APIs. + Consequência: Dificuldade em usar, manter e expandir o software. ## <br>Code snippets illustrating these errors Javascript ```js // Clear comments and naming conventions // 1. Understand the language fundamentals var x = "10"; if (x === 10) { console.log("Equal"); // Will not be equal because we are comparing type and value } // 2. Clear comments /** * Sums two numbers * @param {number} a - First number * @param {number} b - Second number * @returns {number} - The sum of the two numbers */ function sum(a, b) { return a + b; } // 3. Naming conventions var name = "John"; // 4. Exception handling function divide(a, b) { if (b === 0) { throw new Error("Division by zero"); } return a / b; } // 5. Unit tests (example with Jest) /* test('sum of 1 + 2 should be 3', () => { expect(sum(1, 2)).toBe(3); }); */ // 6. Understanding copied code try { var data = JSON.parse('{"name":"John"}'); } catch (e) { console.error("Error parsing JSON:", e); } // 7. Version control // Put this code in a Git repository // 8. Modularization function sum(a, b) { return a + b; } function divide(a, b) { if (b === 0) { throw new Error("Division by zero"); } return a / b; } console.log(sum(10, 20)); console.log(divide(10, 2)); // 9. Performance optimization for (let i = 0; i < 1000; i++) { // Limit the number of iterations console.log(i); } // 10. Documentation /** * This file contains sum and divide functions, as well as a demonstration loop. */ ``` php ```php <?php // Clear comments and naming conventions // 1. Understand the language fundamentals $x = "10"; if ($x === 10) { echo "Equal"; // Will not be equal because we are comparing type and value } // 2. Clear comments /** * Sums two numbers * * @param float $a First number * @param float $b Second number * @return float The sum of the two numbers */ function sum($a, $b) { return $a + $b; } // 3. Naming conventions $name = "John"; // 4. Exception handling function divide($a, $b) { if ($b == 0) { throw new Exception("Division by zero"); } return $a / $b; } // 5. Unit tests (example with PHPUnit) /* class MyTest extends PHPUnit\Framework\TestCase { public function testSum() { $this->assertEquals(3, sum(1, 2)); } } */ // 6. Understanding copied code $json = '{"name":"John"}'; $data = json_decode($json); if (json_last_error() !== JSON_ERROR_NONE) { echo "Error parsing JSON: " . json_last_error_msg(); } // 7. Version control // Put this code in a Git repository // 8. Modularization function sum($a, $b) { return $a + $b; } function divide($a, $b) { if ($b == 0) { throw new Exception("Division by zero"); } return $a / $b; } echo sum(10, 20); echo divide(10, 2); // 9. Performance optimization for ($i = 0; $i < 1000; $i++) { // Limit the number of iterations echo $i; } // 10. Documentation /** * This file contains sum and divide functions, as well as a demonstration loop. */ ?> ``` Correcting these errors can lead to cleaner, more efficient and easier-to-maintain code. It's important to take the time to learn good development practices and standards from the outset.

(0) Comments

Welcome to Chat-to.dev, a space for both novice and experienced programmers to chat about programming and share code in their posts.

About | Privacy | Terms | Donate
[2024 © Chat-to.dev]