CHAPTER 10: EDITION 8
The art of telling future developers (including yourself) what the heck your code does
Look, I've written the most GLORIOUS code ever created. This final project is going to BLOW. PEOPLE'S. MINDS. We're talking innovation that makes quantum computing look like an abacus!
WHAT IS THIS ABOMINATION?! There's not a SINGLE comment in this ENTIRE codebase! HOW IS ANYONE SUPPOSED TO UNDERSTAND YOUR DERANGED LOGIC?! It's a SECURITY NIGHTMARE!
I hate to agree with Grumpy, but he's right. This code is completely undocumented. No comments, no README file... it's like you're actively trying to confuse everyone.
Comments? README? Who needs 'em! Good code is self-explanatory. If you can't understand my artistic vision by just LOOKING at it, maybe you should find another profession. Like goat herding.
Um, I'm having trouble figuring out what this function is supposed to do... and why it's named "destroyTheWorld"?
This is precisely why my premium clients pay extra for comprehensive documentation. It's like buying a luxury car – you expect the manual to be printed on fancy paper with diagrams, not scribbled on a napkin.
Legally speaking, undocumented code is a liability time bomb. When you inevitably get hit by a bus – or more likely, when Snowzie finally snaps after you steal her treats one too many times – no one will be able to maintain this.
Fine! FINE! I'll add some stupid comments. But they'll be ARTISTIC comments. VISIONARY comments. Comments that will make Shakespeare look like he was just keysmashing!
Code tells you how. Comments tell you why.
Exactly. And let's not forget the README file. It's like the cover letter for your code – it explains what your project does, how to install it, how to use it, and any other information someone might need.
README? More like DON'T-README, am I right? *crickets* ...Okay, FINE. Let's get this documentation party started. But I'm warning you – my genius doesn't conform to conventional commenting standards!
Other developers need to understand your code to work with it effectively. Good documentation makes collaboration possible and reduces the "bus factor" (what happens if you get hit by a bus?).
Future you will thank present you. Even after a few weeks, you'll forget why you wrote code a certain way. Documentation is a gift to your future self.
Documentation increases a project's lifespan and usability. Undocumented code becomes "legacy code" much faster and is more likely to be abandoned.
Documentation isn't just busy work – it's an essential part of professional development. Even the best code is useless if no one can understand or maintain it.
Think of it as insurance for your code's value. The most expensive code is the code that works perfectly but that nobody can understand how to use or modify.
Alright, I'm ready to grace this code with my commentary brilliance. How do you want me to comment? Single-line? Multi-line? ASCII art? Interpretive emoji dance?
Let's start with the basics. There are different types of comments for different purposes.
// Single-line comments are great for brief explanations function calculateScore(clicks, multiplier) { // Add bonus points for combos over 10 let bonus = clicks > 10 ? 50 : 0; return clicks * multiplier + bonus; }
Single-line comments are created with // Your comment and are ideal for short explanations. Use them to explain why a piece of code exists rather than what it does (which should be obvious from the code itself).
/* * Multi-line comments are useful for longer explanations * that need multiple paragraphs or when you want to * comment out large blocks of code temporarily. * * They're also good for section headers to divide your code * into logical segments. */ /* ----------------------------------- * GAME STATE MANAGEMENT * ----------------------------------- */ class GameState { // Class implementation... }
Multi-line comments start with /* and end with */. They're useful for more detailed explanations, temporary code removal, and creating visual breaks between sections.
/** * Calculates the player's score based on clicks and multiplier * * @param {number} clicks - The number of successful clicks * @param {number} multiplier - The current score multiplier * @returns {number} The calculated score with any applicable bonuses * @example * // Returns 150 * calculateScore(5, 30) */ function calculateScore(clicks, multiplier) { let bonus = clicks > 10 ? 50 : 0; return clicks * multiplier + bonus; }
Documentation comments (like JSDoc for JavaScript) provide structured information about functions, classes, and methods. They support special tags that can be processed by documentation tools to generate reference documentation.
Common tags include @param, @returns, @example, @throws, and @deprecated.
// TODO: Add support for power-up items function processClickEvent(event) { // FIXME: Currently doesn't work on mobile devices updateScore(); // HACK: Temporary workaround until we fix the animation glitch setTimeout(resetAnimation, 100); // NOTE: This approach might cause performance issues with many objects updateAllGameObjects(); }
Special comment flags help highlight areas that need attention. Common flags include:
Many code editors recognize these flags and provide special highlighting or task lists for them.
function process(data) { const threshold = 0.85; let results = []; for (let i = 0; i < data.length; i++) { if (data[i].value > threshold) { results.push({ id: data[i].id, score: (data[i].value - threshold) * 100, priority: data[i].value > 0.95 ? "high" : "medium" }); } } return results.sort((a, b) => b.score - a.score); }
What does this function do? Why is 0.85 important? What do the results mean? Without comments, these questions are left unanswered.
/** * Processes game data to identify high-performing elements * that exceed our minimum quality threshold * * @param {Array} data - Array of game elements with .value properties * @returns {Array} Sorted results with calculated scores and priorities */ function process(data) { // Minimum quality threshold for elements (85%) const threshold = 0.85; let results = []; // Process each element to calculate scores for (let i = 0; i < data.length; i++) { // Only include elements above our quality threshold if (data[i].value > threshold) { results.push({ id: data[i].id, // Convert to percentage points above threshold score: (data[i].value - threshold) * 100, // Elements above 95% get high priority priority: data[i].value > 0.95 ? "high" : "medium" }); } } // Sort by score in descending order return results.sort((a, b) => b.score - a.score); }
Now it's clear what the function does, why certain values are used, and how the results are calculated. Future developers can understand and modify this code more easily.
DON'T OVER-COMMENT! Comments that just repeat what the code obviously does are WORSE than no comments at all! They create MAINTENANCE NIGHTMARES!
Good comments explain "why," not "what." If your code needs comments to explain what it does, rewrite the code.
// increment counter for counter++)
Fine, I've added some perfect comments to my code. Happy now? But just so you know, my variable names are so genius they're practically self-documenting!
Oh really? Let me see... *looks at screen* You have variables named 'x', 'temp', 'stuff', and my personal favorite, 'magicNumber42'...
It's called being EFFICIENT! Why waste perfectly good bytes on long, descriptive variable names?
Modern compilers optimize code size. Descriptive variable names cost nothing in production but save hours of debugging time.
Now that we've fixed the comments, let's talk about the README file. It's the first thing people see when they visit your project, and it's essential for explaining what your project does and how to use it.
I always get confused about what to include in a README... is there a standard format?
A short, memorable name for your project.
A clear, concise explanation of what your project does and why it's useful.
List the key features of your project.
Step-by-step instructions on how to install and set up your project.
Examples showing how to use your project, with code snippets and screenshots.
List the technologies, frameworks, and libraries used in your project.
Information about the license your project is under.
(Optional) Guidelines for how others can contribute to your project.
(Optional) Acknowledgments for any resources or people who helped with the project.
(Optional) Information about how to reach you for questions or feedback.
# Clicker Hero A fast-paced clicker game where players earn points by clicking targets that appear and disappear at increasing speeds. ## Features - Dynamic targets that appear in random locations - Progressive difficulty with faster targets - Score tracking with high score display - Sound effects for successful clicks and game events - Multiple game states (start, playing, game over) ## Installation 1. Clone the repository: git clone https://github.com/yourusername/clicker-hero.git 2. Open the project folder 3. Launch `index.html` in your web browser ## Usage 1. Click "Start Game" to begin 2. Click on targets as they appear to earn points 3. Try to click as many targets as possible before the timer runs out 4. Your high score will be saved locally ## Technologies - HTML5 - CSS3 - JavaScript - Web Audio API for sound effects - Local Storage for saving high scores ## License This project is licensed under the MIT License - see the LICENSE.md file for details. ## Credits - Sound effects from [Freesound.org](https://freesound.org) - Font "Press Start 2P" from Google Fonts - Created as final project for McTweak.ai Web Development Course
# Heading 1 ## Heading 2 ### Heading 3 **Bold text** *Italic text* [Link text](https://example.com)  - Bullet point 1 - Bullet point 2 - Nested bullet 1. Numbered item 1 2. Numbered item 2 ```javascript // Code block function example() { return "Hello World"; } ``` `Inline code` --- > Blockquote text
Bold text
Italic text
[Image would display here]
// Code block
function example() {
return "Hello World";
}
This is Inline code within text
Blockquote text
README files are just bureaucracy! If people can't figure out how my brilliant code works by simply FEELING its energy, they don't deserve to use it!
Actually, a well-crafted README increases a project's perceived value by up to 83%. My premium clients specifically request extensive documentation. It's like the difference between a luxury car manual and a sticky note that says "pedal make go."
Example badges:
I found that having a good README has helped me a lot when I come back to my old projects. I can't tell you how many times I've opened something I made months ago and had no idea how to run it...
Exactly! Documentation isn't just for others—it's for your future self. Think of it as a time capsule message to future-you who has forgotten all the details of this project.
For your final project, you'll need to create a comprehensive README file. Let's practice by making one for the project you've been working on throughout this course.
Don't forget to preview your README! Markdown looks very different when rendered. You want the luxury experience, not the economy version.
And SPELL CHECK IT! Nothing says "MY CODE IS PROBABLY JUST AS SLOPPY AS THIS DOCUMENTATION" like a README full of typos and grammatical ATROCITIES!
Explain the "why" behind your code, not just what it does. Use comments to clarify complex logic and document non-obvious decisions.
Create a comprehensive guide that helps others understand your project, how to install it, and how to use it effectively.
Good documentation makes your project maintainable over time, both for yourself and for others who may work on it.
FINE, I've added comments to my code AND created a README. Are you all happy now? Can I go back to creating digital masterpieces that will revolutionize computing as we know it?
Let me check... *reviews code and README* This is... actually pretty good! Your comments are helpful, and the README covers everything a user would need to know.
Wow, I can actually understand what the code is doing now! And look, the README even has screenshots and examples!
Almost premium quality. I might only charge a 15% consulting fee if I were to improve it further.
You know what? I hate to admit it, but it does feel good having everything documented. Now people can truly appreciate my genius instead of being confused by it!
I think we're ready for final approval. Should we call Snowzie in to review?
*excitedly woofs and spins in a circle before pawing approvingly at the screen*
CODE IS COMMITTED!
In the next episode, we'll focus on preparing for your final project presentation. You'll learn how to showcase your work effectively and demonstrate both its functionality and your technical knowledge.
Chapter 10, Episode 9: Presentation Prep