This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!

Junilu Lacar

Sheriff
+ Follow
since Feb 26, 2001
Junilu likes ...
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
Forum Moderator
Junilu Lacar currently moderates these forums:
Columbus OH
Cows and Likes
Cows
Total received
201
In last 30 days
2
Total given
73
Likes
Total received
1743
Received in last 30 days
28
Total given
314
Given in last 30 days
1
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Junilu Lacar

Nelson Plasencia wrote:
Grass - ... any unit of grass has a 75% chance of dying.

Trees - ... any unit of grass has a 60% chance of dying.


Seems like a copy-paste error. Is that supposed to say "any unit of tree has a 60% chance of dying"?
1 day ago
Welcome to the Ranch!

Around here, we don't do people's homework for them. Please tell us what you have done, show us some code you have written, and ask specific questions on what is confusing you or you're having trouble with.

We'll give you guidance and tips on how to write better code. You have to make the effort of solving your homework.
1 day ago

Knute Snortum wrote:I don't know what a 2D HashMap is, but looping through a Map can be done in several ways.  The simplest is probably



or

or
1 day ago
If you have a number like 314, how are you going to use a while-loop to break that number down into its individual digits?

Hint #1: You will use integer division and the % operator.

Hint #2: You will break it down from the 1's place. That is, you will get 4, then 1, then 3.

Hint #3: You determine the order of concatenation when you build up the string result.

Programming is about exploration and experimentation. Experiment with the operations you've been told to use.  Think: If I had a number like 314, how would I use a loop, integer division, and % to get 4, then 1, then 3? You can either try to find the answer by hand using pen/pencil and paper or you could experiment with a smaller program.
1 day ago
With Java enums, it's pretty straightforward to translate a String value to an equivalent enum value and vice versa. Just use the Enum.valueOf(String) and the Enum.toString() method, respectively.
1 day ago

Jordi van Selm wrote:I make a 2D-array of the alphabet + the value of the letters and compare that to the char array (1D)...

Is there anyone willing to say which things I need to study?


I'd be willing to say you need to study object-oriented programming concepts some more. Using a 2D array with letter+value somehow mapped to each other is a very non-object oriented way of modeling the idea.

The letter and value are both attributes of a Scrabble "tile" are they not? They always go together, right? So that means a more natural object-oriented representation would be some kind of object, say a Tile, that has at least the attributes of "letter" and "value".
1 day ago
Of course, when you search for Scrabble tile values, you quickly realize there are many sets of values depending on the language you're using.
1 day ago
I like your idea to use an enum, Campbell, and yes, it seems like a straightforward proposition to implement double, triple letters. I would assign that responsibility to the Board or Square though. The Tile would just know its face value.
1 day ago

Emily Rosemond wrote:This reason why I'm guessing is because a setter doesn't return anything, it sets a value. If it were to return something then it probably violates POLA, because clients didn't expect a setter to behave this way and I don't have authority to say it does violate POLA, I don't really know.



I'm guessing (see what I did there ) that you don't really know because you haven't been writing tests before you write the code.

One of the advantages of Test-Driven Development is that it makes you think about your API very carefully. Your tests become examples of how someone would use your class. If you read the test code or better yet, have someone else read the test code, and they don't understand why the code works that way, then you have probably violated POLA.

As an example of how to use the class under test, the test code should make sense to someone reading it for the first time. Otherwise, it's probably safe to say that the behavior you have coded into your object is surprising, or at least interesting in a not-so-good way.

A setter that returns a reference to the same object is interesting. It's not so surprising because it's a common pattern, especially when you're trying to create a fluent interface. The possibly not-so-good part is the rationale behind designing the setter method to return a self reference rather than just be a void method like most other setter methods. You have to be able to explain the reason using test code to show concrete examples why this is a good thing to do and a useful thing for users of your class.
2 days ago

Emily Rosemond wrote:You might be able to, because you have years of experience, so you'll be able to look at the code and know, for beginners, it will take time.


