Junilu Lacar

+ Follow
since Feb 26, 2001
Junilu likes ...
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
Columbus OH
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt Green check
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Junilu Lacar

At some point, maybe Java 11, the --source command line argument was needed to run the java command in single-file source mode. See this article: https://www.baeldung.com/java-single-file-source-code

This doesn't seem to be the case any more, at least not in Java 14.
7 hours ago

Piyush Sahani wrote:Try THis Way....

Is that way really an improvement? How so?
9 hours ago
It's all a matter of perspective. The externally observable behavior or result of different List implementations will be the same. This is in keeping with the Liskov Substitution Principle. However, internally, the implementations do in fact behave differently since they are after all implemented differently.

If you consider the example of engines, at some level a diesel engine essentially does the same thing a gasoline engine does: it provides power to drive the wheels of a vehicle. However, internally, diesel engines and gasoline engines operate in completely different ways. The same thing goes for ArrayLists and LinkedLists and any other implementation of the List interface.
9 hours ago

Monica Shiralkar wrote:But my doubt is regarding polymorphism. (How is it a valid case of polymorphism when here behaviour is same instead of different ).

It seems you have a basic misunderstanding of what polymorphism is. "Poly" meaning many, "morphism" meaning forms. So polymorphism means "many forms."

If you look at the example of List, ArrayList, LinkedList, the List defines the API or the generic behavior to expect from any implementation of List. That's the "abstraction" piece. ArrayList and LinkedList provide different implementations of the same behavior defined by List. That's the polymorphism part. ArrayList and LinkedList are different implementations, i.e., forms, of the same API.
1 day ago

Monica Shiralkar wrote:Instead my doubt is that when Polymorphism means same type showing different bevaviour in different situations but here whether it refers to arrayList or LinkedList the behaviour which the caller sees is the same.

Why would you care? Isn't that the entire point of abstraction/polymorphism? All you need to care about is that you're getting the correct behavior. You shouldn't care what the actual underlying object's actual type is.
1 day ago
Here's a definition of abstraction: the act of considering something in terms of general qualities, apart from concrete realities, specific objects, or actual instances.

So, if you have a reference to a "Vehicle", there are certain abstractions related to it:
1. You can ride it
2. You can get from point A to point B with it
3. You have to power it somehow
4. You have to be able to steer it somehow

If I have a Car or Motorcycle, I can do all those things. As I said, abstraction and polymorphism are not mutually exclusive. When I steer, I'm somehow affecting the direction of a Vehicle. If I had code that was written as thus:

The call on line 3 is both abstract and polymorphic, isn't it? So, abstraction is about not caring about the implementation while polymorphism is about using the "steer()" message to achieve a goal differently for whatever type of vehicle I'm dealing with. You might think of abstraction as being more concerned with the API and polymorphism enabling different implementations of the same API.
1 day ago

Monica Shiralkar wrote:Is this an example of Abstraction or instead of Polymorphism ?

They are not mutually exclusive. Polymorphism is one form of abstraction.
1 day ago
@OP - what progress have you made? I feel like you just abandoned this thread at this point. That's a bit disrespectful of the time and effort people put in to giving you answers.
2 days ago
I feel like a broken record but one thing I see that's missing from this picture is any clarity in what exactly this code actually does. To me, you don't really gain much from re-structuring the if-else statements OP has given. Until you know what each boolean expression actual means you still haven't attained one of the main goals of refactoring which is to make the code easy to understand.

@OP: by giving hypothetical code that contains no semantics (meaning), there's really not a whole lot people can suggest other than hypothetical reorganization and simplification of the structure of the code. This is probably the least bang you can get for any effort you spend in refactoring.

Give us actual code to work with to which we can attach some meaningful semantics. That will be much more useful and fruitful, in my opinion.
2 days ago

Tim Holloway wrote:I once noted to a proud application developer that you couldn't collect all those saved nanoseconds in a jar and use them later.

If I had a nickel for every jar of nanoseconds that have ever been saved... I'd probably be down a few dollars.  
4 days ago

Simon Ritchie wrote:Oh, that's interesting.  So basically, design it in such a way that on application startup the code should get the format of the responses from a configuration file?

That's not what I was thinking. More along the lines of a custom annotation that would tag a class as being one of these, for lack of a better term, "wrapper" classes. On startup, the application will scan for classes that are marked with that annotation. That would probably be the end goal because there are simpler ways that you can implement fairly quickly. I wouldn't go the "get the format fo the responses from a configuration file" route though. That seems more complicated than it needs to be. I assume the format of each response is stable and known so you can just code that into the wrapper class itself. I still don't think "wrapper" is the appropriate term for these things.
4 days ago
This stands out to me:

Pieter Vandevelde wrote:
moneyToSpend = 0.1 btc

0.1 is != to 0.01
4 days ago
Do you have any data on how expensive these connections are? What exactly are you saving and how much? Do you have evidence that reducing the cost of making multiple connections will actually translate to $$$ or some kind of benefit to your users or your company? Have you explored other approaches, like maybe caching only the most frequent used queries? Again, what hard evidence are you basing this decision on? Frankly, it still sounds a lot like "gut-based optimization" to me.
4 days ago
Programmers are notoriously bad at optimizing applications and are particularly bad at optimizing by gut feel. Do you have any objective measures that can justify loading all your data in memory versus just delegating the search task to the database which, as Campbell pointed out, is already optimized to do that kind of job?

If you don't have empirical measurements and you're just going off on "I think this will be more efficient" then your "improvements" are dubious at best.
4 days ago
One other thing about clean code: it's easy to test. Think about what kind of challenges the current design poses with regard to testing. Then make the design so that testing becomes easier to do.
4 days ago