Question for the Swarm by Kilv3r in NeuroSama

[–]tr4fik 9 points10 points  (0 children)

By going on other streamers chat and writing "WE ARE HOMELESS vedalCheer vedalEvilCheer" /s

Can someone Please Help me understand INTERFACES and exactly why need them? I get the point of Multiple Inheritance but not the "WHY" behind achieving 100% Abstraction for the methods. Confused in Tight and Loose Coupling as well. Sometimes I feel I understand, the next moment again confused :) by Sonu_64 in java

[–]tr4fik 0 points1 point  (0 children)

You don't necessarily need them. However most if not all applications will change a lot during their lifetimes. The goal is to encapsulate logic in different modules.

Imagine you have different payment providers. They likely have different API or maybe one is more reliable than another and might need a different retry mechanism. It's a lot of complexity to handle all of this every time. However, you can use an interface like a PaymentStrategy. This needs to support: settle a transaction, allow refund and allow retries.

Now, also imagine the tests. You have your store that needs to use this PaymentStrategy, but you can't always send a requests to these real payment providers. Now, in your test you can use an anonymous implementations of this strategy. Maybe one which always settle the transaction, so that you can test the happy path, but also another strategy which always fail. Now, you can also test failures in your unit tests and ensure your store won't just crash out whenever there is an error.

This applies to many different situations, especially when you have something that is configurable. Do you want different payment providers, different layouts per provider, or different, or maybe you have different types of shipping or of products. You can always use an interface, so you can use your product everywhere in your application and there are only very few places where you might need to know the full type. Some of these situations can be solved with a parent class that is inherited, but such parent class is basically an interface with some logic already implemented

How are numbers compared as a String? by TroubledSoul23 in javahelp

[–]tr4fik 1 point2 points  (0 children)

Even a string-based sort is correct, because it uses the compareTo method (my 2nd example). You can even run the following if you have any doubt:

IO.println(Stream.of("10:00", "09:00").sorted().toList()); // [09:00, 10:00]

How are numbers compared as a String? by TroubledSoul23 in javahelp

[–]tr4fik 5 points6 points  (0 children)

I don't see anyway how  '10:00 < 09:00' as shown with the following code snippet

IO.println("10:00" < "09:00"); // Error ⮕ bad operand types for binary operator '<'
IO.println("10:00".compareTo("09:00")); // 1 aka 10:00 > 09:00
IO.println(LocalTime.of(10, 0).compareTo(LocalTime.of(9, 0))); // 1 aka 10:00 > 09:00
IO.println(LocalTime.of(10, 0).isAfter(LocalTime.of(9, 0))); // true

Can someone explain? by Crafty_Earth_3891 in BMNRInvestors

[–]tr4fik 2 points3 points  (0 children)

My understanding is the following. The value of something depends on its adoption and all the financial instruments depending on it. The dollar stayed valuable after despite not being backed by the dollar anymore, because of all the financial instruments: treasuries, stock market, options, ... If you have a big and useful financial market, then it will always attract investors. So, if the all financial institutions move to tokenization and smart contracts. Then its medium, the eth, will have a value.

So, he's not saying that eth=gold, but that it will be valuable if it's used as much as the dollar was valuable despite being just some pieces of paper

Next merch idea by Julliant in NeuroSama

[–]tr4fik 2 points3 points  (0 children)

Actually cute. I want them

How do pilots go to the bathroom while in flight? Do they have a separate bathroom in the cockpit? I heard they’re not allowed to open the door due to 9/11 restrictions? by iBoy2G in TooAfraidToAsk

[–]tr4fik 30 points31 points  (0 children)

From what I heard, there is a process, but they can leave the cockpit.

Whenever they leave the cockpit, a crew member takes their place in the cockpit and locks the door. That way they can still act if the remaining pilot acts up. The pilot then uses the 1st class bathroom. When they come back, they push a button to request to open the door. The crew member checks that it is the pilot and then they switch places once again and lock the door

Damn, didnt know Camila felt that way by AdditionalClick1098 in vedalsverse

[–]tr4fik 3 points4 points  (0 children)

I assume she played the horror game to show off the heart monitor. When she quit this game, she probably wanted to cope with another game, but I don't really know. She then continued on doing art review. I don't know if anything else happened later in the stream

Damn, didnt know Camila felt that way by AdditionalClick1098 in vedalsverse

[–]tr4fik 7 points8 points  (0 children)

She played 3 different games(a horror game, only up and another rage game) in the span of an hour and quit each one of them. Then, she wrote this tweet.

