JacquesCarette / Drasil

Generate all the things (focusing on research software)
https://jacquescarette.github.io/Drasil
BSD 2-Clause "Simplified" License
142 stars 26 forks source link

Improve rendering of print statements in generated code #3417

Open samm82 opened 1 year ago

samm82 commented 1 year ago

The print statements that we generate tend to be pretty messy, with string "fragments" separated into different print statements instead of being grouped together (see the Python example below). These should be formatted to be more readable while still being a manageable line length (do we have an agreed-upon standard @smiths? 80 characters?), which will likely involve using language-specific solutions where applicable (see the corrected Python example using f-strings below).

The following are examples of these messy print statements from Projectile's InputParameters module.

C++ #

https://github.com/JacquesCarette/Drasil/blob/f003baf9c65a28c28a58b4aa5010b73cec672203/code/stable/projectile/projectile_c_p_nol_b_u_v_d/src/cpp/InputParameters.cpp#L45-L56

C# #

https://github.com/JacquesCarette/Drasil/blob/f003baf9c65a28c28a58b4aa5010b73cec672203/code/stable/projectile/projectile_c_p_nol_b_u_v_d/src/csharp/InputParameters.cs#L50-L61

Java #

https://github.com/JacquesCarette/Drasil/blob/f003baf9c65a28c28a58b4aa5010b73cec672203/code/stable/projectile/projectile_c_p_nol_b_u_v_d/src/java/Projectile/InputParameters.java#L53-L64

Python #

https://github.com/JacquesCarette/Drasil/blob/f003baf9c65a28c28a58b4aa5010b73cec672203/code/stable/projectile/projectile_c_p_nol_b_u_v_d/src/python/InputParameters.py#L36-L46

Python ("Corrected") #

  if (not(0.0 < self.theta and self.theta < math.pi / 2.0)) :
      print(f"Warning: theta has value {self.theta}, but is suggested to"
          f" be between {0.0} and {math.pi / 2.0} ((pi)/(2)).")

Swift #

https://github.com/JacquesCarette/Drasil/blob/f003baf9c65a28c28a58b4aa5010b73cec672203/code/stable/projectile/projectile_c_p_nol_b_u_v_d/src/swift/InputParameters.swift#L53-L63

sadieBoBadie commented 1 year ago

Forking. I'm a beginner in contributing. Looks like a good first issue! May I take a crack at it?

smiths commented 1 year ago

@sadieBoBadie that would be great if you could contribute! I don't know anything about your programming experience, but the issue is labelled as Easy considering that the programmer is familiar with Haskell and DSLs embedded in Haskell. If you are a true beginner in contributing, you might be better off selecting one of the issues labelled as newcomers. You may also wish to review Getting Started with Drasil and our New Workspace Setup, along with the other material on our wiki.

sadieBoBadie commented 1 year ago

Got it. A lot to digest, but my interest is certainly piqued. We'll see where it leads me! Thank you for taking the time to point me toward the resources.

JacquesCarette commented 1 year ago

The first thing to do would be to really trace how this works in the code, i.e. the design-needed tag is definitely a good one for this issue.

My guess is that the backend rendered is being very literal in how it deals with Sentence structures that are build from concatenated pieces.

balacij commented 9 months ago

drasil-code/lib/Language/Drasil/Code/Imperative/Modules.hs in particular is the file to look at here. The "80 character" length limit sounds a bit more complicated, begging a separate ticket.