Win a copy of Spring in Action (5th edition) this week in the Spring forum!

Junilu Lacar

Sheriff
+ Follow
since Feb 26, 2001
Junilu likes ...
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
Forum Moderator
Columbus OH
Cows and Likes
Cows
Total received
210
In last 30 days
5
Total given
85
Likes
Total received
1823
Received in last 30 days
47
Total given
329
Given in last 30 days
7
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Junilu Lacar

Daniel Demesmaecker wrote:bare (at least I wrote bare and not bear ) with me


Actually, the correct word is "bear" as in, "Please bear with me."  See meaning 3 (v. intr) in this dictionary entry: http://www.thefreedictionary.com/bear

1 day ago

Daniel Demesmaecker wrote:Does who can't, teach


It's "Those who can't, teach" and I don't necessarily agree with that old saying either. Most of what I do these days is teach and I certainly think I'm still a capable programmer. I'm always careful about following context-free rules. For me, it's best to understand the context in which a rule applies so that I understand why the rule came about in the first place. See The Pot Roast Story
1 day ago
Seems to me that Kotlin is fast becoming, if not already, the preferred language for Android development. It certainly has some nice language features. I'm actively learning it myself currently.

There are many popular Android apps out there that are written in Kotlin: https://developer.android.com/kotlin/
1 day ago
My main considerations for design, in order of highest importance (1=most important):
1. Simplicity (meets the current requirements with least complexity)
2. Easy to understand
3. Easy to extend (loose coupling, cohesive, etc.)
4. Secure
5. Performant (see Three Rules of Optimization)
1 day ago
Daniel, whoever told you that wildcard imports cause performance slowdowns didn't know what they were talking about. Wildcard imports have absolutely nothing to do with performance. Imports are a compile-time thing, to help the compiler resolve type references.

See the SO article I cited.
1 day ago
@OP, you can't just do this:
You have to do this:
The .* causes all classes in the e2.support package to be imported.

I think the old "Don't use wildcard imports" rule should be understood in context. I never saw any problem with wildcard imports since I don't often run into the issues they can cause. On the rare occasions that I do, my IDE will typically help me figure out where the name collisions occur. In fact, if you have this kind of code:

The Java compiler itself will tell you what classes are conflicting:

Foo.java:6: error: reference to List is ambiguous
       List bar;
       ^
 both class java.awt.List in java.awt and interface java.util.List in java.util match
1 error


See this discussion on SO for a comprehensive weighing of the pros and cons of using wildcard imports: https://stackoverflow.com/questions/147454/why-is-using-a-wild-card-with-a-java-import-statement-bad
1 day ago
Why would you name an object "EmployeeList" if it only represents one employee?

There are several ways to go about this but here are the main problems you have:

1. Figuring out which columns are included in the query and the order they will be in
2. Mapping the query columns to the appropriate setter() method on the object

For #1, you'll need metadata or you'll need to parse the text between "SELECT" and "FROM" of the query

For #2, for maximum flexibility, you'll have to use the Reflection API. Another option, although more tedious, would be to specify a "mapper" object for each query. That means you would potentially have to define as many mapper objects as you have queries. A mapper object will essentially have for its main logic whatever code you have in your while (rs.next()) loop.
2 days ago

Daniel Demesmaecker wrote:@mod it really wasn't ment to be foul language, but more a figure of speach, but I will pay more attention in future


I know, which is why I just redacted that one word and not your entire post. Thank you for your cooperation.
3 days ago
Back at my keyboard now so I'll give you some concrete examples by what I mean when I say it's a matter of perspective.

This code is not very OO and is very puppeteer-ish:

With this code, the fact that patients are kept in a list is exposed for all to see. Then, you pass this list to a Patient and tell it to print out all the patients who have been admitted to the hospital. Even in real-world terms, that sounds kind of silly. Imagine being admitted into a hospital and someone coming to you with a list of all patients who have been admitted and telling you to read that entire list out. That's just not something you'd ask a patient to do, either in the virtual software world or in the real world.

This would be more OO and more director-ish:

Here, you have no idea what the underlying data structure is. All you know is that the Hospital object can somehow track the patients that get admitted to it via the admit(Patient) method. You also know that it can somehow print the list of patients who are currently admitted at that particular hospital. This code simply tells the Hospital object about other objects (Patient objects) and then tells the Hospital to do something related to all those patients it was informed about. How that information is managed is not anybody else's concern except the Hospital's.
4 days ago
It's a very common pattern that can be seen often: many programmers seem to have a tendency to let their imaginations run wild and create all kinds of complications for their programs and themselves.

The trick is to start with the simplest possible derivative of the problem. Want to print a Christmas tree made of "*" characters?

Instead of thinking of questions like "What if I want to print different sizes? What if I wanted to print different heights or widths? What if I wanted to put a star on top? What if I wanted to put presents under it?" You should train yourself to take the opposite tack and ask "How do I print a single *? Then how do I print 2 *s? Then how do I print 3 *s? And so on..."

In this case, if you had a 2-digit number, how would you separate the 1s digit from the 10s digit and get their sum? Then for 3-digit number, how to separate the 1s digit from the 10s fro. The 100s digit and getting their sum. And so on until you can generalize the problem to any N-digit number.
4 days ago

Dave Bloomberg wrote:Firstly I am trying to understand how to give a patient a specific list of Doctors, whenever I will have figured that out I will be able to figure out how to add and delete Doctors from appointments. All my issues are tied together with Appointments and ID[].


Why would you need to give a Patient object a list of Doctors? Conceptually, what exactly are you trying to do that requires a Patient object to go through a list of Doctors? The idea alone is making my spidey senses tingle like crazy.

As far as adding/deleting doctors from appointments, it's better to think from a more conceptual perspective. "Add/delete doctors" is a little too implementation-oriented. I would prefer to use more conceptual-oriented language like "assign a doctor" or "associate a doctor with an appointment" and "unassign" or "cancel". This moves your thinking away from implementation and closer to intent.

I'm on my phone so it's hard to type out a code example. Will do that later when I can reply from my laptop.
4 days ago

Daniel Demesmaecker wrote:I usualy take the firstletter of the classname, which coinsidentally in this case is i


Code should express intent, not implementation. In your case, your criteria for choosing a name, i, is essentially arbitrary.

Choose names that help express intent or purpose. Norm's suggestion is better than i, in my opinion.
5 days ago
Some useful design principles to refer to when considering assignment of roles and responsibilities and where best to encapsulate information/data:

GRASP - General Responsibility Assignment Software Patterns/Principles

Tell, Don't Ask

Law of Demeter

Code smell: Inappropriate intimacy
5 days ago