News for hackers. Stuff that matters.
Re:We fired our top talent. Best decision we ever made by mattbgates on Saturday October 14, 2017 @08:25PM (#15475117)
I think I have to agree with you. The fact that Rick was allowed to be turned from a Dr. Jekyll to a Mr. Hyde is kind of the company's fault. No one stepped in to hold Rick accountable during meetings?

While I no longer work there, my first job with some programming had me training to understand the code, what it was about, and even how to write it.

To this day, I still use this method so I don't get lost or bored in my code.

These are the lines I actually use along with commenting my own code just in case I have to return back to it weeks or months or even years later, I don't have to try and trace every step back to a particular code.

  // AUTHOR: MG
  // FILENAME: functions.php 
  // STATUS: ACTIVE
  // PURPOSE: All of the functions for this application (app name)
  // NOTES: There are several unused functions in this file that are commented out but once in production
  // They can be deleted as we likely will not be needing them at all.
Those 5 lines have saved me a lot of time. While I don't include the "author" line since it just me writing the code, if there are tons of hands in there, you should know EVERY SINGLE author as well as when code gets commented, it should contain the initials upfront, such as // mg: this does this and this does that. If I know multiple files touch.. I also add: "ASSOCIATIONS:" and list all files that call this one.

Using this method, I've been able to complete a bunch of projects much quicker because any time I start to forget: what am I doing? what does this code do? am I on the right track? I can look right at the beginning of a file and know the answer.

I'm not saying that a boss or supervisor has to be a micromanager, but meetings are necessary to understand where everyone is at. Leaving a programmer to do his own thing means that he really is doing his own thing and is more likely to get lost in the code. I'd say more like he wasn't a genius but thought he could do it alone.. and sometimes, it is nice to have someone step in and tell you: "Hey where we at? What can we do to speed this up?" or even provide their own insight... I can't tell you how many times I've talked with my spouse about an issue.. and she's suggested, "Why don't you just do this?" and it has saved me hours of time just because of someone not in the code is able to see another solution.

Re:We fired our top talent. Best decision we ever made by Avalaxy on Saturday October 14, 2017 @08:31PM (#15475129)
> AUTHOR: MG

This is already in your commit history, so why hardcode it into the source?

> FILENAME: functions.php

This is obvious because you just opened the file. So again, why even put it there? When the file gets renamed the documentation is no longer correct? These things are also hard to refactor.

> STATUS: ACTIVE

Every part of the code is always active...

> PURPOSE: All of the functions for this application (app name)

Okay, probably the most useful one here. But what if we're refactoring the code and the purpose changes? Or if someone adds a few functions and the documentation no longer covers the purpose?

> NOTES: There are several unused functions in this file that are commented out but once in production They can be deleted as we likely will not be needing them at all.

Very dangerous, again because the source might change while the documentation doesn't. But why even write "they can be deleted"? Why not just delete them? That's what version control is for.

Re:We fired our top talent. Best decision we ever made by nowbacktowork on Saturday October 14, 2017 @08:38PM (#15475158)
I'm not sure why you're being down voted, but this is a very reasonable counter point.

The purpose or brief should be at the top of every file, it should also evolve as class or implementation does. Arguable that it's really the only one that matters and can also come from no other tool or location.

Re:We fired our top talent. Best decision we ever made by account193 on Sunday October 15, 2017 @02:22AM (#15476139)
I will have to admit that this GIT/SVN is a very elegant solution in the ideal world, but in my experience real world code gets very very messy. Teams get lazy and don't always give very detailed commenting in version control.

Startups may be better at this, but the corporate world is even messier with quick turned spaghetti code. Any markup in the codebase itself helps the next developer tremendously.

Personally, I find @mattbgates best practice to be very justifiable in practical use.

Re:We fired our top talent. Best decision we ever made by mattbgates on Saturday October 14, 2017 @08:43PM (#15475172)
Avalaxy, while I know companies use tools to do their thing... I don't, I'm old school. I have files on an FTP server and I write PHP code.

But to explain:

> Author: completely optional, depends on what you are using, you aren't wrong.. since I'm old fashioned, if I were to hire some coder to help me maintain my programs, I'd like to know that he was in there, and I'd have no way of knowing.. again, probably not anyone's issue, but I'm old fashion.

> Status: Not all files are in use, but sometimes they are just leftover and may not be deleted, or sometimes, they might be used for testing purposes -- so Status can be changed to INACTIVE, TESTING PURPOSES ONLY, etc. Maybe the file is inactive because newer code was written, but this was kept as an archive? You never know.

> Purpose: always state the purpose of the code.. if it changes, than this should probably change. If it doesn't, than again: you must be doing your own thing.

> Notes: optional, this is just notes that might be necessary..... again.. Notes to myself: I have some code in there that is not currently being used and if I go into production, I probably won't need it so may as well delete it.

The Notes weren't supposed to be taken as a literal. This is just notes to anyone who reads the file.

Sure, there is a such thing as too much commenting, but no one wants to go through the code to figure out what it does. Leaving a little comment up top of every page, regardless of the simplicity or complications of the function, it is just nice to leave for anyone who has to go in there. It's a better form of organization. Imagine having to go in there 3 years later... would you remember what it does? The little statement up top might help you remember more quickly.

Re:We fired our top talent. Best decision we ever made by gregmac on Saturday October 14, 2017 @09:05PM (#15475270)
> Avalaxy, while I know companies use tools to do their thing... I don't, I'm old school.

You would do well to learn source control system (which these days basically means git).

Leaving aside the team/collaboration part, once you learn it, it's so incredibly freeing. I cannot understate this enough.

You can make changes to the code, and then go back with one operation (discard changes). You can work on an experimental idea (in a branch) for a few days/hours, then switch back to your main code to fix an important bug, go back and finish your experimental branch eventually, and merge everything together -- often with nearly zero effort. If you're supporting multiple release versions at once, you can fix a bug in one and often easily apply it to all other versions.

Ever have a situation where something just stops working, but you're not sure when other than in worked four months ago? You can arbitrarily check out any old version and test, and even - in a single operation - undo that change from the current version of code.

Can you do all this without source control (or with copies named by date)? Sure, but it's kind of like the difference between fetching water from a well using a hand pump and bucket vs having running water and being able to open a tap. Before you have running water, it's just life, and it's not that big a deal to fetch water, really. Once you have it, you could never imagine having to live life that way.

Re:We fired our top talent. Best decision we ever made by mattbgates on Saturday October 14, 2017 @09:14PM (#15475305)
I do know what "source control" is but even when I wasn't working for myself, my boss made me still add this stuff, despite knowing at the end, upon saving, it would ask what changes were made.

We used something called "Source Safe" from Microsoft.

As for what's in the Notes and deleting it upon live production... that is the old stuff... in case the new stuff stopped working for whatever reason.

I guess we all have our own methods of doing things. Fortunately, I've not had major issues, though everything is backed up to it a server upon my completion of work for the day.

Re:We fired our top talent. Best decision we ever made by megaman22 on Saturday October 14, 2017 @10:20PM (#15475517)
Man, you're banging rocks together and working hard, rather than smart. My sympathies for being stuck with a crapfest like sourcesafe.
Re:We fired our top talent. Best decision we ever made by skinnymuch on Sunday October 15, 2017 @12:07AM (#15475843)
Your status reasoning seems weak. Archive? Version control will have it in history. Maybe rarely you want it around for active references. Otherwise you likely don't need it.

The author bit is solved with version control. Much better than a line that can get bogged down with multiple authors or be outdated.

It doesn't feel like you're being old fashioned or old school. It seems like you're being a bit stubborn in your ways. Version control is a good thing. Perhaps there's better ways. Going your way with not having an sort of real alternative isn't right though.

Your other reasons like coming back years later can be applied to version control too. It's helpful to have commits that have diffs, time stamps, author, and other meta data. Imagine having to come back 3 years later without any of that. Commit history might help you remember and manage your project more quickly, efficiently, and effectively.

Re:We fired our top talent. Best decision we ever made by sverhagen on Saturday October 14, 2017 @08:52PM (#15475215)
"Old school"? I think it's in most cases irresponsible not to use version control. Sorry to say, but it's "amateur hour". No better than "Rick".

I agree with one of the parents that "Purpose" is probably the most useful, but even there: at that level the code should be largely self-documenting.

Re:We fired our top talent. Best decision we ever made by mattbgates on Saturday October 14, 2017 @09:05PM (#15475272)
I never said I didn't have version control.

To assume "at the code level it should be largely self-documenting" is to be a Rick. Comments are there to help everyone, including non-programmers understand what is going on.

Re:We fired our top talent. Best decision we ever made by valuearb on Saturday October 14, 2017 @11:39PM (#15475759)
I have been coding for almost 40 years and always been big on documenting code, but the problem is that code changes and documentation doesn’t always keep up.

Given modern tools I’ve come to the conclusion that documenting overall purpose and specific edge cases is more than enough. For example, the file header should describe its purpose, and anything in the actual code that’s not obvious should be commented. No more boilerplate function or file comment header. Git tells me who wrote each line of code, I know the name of the funcs and files, and I can see the inputs/outputs for every func with my own two eyes.

Re:We fired our top talent. Best decision we ever made by sgift on Monday October 16, 2017 @10:38AM (#15483467)
> I have been coding for almost 40 years and always been big on documenting code, but the problem is that code changes and documentation doesn’t always keep up.

This has always been a sign for me to tread very, very carefully. People who change code without changing the comments probably didn't read the comments, didn't read the code or didn't understand it - either way, if comment and code disagree both are probably wrong.

Re:We fired our top talent. Best decision we ever made by valuearb on Monday October 16, 2017 @04:29PM (#15486407)
I agree mismatched comments/code is a huge warning sign. But I think requiring standardized comments is a problem.

When I started out every function had to have a header comment, with name, inputs/outputs, description of purpose/etc. It was significant extra work to keep that up to date. I could update a function three times in a day, and have to rewrite the comments three times to check it in.

And in the end, I know the name of the function. I can see the inputs and outputs. The only part of those comments that were occasionally useful were purpose, details of which often changed with edits. And in reality, as long as the function isn't hundreds of lines long (another problem), I can read it and discern exactly what it's trying to do.

Comments that were most useful said stuff like "this looks weird or dumb, but we had to do it this way because of this thing we and you probably didn't expect in the data/system/etc"

Re:We fired our top talent. Best decision we ever made by debaserab2 on Saturday October 14, 2017 @09:43PM (#15475417)
> To assume "at the code level it should be largely self-documenting" is to be a Rick

You don't have to be a Rick to write clean, concise code.

I'd strongly recommend reading up:

http://www.codeodor.com/index.cfm/2008/6/18/Common-Excuses-U...

https://blog.codinghorror.com/coding-without-comments/

Re:We fired our top talent. Best decision we ever made by sverhagen on Saturday October 14, 2017 @09:14PM (#15475307)
What am I to make from: "while I know companies use tools to do their thing... I don't", if not that you're not using a version control tool?

It's not "genius behavior", but well accepted from people like Uncle Bob, that documentation should be in the names of small and focused functions, methods or classes, not in comments.

Re:We fired our top talent. Best decision we ever made by skinnymuch on Sunday October 15, 2017 @12:00AM (#15475820)
You said initially companies have their tools and you don't. Later you went on about simply using ftp and coding php. It sure seems like you don't use version control. At least not at a level that it should be used at in this day and age.
Re:We fired our top talent. Best decision we ever made by pc86 on Wednesday October 18, 2017 @01:12PM (#15500893)
For what logical purpose would a non-programmer be reading your source code and only be able to accomplish whatever their task is if you adequately comment it?
Re:We fired our top talent. Best decision we ever made by md224 on Saturday October 14, 2017 @09:18PM (#15475317)
I'm an old school surgeon... I like to operate without using anesthetics or sterilizing my tools.
Re:We fired our top talent. Best decision we ever made by steego on Saturday October 14, 2017 @09:34PM (#15475375)
Much like the old school surgeon, he hops on the production server and types very quickly to minimize website downtime.

"Time Me, Gentlemen!"

https://www.theatlantic.com/health/archive/2012/10/time-me-g...

Re:We fired our top talent. Best decision we ever made by no29 on Saturday October 14, 2017 @08:50PM (#15475206)
rcs has been around ~40 years. you're not old school. you're sloppy.
Re:We fired our top talent. Best decision we ever made by mattbgates on Saturday October 14, 2017 @08:54PM (#15475227)
Well, I'm glad you don't have to go into my code to see that sloppy tabbed mess full of comments and code :)
Re:We fired our top talent. Best decision we ever made by steego on Saturday October 14, 2017 @09:19PM (#15475323)
You need to seriously stop wasting time talking about this on HN and learn you some basic git.

https://try.github.io/

It's not hard. It's not like you're computer illiterate and don't know how to program.

Re:We fired our top talent. Best decision we ever made by imron on Saturday October 14, 2017 @10:42PM (#15475595)
> I have files on an FTP server and I write PHP code.

None of that prevents you from using source control.

Re:We fired our top talent. Best decision we ever made by GuB-42 on Saturday October 14, 2017 @09:02PM (#15475258)
Why don't you use source control instead. Don't say who you are in the comments, that's what "blame" is for. Don't comment code, delete it, it won't be lost since you have a history. Make a branch for your experiments if you have to. The state of your work should be apparent in the bugtracker.

Code comments are code comments. If you use comments to help with your development process, there is probably some work to do with your toolchain. Good source control and a bugtracker are a must.

Re:We fired our top talent. Best decision we ever made by scintill76 on Monday October 16, 2017 @04:21PM (#15486348)
Reminds me of this style:

  /**
   * Calculate the thing.
   *
   * @param $foo the foo value
   * @param $bar the bar value
   * @return the thing
   */
  function calculateThing($foo, $bar) {
      return $foo + $bar; // add foo and bar
  }
Such comments are worthless noise that obscures the important parts of the code and camouflages any actual useful comments that might be there. I would so much rather have better names than "thing", "foo", and "bar", and maybe a comment about why the values are summed, if it's not obvious. When you do those right, you won't even need many comments. Maybe a docblock, but don't bother with that if it's nothing more than a robotic "English version" of what is already obvious from the function definition. IMO most good developers will perceive your file header as a redundant annoyance for similar reasons, as other commentors have explained.
Re:We fired our top talent. Best decision we ever made by pc86 on Wednesday October 18, 2017 @01:36PM (#15501139)
It's the "CS 050 Computer Science for Humanities Majors" type of commenting (I was a humanities major, no offense intended). A bunch of comments that are only there because you think you have to have comments, or because you're graded on whether or not comments exist.