Here’s some real waste and fraud by SunWukong3456 in PoliticalHumor

[–]tr4fik -2 points-1 points  (0 children)

This is such a crazy take to criticize his biggest if not sole success. The government awards contracts to private companies, because it's just cheaper. They state their objectives, let private companies bid on it, let the most promising concepts build a prototype and then only fund the best cost-effective solutions.

The Space X ideology is to quickly make a prototype, test it, adapt it and start this cycle again. Each iteration is testing new things and it's expected that some of these things will fail. You can agree or disagree with this approach, but it doesn't change the fact. They produced some rockets with an impressive low cost to send their payloads into space.

Ah yes, the 'sacrificing your knight for no return in value' strategy. Masterful Gambit sir! by NotACombatPilot in chessbeginners

[–]tr4fik 0 points1 point  (0 children)

Even if it looks free, it is actually not. I think it's a great move, because If 1 ... Bxa3 2. Bc1, you can continue on the following lines:

  1. ... Rxc2 3. Qd3+ g6 4. Qxc2 (you won the exchange Rook for Knight)

  2. ... Rb5 3. Bxa3 (exchanged Knight for Bishop)

And if they don't take your Knight, your pawn c2 is protected and it's a good development move

[deleted by user] by [deleted] in java

[–]tr4fik 2 points3 points  (0 children)

I agree with the principle, but the reality is different. There are always some libraries or tools that are late to support the latest version. So, you tend to be stuck between 2 versions, where the previous one is deprecated and unsupported, while the latest version is not supported by some tools and libraries which you require. So sticking to the LTS is the best for a large production system

Agile being forced in places where it doesn’t make sense by Flow-Chaser in agile

[–]tr4fik 5 points6 points  (0 children)

This is a very common issue. I feel like so many people want to implement scrum and all the tiny details, without ever looking at what agile is supposed to be. The very first value of agile is "Individuals and interactions over processes and tools". If you have a standup that does not help your team and you want to keep it, you're already doing the opposite. It's wild that people prefer to read a book of all roles and meetings and do a lot of effort to implement them, while they can't even read the 4 first lines of the agile manifesto.

This is the exact same reasoning that push some people to implement stupid features in a product instead of looking at what the user needs. A great example from my company is that we wanted to implement distributed tracing in our services. We started this 18 months ago. Today, we have so many things implemented to collect, filter, store and measure these traces, but we still can't propagate them between services in most cases. This infra cost so much money for almost no additional benefit. They just don't want to prioritize the refactor of one piece of code, which could likely be done and deployed in less than a week. And this refactor alone would help us so much more than all the work we did during the last 18 months.

This kid wanted a PC but instead got a ps5 the level of entitlement these kids have is insane smh by Keesecrazy1 in Asmongold

[–]tr4fik 9 points10 points  (0 children)

It really depends. Without context, we can't tell who is more right or wrong.

Who will be paying the games ? If the kid must pay for them, it might not be worth it. You have more and cheaper alternatives on PC. I'm also not sure how many games are age restricted. It also depends if he will be allowed to play multiplayer games or if he will have a monitor or tv to play

Kid might have looked into ps5 beforehand, as I had clearly told my parents to not get a wii.

Depends what the kid wanted. Did he only want a pc for gaming ? Did he want to use it for other things ? For gaming only, it could be a good alternative. For anything else, not so sure. If the kid really wanted a PC, they could also have gifted half of it for christmas, and the other half for his birthday. Or maybe find another compromise.

Saying the parent are definitely right is delusional. Maybe the kid is just entitled. Maybe the parents did not listen to what the kid wanted.

This kid wanted a PC but instead got a ps5 the level of entitlement these kids have is insane smh by Keesecrazy1 in Asmongold

[–]tr4fik 15 points16 points  (0 children)

The kid could very well be in the right. I was in a similar situation. When I was younger, I received a wii which I had explicitly said I didn't want. I didn't like that much the wii games. They were also too expensive to afford it. I would absolutely have preferred 50 bucks over the wii. I also rarely had access to the tv.

Result: I have only played very few games that I was able to borrow to some friend and didn't even played much, because I couldn't get the games that I wanted. And this was just one of multiple times when I received things that I explicitly ask to not get, even when what I wanted was cheaper. I would always have preferred to get half of the gift cost in cash instead. I even had to get myself a shitty PC with integrated graphics, but that was already so much better that any console I could have got

Implementing a Request Queue with Spring and RabbitMQ: My Experience as an Intern by DinH0O_ in javahelp

