New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Improve new Random
function
#1668
Conversation
Feat: improve to accept 0, 1, 2 args
Now, I am not so sure, but I think that, because of:
I think that the function executeReturnFunction() is called only with 0, 1 or 2 arguments. But, as I said, I am not so sure: perhaps you should test this and tell us :-) You may also add some tests about this function (in the incoming days :-) ) And finally, you should change:
in
This change encapsulates random within the class, adhering to the principle of least privilege. It's generally a good practice in object-oriented programming to restrict access to class members as much as reasonably possible. To summarize, it is a good practice. It's really a pity that everything is not private by default in Java, but that's a personal opinion... |
@The-Lum thank you for changing the function name from |
Hi all,
I had to, I took a model from What are the difference between Regards, |
First, I must extend my apologies regarding the current state of the code: the preprocessor was developed incrementally, with minimal initial planning. Consequently, we've reached a point where it would benefit from some refactoring to enhance its simplicity and coherence. Let me clarify the distinction between When an error arises during the 'eating' process (i.e., while preprocessing), the nature of the available information dictates which exception is raised. If the error's location is known, an We have an hack (but this is somehow an ugly hack): every single execution goes through
This method processes each line of code sequentially. If an This approach allows us to handle errors more gracefully by leveraging the additional context available at the moment of the exception. However, it's acknowledged that this method of error handling, though effective, might not be the most elegant solution, indicating an area for potential improvement in the system's design. The proposal to eliminate The original
This can be revised to:
By adopting Furthermore, this change eradicates the need for the previously mentioned workaround—the conversion from In conclusion, by modifying the I'm uncertain if this approach will be effective; the only way to know for sure is to attempt the change. While it may seem complex at first glance, it's actually not as complicated as it appears. Your question has sparked my curiosity as well: could this really work? The only way to find out is by giving it a try—I'm inclined to do so. 😊 To summarize, having two different classes often signals poorly designed code. The good news, however, is that this issue can be rectified. I hope my explanation hasn't added to any confusion! @The-Lum, if you're considering giving it a try, I recommend creating a new branch to experiment. This could be a valuable exercise, despite its complexity. Even if you don't succeed, you'll undoubtedly gain insights into PlantUML code. 😊 Please let me know if you decide to proceed, so we avoid duplicating efforts! |
I think I'm going to have to digest all of this... 🍽️ Thanks @arnaudroques... |
Add: - `RandomFunctionTest` test file - private declaration for random lib. Ref.: - plantuml#1667 Improve: - plantuml@dbaf8ac - plantuml#1668
Hello PlantUML team,
From:
Here is a PR in order to improve new builtin
Random
function.With management of
0
,1
or2
param.:random()
->0
or1
random(n)
-> a random integer between0
andn-1
random(min, max)
-> a random integer betweenmin
andmax-1
For @arnaudroques:
I use
java.util.Random
like on some other package...Then I use:
EaterException.located("Error on Random: Too many argument")
...I don't know if that good or not... Perhaps return 0 in this case...
(Have a good night...)
Regards,
Th.
[FYI: @philCryoport]