9 ms·
This is why comments that specify what the code does are a "code smell". Comments should explain things that are not obvious from the code. Comments should be
by pjc50 10y ago
This is why comments that specify what the code does are a "code smell".
Comments should explain things that are not obvious from the code. Comments should be things like
// Note: PCI-DSS requirements apply below
// Must check status register and FIFO to determine completion due to flaky hardware
// Algorithm below is modified Knuth-Morris-Pratt
// This is O(scary), but seems quick enough in practice.
(Now, if someone lets me put images in comments, that would be amazing. Good for state transition diagrams and random scribbles)
- e12e 10y agoA state transfer diagram would probably be more useful as a view on the code (similar to how the Smalltalk browser is a simple graphical representation/layout of code. Or indeed any IDE with advanced code folding (show me the class name and public methods only). But there's ways to mix the two: Python doctests is one. The lp approach is to "escape" the code, not the comments. I really do think some richer data structure than flat text files is needed - simple multi-/hyper-text seems like a minimum. Not only links (most ides have this: hoover to display help, click to goto definition etc). Why so few seem to successfully add vector graphics and diagrams I don't know. I guess jupyter / ipython might be a rare breath of air. But who really wants to maintain 10k locs of code and 15k locs of tests in ipython notebooks? We need something more (lively kernel might be more interesting here - webdav for persistence Web browser for run/edit/view - I'm not sure if the required power Canberra realised any simpler).
- p10_user 10y agoI personally only see the utility of the notebook as a demonstration tool of a finished product. Kinda goes to your comment on the notebooks and code maintenance. It's a good teaching or presentation tool but not (IMO) a development tool.
- e12e 10y agoThe main question is if there's any fundamental reason for why we can't have both: a rich, versioned, distributed data store for our logic and data - and a number of views that allow us to inspect and modify it. The best example I'm aware of is probably Smalltalk coupled with monticello version control and a solid object database like gemstone/s (I'm not aware of a real open/free workalike for the last part). That's not not say relational or logic databases aren't useful - but it's more difficult to manage the data, query code and program code in one integrated system if the database takes the form of an external server. That said, Ms visual studio and the SQL db gui does a pretty good job of presenting a somewhat coherent environment. I used to be strongly in the Linux/Unix camp - thinking that the datastore we call the filsystem is a good abstraction. But I've come to believe that even the strong legacy of user familiarity isn't a good enough reason to stick with it. Even if we were a little bit more serious and at least went all plan9 - rather than the half-hearted state of Linux/Unix (everything is a file, or a database file, or a binary file or an archive of a filsystem or...). That said a "filsystem" might very well still be a decent building block for a higher level system (with decent search, for example). But yeah, I don't think jupyter is the be all, end all of development. But it is an interesting way to move legacy programming environments forward in a low friction manner.
- Samis2001 10y agoFor the OODB, perhaps Squeak's Magma? http://wiki.squeak.org/squeak/2665 http://wiki.squeak.org/squeak/2665
- astrobe_ 10y agoMost coding editors (even the "deprecated since the 70ies" Vim) shall let you follow links you put in comments. For someone who likes to have as much code as possible on a single screen, this is the best option.
- noobiemcfoob 10y ago+1 for images. It's been my main reason for looking into tools like doxygen
- brianwawok 10y agoYou didn't solve the OPs problem, you just moved it around. In his case, his algo said X, and his code did Y.. very easy to see the mistake. In your case, lets add a comment // Note: PCI-DSS requirements apply below Now 3 years later, the law changes and the requirements do not apply. So you are at the same situation. Code does X, comments say Y. Which is right? Not a very easy to keep comments and code in sync
- tunesmith 10y agoThat's sort of a different problem. I often think of comments as "why" and code as "how" (or "what" if you're declarative). If how breaks, then the code breaks, so you have immediate feedback. But if why breaks - like if your reasons for writing it that way no longer apply - then it's impossible to recognize immediately. If there were instead a way to codify the assumptions behind why, such that the why statements would break when the assumptions become false, that would be interesting. But at any rate, why is relevant, and code doesn't express the why.
- tomtheelder 10y agoI'm fairly sure he was attempting to agree with the OPs problem.
- PJDK 10y agoMy approach to this is that the comment can almost always be turned into a text. A test class called FooPCIDSSCompatibility with tests for all the bits both defines things more strongly and will start failing if you ever break it (either accidentally or because it is no longer required). Either way you need to update either code or test to get through the build process. Comments can be useful for annotating algorithms or referencing stack overflow though.
- PJDK 10y agoMy approach to this is that the comment can almost always be turned into a text. A test class called FooPCIDSSCompatibility with tests for all the bits both defines things more strongly and will start failing if you ever break it (either accidentally or because it is no longer required). Either way you need to update either code or test to get through the build process. Comments can be useful for annotating algorithms or referencing stack overflow though.
- FrancoDiaz 10y agoAgreed, so then most programming systems are wrong if things are not obvious?
- praxulus 10y agoWell, it's just a code smell. Smelly code isn't necessarily wrong, it's just more likely to be wrong. Sometimes a piece of code needs to be highly optimized to the point of being basically unreadable, at that point it's probably worth adding explanatory comments that you would normally avoid.
- quantumhobbit 10y agoI think the literate in literate programming is too formal. Maybe it should have been conversational programming. The comments should be the things that you would tell a new team member during a pair programming session. You assume she knows what the syntax of the language is, but you don't assume she knows the business intent behind the code or the history of trial and error that led to its current state.
- spaceknarf 10y ago> Now, if someone lets me put images in comments, that would be amazing. Good for state transition diagrams and random scribbles That's exactly what JetBrains MPS (https://www.jetbrains.com/mps/ https://www.jetbrains.com/mps/) does. Even better: the state transition diagram is the code. Some of my colleagues are playing with it - not sure if it's used in production yet.