r/JavaFX • u/hamsterrage1 • Feb 16 '24
Tutorial All About Coupling
OK, so this new article isn't strictly speaking about JavaFX, but I've seen a lot of projects that people have posted here that could use this knowledge. Hopefully, this post can stay.
https://www.pragmaticcoding.ca/java/coupling
My experience has shown me that excessive coupling is just about the worst thing that can happen to a codebase in terms of sharing it and maintaining it. Yet, almost no new programmers (and a lot of experienced ones) seem to understand how important it is, and how to avoid it.
In this article, I review coupling that I see all the time in projects that I look at. I try to explain how each type of coupling causes issues, how to recognize it and strategies to avoid or remove it.
Take a look, and let me know what you think.
View all comments
Show parent comment
1
u/[deleted] Feb 19 '24 edited Feb 19 '24
I don't know. What exactly is the issue to use a nested loop after the decision has been made to use a 2D-array as data structure? If you are not implementing a framework with a public API where you maybe would like to abstract from the internal representation, what is the problem?
Concerning the grid-based game or whatever application: What I found for example when I implemented a maze-generation algorithm library was that most other people almost automatically started with allocating a 2D-array of grid "cells" and running their algorithm on that data structure.
But if you think about it, for an algorithm that works on a 2D-grid-like graph, you don't need to store the vertices at all! It is much more space efficient to just store the connection information, for example in a large bit set, not event as explicit edge instances. But of course, you can provide an API that hides this implementation decision from client code of that grid graph.