• 0

check my comments


Question

17 answers to this question

Recommended Posts

  • 0

The comments are ok but i have some suggestions I wouldn't comment that explains what the code is doing literally.

--Wouldn't use these--

//Increment by 1

//When count reaches 9 or above, check for winner -- this one is ok but its better to make it more generic

--Would use more like this--

//Check for placed "X" on buttons

//Display output if "X" wins

I would comment on modules or block of functionality rather than literally commenting what the code is doing

  • 0

The golden rule of comments: The code should describe WHAT is happening, the comments should explain WHY its happening.

If you have to write a comment explaining what a piece of code is doing, you should be re-writing it to make it more obvious. Comments like "// Increment by 1" are redundant, as I could very easily look at the code to figure that out. On the other hand, if a piece of code is doing something, but it's not immediately obvious WHY it's doing it, just add a brief comment to explain why the code is the way it is (for example, if you have to write a hack to work around a bug in someone elses code, explain why the hack is there).

  • 0

I comment the code in a way anyone reading it (that knows the language or not) understands it. My comments are almost pseudo code. So I do things like:

//Okay, first we need to build our query

string q = "SELECT..........";

//Now, we need the result to give us the items

string result = clsMain.Database.dbQuery(q);

//Now split it up to get all the parts

string[] split = result.Split(';');

//And finally loop through the results

foreach (string s in split)

if (s != null)

blah;

else

break;

//Now we move to getting the users....

  • 0

I comment the code in a way anyone reading it (that knows the language or not) understands it. My comments are almost pseudo code. So I do things like:

//Okay, first we need to build our query

string q = "SELECT..........";

//Now, we need the result to give us the items

string result = clsMain.Database.dbQuery(q);

//Now split it up to get all the parts

string[] split = result.Split(';');

//And finally loop through the results

foreach (string s in split)

if (s != null)

blah;

else

break;

//Now we move to getting the users....

Your comments shouldn't read like pseudo code. I wouldn't cater for people who aren't familiar with the language/framework. By over-commenting you are making the code harder to read for people who actually know the language/framework. The latter should be your audience since they are the ones who are most likely to be reading your code and have a use for it in the first place.

Do not describe what the code is doing. Just document why you are doing what you are doing.

You should also pick better variable names. Once you do that you'll find that the above code doesn't need to be commented at all. So, instead of saying something like:

//Okay, first we need to build our query
string q = "SELECT..........";[/CODE]

You'd do:

[CODE]string query = "SELECT..........";[/CODE]

Also, if you find yourself having to split strings that you've just grabbed from your database, you should consider moving that data out into another table.

  • 0

Your comments shouldn't read like pseudo code. I wouldn't cater for people who aren't familiar with the language/framework. By over-commenting you are making the code harder to read for people who actually know the language/framework. The latter should be your audience since they are the ones who are most likely to be reading your code and have a use for it in the first place.

Do not describe what the code is doing. Just document why you are doing what you are doing.

You should also pick better variable names. Once you do that you'll find that the above code doesn't need to be commented at all. So, instead of saying something like:

//Okay, first we need to build our query
string q = "SELECT..........";[/CODE]

You'd do:

[CODE]string query = "SELECT..........";[/CODE]

Also, if you find yourself having to split strings that you've just grabbed from your database, you should consider moving that data out into another table.

Trust me, I go through code that other people write, the last thing I want to do is figure out what the hell they were doing. I would rather just read the comment and know what they were thinking when they wrote it. There are a million and one ways to write a set of code. I'd rather not have to run through the code in my head (even though I know the language). So I do what works for me.

Also, when I pull date from a database I often pull multiple fields. I then split it up as not all the fields will be used for one thing.

For example.. I may pull a userID, userFirstName, userLastName, userEmail, userDOB. I then split it up and fill in the appropriate input fields with the data. I don't use Datasets, I don't use gridviews, I don't use built in database connections.

  • 0

Trust me, I go through code that other people write, the last thing I want to do is figure out what the hell they were doing. I would rather just read the comment and know what they were thinking when they wrote it. There are a million and one ways to write a set of code. I'd rather not have to run through the code in my head (even though I know the language). So I do what works for me.