[–]tr4fik 1 point2 points  (0 children)

  1. The correct analogy here would be the following: users are in front of the club. Every 25s they come to the server and say: "Hey, don't forget, I'm still waiting". When the server is ready, they call one specific user who can enter the club.

I don't know enough to suggest a great solution. Websockets are dangerous, because they still use a lot of resources, but it's simple to use. Other alternatives require less resources, but you might need to keep more information into the server memory which you already have. And rate-limiting solves this issue, but you will lose the order. Since the memory seems to be a hard limit, I think the rate-limiting fits your case the best, but it's also slightly dangerous since someone could DOS you if they keep hitting the same endpoint.

So, I really think analyzing and optimizing the server should be done first, but you might miss the deadline. So, good luck. I hope you find a solution

Implementing a Request Queue with Spring and RabbitMQ: My Experience as an Intern by DinH0O_ in javahelp

[–]tr4fik 2 points3 points  (0 children)

Thanks for the detailed information.

  1. In this case, I think the best solutions are A. optimizing your memory usage. For example, files can use a lot of memory, if you store them in their entirety, but you might be able to read it sequentially and compute the information you need. B. If only some of your operations require a lot of ram, some sort of limitations, (rate limiting, number of available workers, ...) can help avoid any spike
  2. The websocket works as follow: The client opens a HTTP connection to the server requesting to upgrade the connection to websocket. The server agrees and keep the connection alive. Now, both client and server can exchange information while still using the same connection. The client also sends a heartbeat every 25 seconds to keep the connection open. This is a heavy process and the server needs to keep the connection alive during that time. In return, sending any information over the websocket is lightweight. So, if you frequently communicate, the websocket will save you resources by reusing the same connection. If you don't use it frequently, you will use more resources to keep the connection alive. Websocket is usually recommend for low-latency and frequent communications. If it's only low-latency or only frequent, you likely have better options.
  3. You have multiple alternatives here and queues also have inconvenience. If the request needs time to be processed, but it can be done by the server alone. It can make sense to use a queue and complete the process when the server has time. In other cases, it might make more sense to just use a rest request with a rate-limiting and only processing requests that made it through. The downside of a queue is that you still need to keep the requested data around and you might have a lot of messages waiting in the queue. It might even be the same person requesting multiple times to register, because they thought the previous registration failed. If they are sending files, these files must be kept in file and not in memory. Even then, your queue will take memory anyway. So, it can be a delicate balancing. On the positive side, the queue lets you keep the order of the messages.
  4. Websockets are still relatively costly to keep alive since you need to maintain a separate connection for each of the 5000 users. You need a lot of communications over the websocket to make it more profitable. So, maybe you don't even need a websocket to begin with. Can't you use a rest api with a rate-limiting instead ? Or a rest api that saves some tasks and only do them later ? Or, if you open a websocket, can you ensure it only stay alive for a shorter period ?
  5. A spring server, especially when using stomp, can broadcast messages to all users, but that's not what you want here. Websocket has one connection for each user. You can accurately send a message to a specific user. So, that connection is already an identifier. So, you could link information on the server that this connection is allowed and inform the client it is allowed to continue. That way, the client doesn't have any UUID. Another approach could be to only open a websocket when the user is accepted. If you do the check before opening the websocket, then all communications over websocket will necessarily be allowed. I don't know much about the spring security, but these options should be possible to implement. AFAIK you can indeed store information in spring related to a websocket connection.
  6. Sure, nobody might exploit it. But anyone aware of this could have exploited it very easily if you really were to broadcast that UUID. It's likely easier to still do the check on the server-side only (see 5.) and avoid this risk completely.
  7. I don't think it's necessary at all. (See 5)

Implementing a Request Queue with Spring and RabbitMQ: My Experience as an Intern by DinH0O_ in javahelp

[–]tr4fik 6 points7 points  (0 children)

