Keep it simple!
Posted in Performance, Tips | No comments
Do you really need to have a database table with all existing countries? What’s the benefit? Apart from adding one more database query to each page hit and an array to each users context while loading that form…
Think it over, every software component’s goal must be, first of all, to satisfy the users needs as fast and as reliably as possible. Considering the “fast” part, you must always evaluate if it’s really necessary to store this kind of info in a database table, and penalize the applications overall performance by adding another database query, recordset run through and a whole bunch of new objects in an array in request or session context.
So, maybe the next time you need a static list of elements, just type it your web page, and if you do not want to “repeat” this list in every page you need it, just make a nice custom tag, or a <c:import /> and keep the list in a single JSP.
And just in case you are thinking: “well, but having this info in a database table makes it so easier to update”, evaluate for each case, how often will you change it, and whats the difference in effort between adding or removing one line in a JSP or executing a script in your database production environment. The latter may seem more elegant, but if you look closely you’ll see that it actually makes your application a whole more complex (typically adding a new domain object, a new data access component, a new entry point in your business logic and an additional call in your front-end); and in my book at least, elegance in software is synonym of simplicity and overall maintainability (for all involved: users, sys admins, DBAs and developers).
Tags: database, java, jsp, Performance, simple