You can figure out what the code is doing by reading the code itself. Trust me, it becomes second nature after a while and you won't need to translate the code to english in your head.

The thing with comments is that you can only trust them so far. Comments have to be maintained to and they can get outdated. At the end of the day, the code is what gets executed.

Don't over-comment. Don't repeat yourself.

  • 0

I always stick to javadoc conventions, and attach comments to the end of lines if needed. I also tend to use very verbose method names (which I guess is an overhang since my primary language is Objective-c, but it makes it much easier to understand your code later on, and makes life much easier for anybody who needs to change/refactor things).


/**
* Brief description of what the method does. Followed by a
* short description of why it does something, or how it does it
* (if it's a weird way/important/nice to know).
*
* @param x Description of variable x
* @param y Description of variable y
* @return What the method returns
* @throws IOException Reason for throwing an IOException
*/
public float calculateAreaOfCube(int x, int y) throws IOException
{
return (x*y);
}
[/CODE]

  • 0

I comment the code in a way anyone reading it (that knows the language or not) understands it. My comments are almost pseudo code. So I do things like:

//Okay, first we need to build our query

string q = "SELECT..........";

//Now, we need the result to give us the items

string result = clsMain.Database.dbQuery(q);

//Now split it up to get all the parts

string[] split = result.Split(';');

//And finally loop through the results

foreach (string s in split)

if (s != null)

blah;

else

break;

//Now we move to getting the users....

I read through a lot of code as well and these comments would annoy me. They're not adding anything at all. clsMain bothers me as well.

//Okay, first we need to build our query
string q = "SELECT..........";

Like another person said you could just name the variable query and remove the comment.

//Now, we need the result to give us the items
string result = clsMain.Database.dbQuery(q);

What does the result represent? Also, dbQuery method is pretty redundant. You're in the context of the database already so the db in front of query isn't needed.

//Now split it up to get all the parts
string[] split = result.Split(';');

Your comment is telling us that we're splitting the result into "parts". Well yeah, the code tells us that much. Actually, the code tells us more. What are the parts? Again, what does the original result represent? Meaningful variable names would go a long way. You could also refactor this into a new method with a descriptive name. The comment just isn't needed.

//And finally loop through the results
foreach (string s in split)
if (s != null)
blah;
else
break;

The comment isn't very useful. The foreach is a loop so we know we're looping. The variable names leave a lot to be desired so it's hard to guess what this is trying to do.

You could refactor this into a method as well and give it a descriptive name.

  • 0

I read through a lot of code as well and these comments would annoy me. They're not adding anything at all. clsMain bothers me as well.

//Okay, first we need to build our query
string q = "SELECT..........";

Like another person said you could just name the variable query and remove the comment.

//Now, we need the result to give us the items
string result = clsMain.Database.dbQuery(q);

What does the result represent? Also, dbQuery method is pretty redundant. You're in the context of the database already so the db in front of query isn't needed.

//Now split it up to get all the parts
string[] split = result.Split(';');

Your comment is telling us that we're splitting the result into "parts". Well yeah, the code tells us that much. Actually, the code tells us more. What are the parts? Again, what does the original result represent? Meaningful variable names would go a long way. You could also refactor this into a new method with a descriptive name. The comment just isn't needed.

//And finally loop through the results
foreach (string s in split)
if (s != null)
blah;
else
break;

The comment isn't very useful. The foreach is a loop so we know we're looping. The variable names leave a lot to be desired so it's hard to guess what this is trying to do.

You could refactor this into a method as well and give it a descriptive name.

As I described above.. my comments are like pesudo code. They explain my line of thinking and what I was doing when I wrote the code.

It's almost like a plain english version of the code. I try to reduce code as much as I can (methods only when required, non-temp variables when required, etc). I also name my things not based on the end context, but as it is now.

For example.. I call all my classes "cls[Name]" even though I could just do it as "Name". That's just how I program.

And the "clsMain" well it's the Main Class, and such it is named that.

  • 0

As I described above.. my comments are like pesudo code. They explain my line of thinking and what I was doing when I wrote the code.

It's almost like a plain english version of the code. I try to reduce code as much as I can (methods only when required, non-temp variables when required, etc). I also name my things not based on the end context, but as it is now.