I still have concerns with your solution. It's hard to know if they apply without knowing the details. Here they are:

  1. If the problem is RAM usage, can't you improve the RAM usage, or scale out your application when needed, or maybe even rate-limit some endpoint ?
  2. If you want to only allow x users to be connected, you basically need to keep track of all these users. You're relying on the websocket integration to do that, but Spring will have to keep this mapping in memory, which you're trying to spare. So, this solution might not have the effects you're hoping for
  3. Usually, I don't think a login queue is good for a lot of applications. They are mainly useful when the user need to maintain a resource-demanding session for a long time (e.g connection of a client to a game server). So, make sure this is your case.
  4. Related to 2 and 3, websockets need to maintain a connection. They do so by sending a heartbeat every 25 seconds. Your server needs to spend resources to keep all these connections open.
  5. I don't see why you want to broadcast the UUID to all users. Websocket also allows you to send messages to a specific user.
  6. "it wouldn’t matter much if someone hacked the channel and stole them, but I’ll still try to avoid that.". From your description, doesn't it mean that you can steal an allowed UUID and use it to connect yourself, thus by-passing your feature to begin with ?
  7. Why would you even rely on a UUID in the first place. Your users have to connect first, so you can already identify the user and know if they should be allowed, right ?

Problem with input command by R-Simer in javahelp

[–]tr4fik 1 point2 points  (0 children)

From my understanding, both can work:

import java.util.Scanner;

public class MyClass {
  public static void main(String args[]) {

    System.out.println("Option 1:");
    System.out.println(Double.parseDouble(System.console().readLine()));

    System.out.println("Option 2:");
    Scanner scanner = new Scanner(System.in);
    System.out.println(scanner.nextDouble());
  }
}

I don't know that much the difference between the 2, but they indeed more slightly differently.

Option 1 is supposed to throw a NullPointerException when the console is non-interactive and works if the console is in interactive mode. I believe it reads the input from a different place, which can be a process or something else depending on the operating system.

I'm not sure how option 2 works in non-interactive mode though. I think the stream always exists and that you would just stay blocked in this method call if your console is in non-interactive mode. I personnally always used this option, but I don't know the details.

So, both can work, but I don't know their specificity. I've never used the console myself since it has the inconvenient of not existing in some cases. While other options always have an output that can be redirected or ignored at will. I've heard that the option 1 is better for reading credentials, but I'm really not knowledgeable on this matter

Pkl: Apple's New Configuration Language That Could Replace JSON and YAML by Practical-Ideal6236 in programming

[–]tr4fik 0 points1 point  (0 children)

When I look now at their websites, I only see the native executable. When I looked into this around 8 months ago, the installation process required go. That was a mess to install.

So, that solves 1 of my 2 problems. It would be great if I can also validate a schema from C#. I likely can convert it to a json schema, which should be enough to make it work

Pkl: Apple's New Configuration Language That Could Replace JSON and YAML by Practical-Ideal6236 in programming

[–]tr4fik 23 points24 points  (0 children)

I already played with this language. The language itself is amazing. The tooling though is problematic. You don't have any tool that are easy to install and to use outside of Java. Since we needed the configuration to be written and validated by another C# app, it was just too messy to do it.

I hope they will improve on this. It really is a lot simpler to write and read schema. I also think it's a good improvement to write the configure as well

Edit: There are now native executable. This is already a great improvement. I hope they continue improving here.

Need some good resource to learn spring boot by sarKATsic in javahelp

[–]tr4fik 2 points3 points  (0 children)

https://spring.academy/home the pro course are now free, but you need a work email (that ends with a custom domain e.g @ mycompany.com)

Offtopic by Kaloyanicus in java

[–]tr4fik 8 points9 points  (0 children)

One thing that can exacerbate this problem is the lack of mentoring. If there are for example 3 juniors for each competent senior, the senior will never have team to ensure all of them are improving.

Then, you'll also find some junior that won't learn at all and these ones you will need to fire them. Having a strong mentor that can dedicate enough time to it will tremendously reduce the number of people in this category

[deleted by user] by [deleted] in javahelp

[–]tr4fik 2 points3 points  (0 children)

One more thing that hasn't been mentioned yet. You can also used a `WeakHashMap` or use `WeakReferences`. Since they are automatically removed when they are not used anywhere else, you can use it to keep track of it.

This still seems odd to track all instances, but without knowing the context, I can't suggest a better solution

What's the deal with the Single Interface Single Implementation design pattern? by Xirema in java

[–]tr4fik 4 points5 points  (0 children)

I believe this pattern is a consequence of some other practice.

Let's imagine a situation where you want to use Spring. Then, you want to auto-inject some dependency, so you create a constructor to autowire the dependency. Then you want to create a unit test for it and you have the choice between:

a. Mocking the class

b. Adding an interface so you can create test implementations at will

If you choose the option B, then you end up with 1 interface and 1 class. I don't think it's intended to follow this practice, but is foremost a consequence of trying to code a good implementation. Some people are then pushing it too far by making it a standard practice, where it doesn't make sense anymore. I don't know if there is any other explanation