Yes, I'm experienced but that only means I have made way more mistakes than you have.

"Experience is what allows us to recognize a mistake when we make it again."
2 days ago

Emily Rosemond wrote:This code isn't meant for a program sitting in a publishing company or to interact with a sophisticated database. It's to illustrate my problem, Are there situations where it doesn't makes sense to follow DIP? Book and Author were the only example I could come up with. Why should a specific type of Author exist? Why should a sciencefictionauthor subclass exist? Why can't it be a label applied to an Author?


Why do you worry yourself over these things? As you said, it will take time for you to gain experience. The only way to gain experience is to actually practice. Write programs. Don't embark on flights of fantasy and imagination of what you would do if this or that thing were to happen. Don't try to NOT make mistakes. On the contrary, while you're still learning, try to make as many mistakes as you can. Then understand why they are mistakes and what you can do to avoid them in the future.

You're making a mistake right now by starting with a bunch of "What if" scenarios in your head. Stop that.

Find a good problem or exercise where the DIP or whatever principle you're trying to learn might apply. Then WRITE SOME CODE. Discover what kind of problems you encounter when you make one decision or another. If the code becomes difficult to work with, try to apply the principle you're trying to learn. Come back here and ask questions, ask for advice. We're more than willing to give you some, and more.

Good luck.
2 days ago
Agility is not about making developers "produce more, faster" -- Seems like most people who claim to do Agile these days are getting it wrong. WTH.

Agility comes in the long run when developers are given the space to do their work at a SUSTAINABLE pace. That means they are allowed the time to write quality code. They are allowed time to learn. They are allowed time to make mistakes and learn even more.

When you have managers and tech leads cracking the whip as you have been describing, that's not developing at a sustainable pace. They are only driving your organization to the breaking point faster. When that happens, everybody loses.
2 days ago

Paul Clapham wrote:... these days I find it hard to learn things by discussing theories. I find it much more useful to look at actual real-life examples (or reasonable approximations) and understand how they illustrate the theories (or how they conflict with them).


Yes, yes, yes.

Again, programmers should learn how to solve problems as they present themselves. The set of problems that can arise from a situation that involves hundreds of variables and moving parts is far too large for us to possibly predict and completely cover up front. We just have to do the best we can with what we know at the moment. As we learn more through testing and use of the program, we can expand our design and adapt it to handle a wider range of problems.

While you're still learning about the domain your program lives and operates in, however, focus on solving the known problems and making your program well-factored enough so it reflects your current understanding of how the program behaves as clearly and as cleanly as possible. That way, it will be easier for you and others to make changes when you discover more problems your program needs to handle.
2 days ago

Emily Rosemond wrote:When a class is an attribute of another class, does it always make sense to follow DIP? Are there situations where following DIP will introduce more problems than it solves?


Any situation where the principle is applied to a problem it wasn't meant to address.

What problem are you addressing by applying DIP to this kind of relationship?

DIP says that less stable parts of your program should depend on more stable parts, and not the other way around. Now, what about dependency stability is a problem between Book and Author. Is one inherently more unstable than the other? If something changes about Author, is that change likely to break any code where the Book-Author dependency comes into play? Ask the same questions going the other way, too.

I don't have any answers for you other than those questions. Again, because I don't know what exactly is the problem you're trying to solve here.
2 days ago

Emily Rosemond wrote:A common pattern is to abstract out the class behind an interface, but what happens if doing so is unnecessary or pointless.


Complexity happens.

A rider on a gray horse follows soon thereafter.

Ok, a bit too dramatic but the reality is not far off. Think of the kind of unnecessary pain and suffering overly-complex programs and designs have caused all these years and the money wasted because of it. That's why I'm a big believer in YAGNI (You ain't gonna need it) and DTSTTCPW (Do the simplest thing that could possibly work). It's also why I lost all my hair. Well, a big part of the reason, at least.
2 days ago