I know. I read your original post. I just disagree with it. I just don't think "that's just how I program" is a good reason for doing anything. Anybody could say the same thing and we would never improve on anything. In 97 I was writing Perl with flat files. The code was awful and needed improvement. I could have said, "Well, this is just how I program" and dismissed improvement opportunities.

For example.. I call all my classes "cls[Name]" even though I could just do it as "Name". That's just how I program.

But why? Why do you do that?

And the "clsMain" well it's the Main Class, and such it is named that.

What's a main class? Are we talking about your program's entry point or is it a god object?

Everyone should really check out the book "Clean Code" by Robert Martin. I think it should be required reading for everyone.

  • 0

But why? Why do you do that?

Because it's how I was taught to name things, and I carried it on, and in my head when I am coding to me it is easier and cleaner. I know what to type when I want a class, I know what's what based on the start of the name.

What's a main class? Are we talking about your program's entry point or is it a god object?

Main entry point, the main class in which everything is initialized and set, where some global references are stored.

Also, the code in which the above would be used is inside of a .DLL File which follows an addon/module system I wrote to allow DLL files to be loaded dynamically by the parent program to add functionality (think of them like addons for WoW).

However the Addons can talk to each other without any direct references so the clsMain also holds the communication events and such necessary for this. It is also the location that the initial calls for initializing are made via the base program.

Everyone should really check out the book "Clean Code" by Robert Martin. I think it should be required reading for everyone.

I'll give it a look.

  • 0

I always stick to javadoc conventions, and attach comments to the end of lines if needed. I also tend to use very verbose method names (which I guess is an overhang since my primary language is Objective-c, but it makes it much easier to understand your code later on, and makes life much easier for anybody who needs to change/refactor things).


/**
* Brief description of what the method does. Followed by a
* short description of why it does something, or how it does it
* (if it's a weird way/important/nice to know).
*
* @param x Description of variable x
* @param y Description of variable y
* @return What the method returns
* @throws IOException Reason for throwing an IOException
*/
public float calculateAreaOfCube(int x, int y) throws IOException
{
return (x*y);
}
[/CODE]

I agree.

Commens should indicate how every function/member works. It is not quite needing to comment each part of the code, unless it requiress a special logic or it is too tricky (dragon-lies-here code for example)

