-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add new java printer #26522
base: master
Are you sure you want to change the base?
Add new java printer #26522
Conversation
✅ Hi, I am the SymPy bot. I'm here to help you write a release notes entry. Please read the guide on how to write release notes. Your release notes are in good order. Here is what the release notes will look like:
This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.13. Click here to see the pull request description that was parsed.
|
🟠Hi, I am the SymPy bot. I've noticed that some of your commits add or delete files. Since this is sometimes done unintentionally, I wanted to alert you about it. This is an experimental feature of SymPy Bot. If you have any feedback on it, please comment at sympy/sympy-bot#75. The following commits add new files: If these files were added/deleted on purpose, you can ignore this message. |
class JavascriptCodePrinter(CodePrinter): | ||
class AbstractJavaFamilyPrinter(CodePrinter): | ||
|
||
def _print_Pow(self, expr): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the only thing they have in common or is there more coming? It doesn't seem worth having a shared superclass for just one method.
Generally, Java and Javascript is not very common, shares nothing common in history, and maintained by different entities (Oracle and W3C), I think that you need to add comprehensive test cases. It's hard to believe that it can generate generally correct code for Java, unless we can read the outputs. |
I think it is wise to reuse the names of the math functions (which are the same between Javascript and Java I believe). It does not need to use a subclass (and it doesn't look like it's an abstract one? so that would need to be renamed anyhow). And yes, I think more tests are needed. Did you try to get the tests in test_algorithms to pass? (the choice of supported math functions lead me to believe that): sympy/sympy/codegen/tests/test_algorithms.py Line 136 in ab88a7d
If so, it would be great if we could test a full java compilation & execution on the CI-server (we already do this for C). We could duplicate the _print_Pow method, but I would be curious to see if we could even move that into |
If the math libraries are the same then what will be the actual functional difference? If the two are extremely similar, we could just have a single class with a flag to switch between the two. Or just document that for the purposes of what is implemented, |
I'm not personally a fan of having a flag which changes the behavior of methods of a class, I much rather have two distinctly named classes (their relation, i.e. one being the child of the other, or them both sharing a common parent class is to be considered an implementation detail in my opinion). Math constants are spelled differently for one. I see But some math constants are spelled the same way, e.g. Integer division differs between the two, since JavaScript doesn't really have a first class integer type. If we want to support special functions, I guess we could default to Apache commons math library for Java. But that can of course wait to a later date. |
Well if they're only incidentally similar, I would actually go the other route and not have the two share any code in common at all. It's not a big deal to duplicate the code across two different files, and it would lead to less confusion and mistakes to have them be separate. |
References to other Issues or PRs
Brief description of what is fixed or changed
JavaScript looks supported. But there is no printer for Java.
Other comments
Release Notes