Skip to main content
92 votes
Accepted

Using commented dashes to divide up code chunks

What you're doing here isn't commenting the code, it's writing documentation with some code snippets in it. If this was part of a tutorial course to help me understand some new tech stack step by step,...
Flater's user avatar
  • 52.5k
32 votes

Using commented dashes to divide up code chunks

There is a proper place for commenting this heavily: when you're writing code that nobody will ever be an expert on and is in an unfamiliar language, or otherwise can't be understood within a ...
John Dallman's user avatar
28 votes

Are "factory methods" anti-pattern now?

But isn't that all a DI concern? No, it isn't. Raw DI simply means that an object receives its dependency as parameter, as opposed to constructing it internally. You inject dependency. It is true ...
freakish's user avatar
  • 1,404
28 votes

Using commented dashes to divide up code chunks

There were several answers speaking to commenting in general. However, you question specifically asks about the dashes pattern. Dashes are loud. They interrupt any flow you might have had while ...
Cort Ammon's user avatar
  • 11.6k
11 votes

Using commented dashes to divide up code chunks

Step 0 - intro Comments in code are (generally) a code smell (=small red flag). If you need comments to explain you did something wrong, code needs to read like a story. The same goes for needing ...
Martijn's user avatar
  • 697
9 votes

Using commented dashes to divide up code chunks

So, first, I'd agree with others that your example is totally over the top... comments that just re-state what's already obvious (e.g. that class MyClass creates a class called MyClass), and you have ...
Simon Geard's user avatar
6 votes

Are "factory methods" anti-pattern now?

Whether something is considered an anti-pattern often comes down to how a particular design is used. Dependency injection frameworks can provide factories. They are a factory in their own right. DI ...
Greg Burghardt's user avatar
5 votes

Using commented dashes to divide up code chunks

Specific to using lines of dashes to offset sections: this is not inherently bad, if used appropriately, and actually it used to be quite common...but modern programming tools and styles mean there ...
user3067860's user avatar
5 votes

throwing an exception or returning Optional

There are two primary use cases for exceptions, which partially overlap: You detect a problem that is unrelated to why this function might be called. It is unlikely that the calling code knows any ...
Bart van Ingen Schenau's user avatar
4 votes

Is setting a flag in a loop a code smell?

Python has a special for ... else syntax just for that control flow pattern. So I'd say doing it like this in a language that doesn't have special support is probably as good as it gets.
Kilian Foth's user avatar
3 votes

Using commented dashes to divide up code chunks

Others have given lots of good advice. Here's a few more points, which I hope may prove helpful on your journey. Learn to use language features. It seems to me that you have the abstraction of an ...
Simon Crase's user avatar
3 votes
Accepted

Where to put getOrSave responsibility?

Putting this logic in a different class does not reduce the clutter. The clutter is simply moved to another part of your architecture. The truth is, I don't think there is a perfect place to put this ...
Greg Burghardt's user avatar
3 votes

Is setting a flag in a loop a code smell?

I don't think it's a code smell. It's just that your intentions would be clearer with the stream API. It's more readable like this because it says what you do, you just have to read the code: myList ...
Mathieu's user avatar
  • 1,039
3 votes

Using commented dashes to divide up code chunks

Should you do this in a professional context? No. But it's interesting to think about why you think this is more appealing. I suspect the reason you are doing this is because you are new to coding and ...
jmathew's user avatar
  • 262
2 votes

Using commented dashes to divide up code chunks

In almost all cases, using long lines of dashes to break up code is not helpful. Most IDEs have features that help you collapse code when you need to, a simple double line break would have achieved ...
Chris Schaller's user avatar
2 votes

throwing an exception or returning Optional

IMHO, throwing an exception always exactly means "I could not fulfill my contract". As an API developer, your steps should be: Design the contract (with usefulness for your callers in mind)....
Ralf Kleberhoff's user avatar
2 votes

End2End/integration Testing in Java with Selenium - how to get a good test structure - looking for experiences

I have been organizing and implementing end-to-end test frameworks for more than 10 years. I have to say, I am frustrated by the lack of design patterns and architectural guidelines for this kind of ...
Greg Burghardt's user avatar
1 vote

Should Value Objects be used inside the DTO?

If you are able to use your value objects with thier built in validation on the client side of the DTO it begs the question of why you have a DTO at all. The purpose of a DTO in this case would be to ...
Ewan's user avatar
  • 77k

Only top scored, non community-wiki answers of a minimum length are eligible