This topic is now closed to further replies.
  • Posts

    • Microsoft Weekly: Xbox exclusives are back, big Windows app updates, and more by Taras Buria This week's news recap is here. Microsoft is returning to XBOX exclusives, Windows 11 gets new preview builds, the Low-latency Profile is here, big updates for inbox Windows apps, Patch Tuesday updates, and more. Quick links: Windows 10 and 11 Windows Insider Program Updates are available Reviews are in Gaming news Great deals to check Windows 11 and Windows 10 Here, we talk about everything happening around Microsoft's latest operating system in the Stable channel and preview builds: new features, removed features, controversies, bugs, interesting findings, and more. And, of course, you may find a word or two about older versions. The June 2026 Patch Tuesday updates are now publicly available. Windows 11 users can download KB5094126, which introduces plenty of new features and security updates, including the Low-latency Profile for better performance, shared Bluetooth audio support, and more. Windows 10 users with PCs enrolled in the Extended Security Update program can download KB5094127. In addition, Microsoft released new Defender updates for its operating systems. Speaking of Defender, Microsoft will now deliver EDR updates via Microsoft Update for faster security improvements independent of Patch Tuesday updates. Following the release of this month's Patch Tuesday updates, Microsoft also published new Windows 11 images available in the Media Creation Tool app. Now, you can create bootable USB media for clean Windows 11 installations with the latest releases. Some unfortunate stuff is going on with certain PCs from Dell and HP. Dell acknowledged that the SupportAssist bug causes black screens of death, while HP systems are suffering from Secure Boot update issues and boot loops. Both companies issued official advisories. Windows Insider Program Here is what Microsoft released for Windows Insiders this week: Builds Canary Channel Builds 29610.1000 and 28120.2302 This week's "Canary" builds only contain performance improvements and fixes, including the Low-latency mode, which is now available in the Stable channel for all Windows 11 24H2 and 25H2 users. Dev Channel Build 26300.8687 Microsoft brought some useful File Explorer changes with this build. You can now open folders in a new tab by middle-clicking them in the address bar. Beta Channel Build 26220.8680 and 28020.2298 Screen Tint, improved Windows Widgets, and other enhancements are included in this week's Beta releases. Release Preview Channel Builds 26200.8728 and 26100.8728 These builds also feature better widgets, new Windows Update controls, point-in-time restore, File Explorer improvements, and more. In addition to new Windows 11 preview builds, Microsoft announced that inbox Windows 11 apps now have their dedicated release notes in the official documentation. Also, Microsoft dropped massive feature updates for six apps, including Paint, Clock, Calculator, Camera, Media Player, Photos, and more. Updates are available This section covers software, firmware, and other notable updates (released and coming soon) delivering new features, security fixes, improvements, patches, and more from Microsoft and third parties. Google has some bad news for those still using MV2-based extensions in Chromium-based browsers, particularly Chrome. The company is now removing flags responsible for Manifest V2-based extensions (uBlock Origin is one of the most popular). However, some browsers resist this change, and Opera issued a statement that it will allow users to continue using MV2 extensions for as long as possible. While Microsoft is still not ready to share new details about MV2 extensions in Microsoft Edge, the company shared important details about the way it will be updating the browser going forward. Now, Microsoft wants to update Edge every two weeks across all platforms instead of the current four-week schedule (only the Extended Stable is exempt from this change). This week, Microsoft confirmed a useful new Teams feature that is coming to the messenger soon. It also detailed all the improvements that made the platform better for users in 2026. However, not all changes are great, as the company is moving ahead with the check-in feature, which many believe will lead to employee monitoring. PowerToys received a feature update this week. Version 0.100 arrived with a big rework for the Shortcut Guide, a new extension gallery for Command Palette, new Dock features, and plenty of other changes. Here are other updates and releases you may find interesting: Microsoft is bringing big performance improvements to OneDrive on Mac Popular Windows 11 file manager Files gets improved tags, layouts, and a new OneDrive icon New Outlook for Windows and Web is getting a simple but very useful email feature Microsoft had to shut down 70+ GitHub repos after getting hacked, bringing back some Microsoft AI boss no longer believes that AI will replace human workers Microsoft wants to end printer driver headaches with Windows Ready Print SQL Server Management Studio 22.7 brings "What's New" page, T-SQL formatting, and lots more Microsoft releases Visual Studio Code 1.124 with smarter autonomous AI agents Windows Server gets DNS over HTTPS (DoH) support Here are the latest drivers and firmware updates released this week: NVIDIA 610.52 Hotfix with multiple fixes for black screens of death, sleep issues, G-SYNC, and more. Reviews are in Here is the hardware and software we reviewed this week Steven Parker reviewed a rather unorthodox device here on Neowin this week. He took for a spin the DWARF mini, the world's smallest smart telescope for night and day sky captures. It tracks objects in the sky, has a sun filter, and has a low learning curve. There is also nice build quality and a quite affordable price. Pulasthi Ariyasinghe reviewed 007 First Light. The game turned out to be a satisfying spy adventure in the James Bond universe with great gunplay and combat, impressive crowds, over-the-top action sequences, and more. There are a few quirks here and there, but overall, the game scored high on our scale. On the gaming side Learn about upcoming game releases, Xbox rumors, new hardware, software updates, freebies, deals, discounts, and more. Microsoft held the latest XBOX Games Showcase this week. There, the company announced plenty of cool stuff, including a remake of Halo: Combat Evolved, a special 25th anniversary XBOX Series X with a classic translucent green design (coming in November 2026), details about Gears of War: E-Day, Spyro: A Realm Beyond after nearly 20 years since the last release, a new Hellblade game from Ninja Theory, a new expansion for DOOM: The Dark Ages, fresh details about State of Decay 3, and even a new entry in the Crazy Taxi series. More improtantly for XBOX fans, Microsoft announced the return of XBOX exclusives, with Gears of War: E-Day and Clockwork Revolution kicking it off. Microsoft also has some good news for Nintendo Switch 2 owners. Minecraft is coming natively to the second-gen Switch, offering better performance and new features, including the visual overhaul called "Vibrant Visuals." Playground Games revealed a 30-minute gameplay video of the upcoming Fable, showcasing combat, action, NPC simulation, relationships, and player choices. Additionally, the studio confirmed a bug with Forza Horizon 6 wiping saves for some gamers. It also had to shut down one of the game's online modes after users discovered an infinite money glitch. NVIDIA announced new games for the GeForce NOW streaming service and a big Summer sale that lets you get 12 months of GeForce NOW for $35 or $70 less, depending on the tier. Speaking of discounts, check out this week's Weekend PC Game Deals article, full of discounts and the latest freebies from the Epic Games Store. Great deals to check Every week, we cover many deals on different hardware and software. The following discounts are still available, so check them out. You might find something you want or need. GIGABYTE Radeon RX 9070 XT Gaming OC ICE 16G - $649.99 | 13% off 1TB Samsung T7 Portable SSD - $189.98 | 31% off AirPods Pro 3 - $179 | $50 off Edifier R1280Ts Powered Bookshelf Speakers - $129.99 | 24% off This link will take you to other issues of the Microsoft Weekly series. You can also support Neowin by registering for a free member account or subscribing for extra member benefits, along with an ad-free tier option.
    • Microsoft Flight Simulator's City Update 15 enhances Midwest cities by Pulasthi Ariyasinghe The third major city update of the year has landed for the original Microsoft Flight Simulator and the 2024 release. The latest drop is upgrading the visuals and regional accuracy of three metropolitan regions in the American states of Illinois, Minnesota, and Wisconsin. The 15th city update is adding eight new areas of interest that have been enhanced with high-fidelity TIN (triangulated irregular network) surface texturing in the mentioned regions. The free update highlights Chicago, Elgin, Cicero, and Arlington Heights in Illinois, as well as Minneapolis, St. Paul, Bloomington, Duluth, Brooklyn Park, Woodbury, Lakeville, Plymouth, and Blaine in Minnesota. In Wisconsin, the development has also upgraded the lands and buildings of Milwaukee, Madison, and Racine. The update lands just as one of the world's largest enthusiast flight simulation conventions, FlightSimExpo, kicks off in downtown St. Paul, Minnesota, on June 14. The Flight Sim development team's 40-minute keynote at the event can be watched here. At the same time, Microsoft is bringing the 6-seat, single-engine, multi-use light civil airplane Piper M600 into the game as a part of its Expert Series 2 program. This premium plane can be purchased from the in-game marketplace for $24.99. City Update 15: The United States Midwest is now available in Microsoft Flight Simulator, as well as the newer Microsoft Flight Simulator 2024, as an optional download. It can be accessed across Steam and the Microsoft Store for PC, Xbox Series X|S, and PlayStation 5, as well as Xbox and PC Game Pass subscriptions. Xbox One, mobile, and PC players can also jump into the new content using Xbox Cloud Gaming if they have a Game Pass Ultimate membership. The game must be updated to the latest version to download this free update from the in-game marketplace.
    • Five things you might have missed during Apple's WWDC 2026 by Aditya Tiwari Image: Apple Apple's annual developer event, WWDC 2026, happened from June 8 through June 12. We have already covered several new features and updates that the iPhone maker unveiled during the official keynote. Apple took Google's help and finally announced the upgraded Siri AI personal assistant, which now comes with an app. Moreover, a truckload of Apple Intelligence features took the center stage. That said, this year's WWDC is a bit different, and you might have noticed or missed the following stuff: Apple's ongoing unification of platforms Image: Apple One thing Apple is widely known for is its seamless hardware-software ecosystem. The company added a new chapter in 2020, when it began the Apple Silicon transition and launched macOS 11 Big Sur with native ARM support. Some major changes happened last year as well, when Apple renamed all of its operating systems to version 26 and introduced the Liquid Glass design language. Until WWDC 2025, Apple keynotes had dedicated segments for iOS, iPadOS, macOS, watchOS, and other operating systems, in which the company discussed each in detail. The WWDC 2026 keynote was different, and Apple allotted most of the screen time to Apple Intelligence and Siri. It didn't even publish separate press releases on its website for different operating systems. While it might seem surprising at first, it shows how Apple plans to move forward with its software ecosystem. Be it the Liquid Glass changes, child safety updates, or other features, they are mostly rolling out across multiple platforms. In other words, Apple is slowly blurring the line between its operating systems and achieving feature parity wherever possible. It's easy to rule out that someone in Apple's marketing team forgot to press the publish button. Everything is a calculated move when it comes to a company like Apple. Putting Apple Intelligence left, right, and center hints that the OS itself is no longer the product anymore. It's Siri, not Pepsi Time and again, various Apple products have been compared to unrelated things and turned into meme material. You might have heard about the "cheese grater" Mac Pro or the "trash can" Mac Pro, to name a few. It's Siri's turn this time. The upgraded AI assistant got a fresh logo, and people have started comparing it with Pepsi. There are other contenders, such as the Sony Ericsson logo and the Yin and Yang symbol. Shot on iPhone. Edited on Mac Image: Apple Apple has been putting the iPhone's camera muscles to the test on various occasions. Even NASA astronauts took it to Space earlier this year and captured some out-of-this-world photos. Recently, Apple TV streamed the first major live sporting event shot entirely on iPhone 17 Pro: an MLS match featuring the LA Galaxy vs. the Houston Dynamo FC. The 'Pro' iPhone has also been used to shoot Apple events in recent years. It's "Scary Fast" Mac event in 2023 was among the earliest attempts, and the tradition trickled down to the WWDC 2026 keynote, which ended with the tag line "Shot on iPhone. Edited on Mac." It's unsurprising to see Apple flexing the camera capabilities of its Pro models, especially when it has been baking professional-grade features, including ProRes RAW and Genlock. Hints for the foldable Apple has been sitting on the foldable iPhone for so long. There is still confusion over when the company will make it official. A recent report said that the iPhone Fold might get delayed as Apple is struggling to perfect its hinge mechanism. But Apple has been dropping hints here and there. A developer dug into the iOS 27 beta code and found internal references about device folding states. As verified by Macworld, the code includes references to "foldState" and "angleDegrees" internal status values, which are apparently designed to tell apps if a device is folded and at what angle. As of now, no other Apple device uses these states. The publication also found internal code suggesting Apple has been testing a device with both Touch ID and Dynamic Island, a combo that doesn't exist today. Last event as Apple CEO Image: Apple Tim Cook's bond with Apple is now almost three decades old, having started in 1998 as the SVP of Worldwide Operations. Back in August 2011, Steve Jobs stepped down as Apple CEO months before his passing, and Cook took charge. Now, the baton has been passed to the hardware chief, John Ternus, who will take over the role on September 1. WWDC 2026 is the last major Apple Event for Tim Cook as CEO. We have seen so much during Cook's tenure over the years, much of which defines Apple as we know it today. From new hardware product lines like Apple Watch, AirPods, Apple Vision Pro, and Apple Silicon, to boosting Apple's services business with Apple Music, Apple TV, Apple Pay, Apple Arcade, Apple Fitness+, Apple Care One, and more. That said, the first developer betas for Apple's latest operating systems are now available. You can check if your device is supported on iOS 27, iPadOS 27, macOS 27 Golden Gate, watchOS 27, and other platforms. What's your favorite feature that Apple announced this year at WWDC 2026? Tell us in the comments.
    • Trailer park trash “sport “, fits the current White House
  • Recent Achievements

    • Week One Done
      ssd21345 earned a badge
      Week One Done
    • Contributor
      MarkHughes4096 went up a rank
      Contributor
    • Dedicated
      jordanspringer earned a badge
      Dedicated
    • Rookie
      Rimplesnort went up a rank
      Rookie
    • One Year In
      Markus94287 earned a badge
      One Year In
  • Popular Contributors

    1. 1
      +primortal
      486
    2. 2
      +Edouard
      172
    3. 3
      PsYcHoKiLLa
      138
    4. 4
      ATLien_0
      94
    5. 5
      Steven P.
      79
  • Tell a friend

    Love Neowin? Tell a friend!