Stephan van Hulst

Saloon Keeper
+ Follow
since Sep 20, 2010
Enschede, The Netherlands
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 Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Stephan van Hulst

All of this is very reasonable. Using threads directly is a bit old-fashioned, however. Let your main thread create an ExecutorService, which you pass to the class that's responsible for listening for incoming connections. It starts listening by submitting a task to the executor service that handles the server socket. Every time a new connection comes in, that task creates a new task to handle the connection, and submits it to the executor service. That way, the (number of) tasks that need to be performed is completely decoupled from the (number of) threads that perform them.

It would be extra nice of you don't just pass an ExecutorService to your server class, but also a task factory, that creates new tasks that handle your incoming connections. That way your server class will work not just for chat applications, but for any application that has multiple clients.
You still haven't explained what the parameter of Storable means. It just makes no sense to me.
1 day ago
Stephan van Hulst,
Your post was moved to a new topic.
(This informational message will self destruct in two days)
Sorry for hijacking the topic. After this post, I'll leave it at that. Or I'll just split the topic.

I will take your points about me Putting My Money Where My Mouth Is, and about the fact that programming At Home is not the same as programming In Real Life. I am certain one never needs static variables in fresh code, but I'll have to consider how to fix existing applications in a cost-effective manner.

I have some final questions. Why is it important to maintain insertion order? I agree that for things that absolutely need to be processed in insertion order (database migrations or whatever), an increasing sequence number is the natural key. But then the ID has semantic meaning. I advocate GUIDs for records that don't have a meaningful combination of properties that make them unique. And how does an increasing sequence number help in slicing the database, when after many deletions over time, there could be many large gaps between successive records?

Can you explain what you mean by that POJOs are not supposed to have infrastructure-related property mandates? Does that mean that I can't simply pass a logger(-factory) in a constructor?
1 day ago

Rob Bank wrote:Can I check if you are in C# mode? Seems var is not a Java syntax.

Haha, yes. I use C# a lot at work and sometimes I hammer out code snippets without checking them in my compiler. I apologize.

And RaceResult parse does not accept path so do you mean;

RaceResult has an overload that accepts a path, which reads the lines from a CSV file, and then delegates parsing those lines to the overload that accepts a stream of lines.

This does not printf anything but neither do I get any direct errors so I'm thinking this could work once I figure out how to correctly implement some modifications I did to Participant to more accurately match my app objectives.

Are you sure that the file you're reading from is not empty, and that the output is directed to where you expect it to be?

Lightbulb, I think I get the intension of path in RaceResult. It enables a main shortcut like;

Yes. This is what I was going for in my previous post, but goofed up.
1 day ago

Tim Holloway wrote:1b. GUIDs are HORRIBLE database keys. They're effectively long random strings, so you cannot slice a database according to any logical function. Which can interfere with optimization and housekeeping.

Why do you want to perform such a logical function on an ID? Either the property that uniquely identifies a record is meaningful, in which can you use neither auto-increment nor a GUID, or the ID isn't meaningful, and you wouldn't perform logic on it.

They have no inherent sequence, so you'd better have at least one other unique chronometric field in the table if you want to be able to access by order added.

Okay. That's fine isn't it?

Use GUIDs as, say, invoice ID numbers and see how customers react.

This is a good argument. I don't have an elegant solution to this. I guess for invoices, I would generate an ID by mangling the properties that make the invoice unique, or use a database that DOES generate identifiers correctly.

The one thing GUIDs are good for is (virtually) ensuring that every record in the table has a truly Globally Unique ID, regardless of where it was originally created. And that's a great help when you have a system with multiple feeds, but not for most other applications.

I would argue that it's not the responsibility of the application to know this, but of the service that it uses to store data. Regardless of whether you use a GUID or something else, I don't think you should generate it statically from your application.

2. Who passes around random number generators? Unless you are specifically looking for repeatability of "random" numbers on a per-thread basis in a multi-threaded environment, one RNG is all most people need, and there's no need to instance it.

I do, in most of my classes that need a source of randomness. Greatly improves my ability to unit test the application as well.

3. See Item #2. It's even less likely that you want multiple instances of a generator for a blockchain. [...] Having more than one generator defeats the whole concept.

I don't agree that needing only one instance of an object automatically means it should be static. Singleton classes cause so much bugs in large applications. People use them because they can't be bothered to properly declare dependencies between objects. That's just lazy programming.

Which reminds me. The most popular logging classes also use static accessors to obtain the logger instance. Because, again, that avoids the need to explicity inject or construct them.

Really, what's the problem with just injecting them explicitly?
2 days ago

Rob Bank wrote:Those concepts aside, I'm still stuck on the usage of lineOfCsv in the Participant class and path in the RaceResult class and how they relate.

As I see it, RaceResult invokes Participant participant. There is no invoking the other way around. So, after I in my main class do Participant.parse(lineOfCsv), RaceResult can operate on my data parsed into Participant. Hence, what is the intention of the RaceResult class reading path?

That's just a convenience method that reads lines of CSV from a file, and converts them to a RaceResult. If you don't want to read CSV from a file, but want to provide them from a different source, you would call the parse(Stream<String> lines) method directly.

What seems most logical to me (still not knowing what to do with RaceResult's path) would be to (in my main class) do [...] where I get errors like Cannot make a static reference to the non-static method participants() from the type RaceResult

That's because you call participants() on the RaceResult class, but you need to call it on an object of type RaceResult. Given that you have a file with comma separated values, and the path name is stored in the pathResult variable, this is how the main method would look:
2 days ago
Alternatively, if you want to maintain the type of the elemental unit, you can add another type parameter.
2 days ago
I don't understand why you have a generic type parameter on Storable. What does it mean? What if I make a class WaterBottle implements Storable<Number>?

If you remove it, you have the following:
2 days ago
That's just the message that the JVM prints out. 'Exception' probably just reads nicer than 'throwable'.

Yes, you should distinguish between the two, even if the message doesn't. Throwable includes critical errors that you probably shouldn't catch.
3 days ago
You need to use a layout manager.

Check out these two guides:

Look at the sample code and play around with it a bit. Try to achieve what you want, and if you get stuck, let us know and show us your code.
4 days ago
You can lay a JPanel out in a certain part of the window, and change its background color.

What is it that you're exactly trying to achieve?
4 days ago

Tim Holloway wrote:An extremely common case would be where you have a single-threaded app who is the sole writing client to a database where the primary key is a sequence number.

Why not let the database generate IDs, and why not use GUIDs?

Another case would be if you needed a random number generator. Mathematical RNGs (see Knuth) start from a seed and each successive value is produced based on the preceding value. Which, of course means that they aren't truly random, but that's immaterial.

Why isn't the generator an object that's passed around, containing its own internal seed?

A more complex case might be a blockchain generator, where the last block is referenced by the next block to be generated.

Again, why isn't the generator an object?

That's the only sanctioned way to obtain such useful things as the HttpServletRequest, HttpServletResponse, HttpSession objects, [i]etc.[i] within JSF.

So where would the static variables be?
5 days ago

Tim Holloway wrote:Suppose we need a factory that can produce a sequential key value.

Why? For what purpose? I can't easily think of a valid use case where this behavior isn't also dangerous.
5 days ago
This discussion was split from

Let me qualify my statement in my own way: "Never EVER use static variables, with variable meaning that the value of the variable or the state of the object it references can change".

Even if the class is not intended to be thread-safe, static variables are just a no no.
5 days ago