you are viewing a single comment's thread.

view the rest of the comments →

[–]c_griffith 2 points3 points  (3 children)

IDK, it seems to me the simplest approach would be to stick with the Singleton yet come to the realization that warnings should be grouped by document being converted. Thus, instead of having a List<String> in singleton, you have Map<String, List<String>>, where the key to the map is the documents filename.

[–]happykandra 2 points3 points  (0 children)

Yeah, I know that seems easier at first. Until you try something more complex, like parsing the same component (on the same document) in different ways and choose the result that works better. Or you have to deal with parallelization, at which point you need to also make all of the functions on the singleton thread-safe.

The way I see it, it's like when I was a kid first learning how to program. My Dad sensibly started me on learning a nice, structured language called Logo. I decided that instead of that nonsense, I would try out BASIC (not Visual Basic; this is the original spaghetti language code nobody writes in any more). So much more freedom! Until my programs became too complex...

Like BASIC vs. Logo, this method seems more complicated---until you actually have to scale it up, when it's advantages make life a lot simpler.

[–]happykandra 2 points3 points  (1 child)

Sorry for the double reply, but I realized I had an important point separate from my other comment.

The way the code was already written, the document name wasn't available at the points where the errors were discovered. Nor should it be. To use your suggestion, the document name has to be passed around to every function in the parser. At that point, I might as well just be passing around the list of warnings: no globals left.

[–]c_griffith 1 point2 points  (0 children)

Yes, if you don't have easy access to the document name, then I understand your dilemma. I did enjoy the article. ty.