--
You received this message because you are subscribed to the Google Groups "Java Posse" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javaposse+...@googlegroups.com.
To post to this group, send email to java...@googlegroups.com.
Visit this group at http://groups.google.com/group/javaposse?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Though it pains me... I have to agree with you Cedric ;-)
If what we write first is "the simplist thing that might work", then I'd suggest comments should explain code that is not apparently the "the simplist thing that might work". or "comments should explain why the simplistic thing that might have worked, didn't"
It should *always* be the simplest thing that could possibly work, my experience is that the bit in doubt is often the definition of "work" in question, especially if that definition has evolved over time.
For example, "working" could include the need to handle malformed data, or backwards compatibility, or not fixing and old bug that downstream users came to rely on, or working around a bug in some underlying component, or some strict performance requirements. In which cases the simplest thing might not be so simple.
So when there's room for doubt, document exactly what working means - WHY a piece of code is there, HOW it's expected to be used.
If you can't cleanly express a usage pattern through types and a DSL, then Javadocs and test fixtures are very often my favourite way to do this :)
Of course, let's be reasonable here: While in theory any and all comments are code smells, they are pretty much always the lesser evil. Anything beyond the most academic of projects is going to have some chunk of code which does something in a somewhat weird way for a good but not immediately obvious reason, and the right choice is definitely to add a comment to explain what's happening.
It seems that a big thing that should always be discussed as part of this topic is what the nature of the comments is. Javadoc was brought up and I dare say that kind of information is absolutely necessary and is not on par with inline comments that one only sees when looking at the source code. API comments are directed almost squarely at the consumer of said API and themselves can be broken up into 2 categories:
- necessary information otherwise not captured by the programming language (so many of API comments I see in Python these days start by saying something about input and output types and so many comments in general talk about possible exceptions otherwise not seen by explicit checked exception declarations)
- some helpful information about general intent and intended use of the API -- could be considered technically superfluous, but sometimes oh so necessary to the human trapped inside of us struggling to get out :)
Personally, I think there's a time and place for both. It's not possible to capture every good piece of information that's necessary at the time of authorship of the code or in some perceivable future in strict language artifacts alone. I see and write plenty of code completely devoid of comments. That sort of thing is usually obvious in its intent in the context of the project. But not everything is obvious and therefore there's no shame in giving future self or your colleagues or co-conspirators a helping hand.
On Sunday, April 14, 2013 2:44:58 PM UTC-4, Reinier Zwitserloot wrote:
Particularily bad is the documentation of the domain model objects and methods. Quite often in my experience, the domain model is anemic and only acts as a dumb record holder with simple getter and setter methods.
While it seems to be obvious at first glance, what the method named getName() does, it is much less obvious what the name field means for the business. Is it merely a human readable label for the object? Is it used to identify the object in some subsystem? What is the format of the name (i.e. does it allow spaces numbers or punctuation) etc?
And that is just questions I get when I see the propert called "name" in the model. What if the property is called "total" or "susg".
I'd have to disagree. For constraints you're much better doing it in the type system, where the compiler can check things for you.
e.g. Provide an argument of type ValidatedId instead of a String with a bunch of annotations.
I'm also curious to see if the new 'Optional' type gets much adoption vs @NotNull and friends, despite its limitations.
--
You received this message because you are subscribed to the Google Groups "Java Posse" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javaposse+unsubscribe@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to javaposse+...@googlegroups.com.
Roland,We have a similar problem in the bioinformatics world, where a field like "id" could mean an ID from a specific database, an accession (an alphanumeric ID similar to a database ID). One way around this is to use semantic annotations for fields. Here's an example. http://aspenbio.wordpress.com/2011/01/20/biogroovy-and-the-semantic-web/Cheers,Mark
We use longs for ids and strings for accessions or gene symbols. The id's are usually used for joins and the accessions are used by users when doing searches.
Mark
--
--
You received this message because you are subscribed to the Google Groups "Java Posse" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javaposse+unsubscribe@googlegroups.com.
If what we write first is "the simplist thing that might work", then I'd suggest comments should explain code that is not apparently the "the simplist thing that might work". or "comments should explain why the simplistic thing that might have worked, didn't"
Ah, but tests are testable (the code tests the tests and the tests test the code; if your tests have a bug in it, they will fail, you will figure out it's not your code, and thus, your test). Put differently, if your test becomes 'out of date', you will notice. If a comment becomes 'out of date', it'll remain there and just confuse the heck out of any future readers.
You're basically advocating comments that are like '// add 1 to a'. Which I think we can all agree is not, in fact, a good idea.