0

Say I want to implement a mathematical tool or simulator for mechanical joints.

There are different types of joints (revolute, prismatic, etc).

Which have different properties (degrees of freedom, constraints in a 2d planar system, constraints in a 3d spatial system, etc).

I can think of multiple ways to implement this. Many of them excluded for being clearly the wrong solution. But I don't have enough Python experience to know the 'best' or 'most pythonic' way to implement it.

We could have a basic class "Joint" which has 
"None" for each of their properties
has get methods for the properties
A subclass for each type of joint
    (wherein the properties are defined)

Or

We could have a basic class "Joint" which 
takes the type of joint as an input
has a list of possible joint types
has a corresponding list for each property which defines the property value depending on joint type
has a method which finds the index for the joint type, and sets variables for each property according to the value 
    at that index in each of the property lists
has get methods for the properties

Or

We could have a basic class "Joint" which 
takes the type of joint as an input,
has a dict defining each property depending on the joint type
has a method which defines a property variable for each dictionary
has get methods for the properties

Or, some alternate method.

3
  • 1
    "don't have enough Python experience to know the 'best' or 'most pythonic' way" - doesn't matter. Nobody's going to come and judge you code because your code is not "pythonic" enough; that's more about the coding style - and that will come with time and experience. Choose one that gets the job done while being simple and understandable enough to you, so that you can easily pick up on what's going on after you come back to the code a month later, when you've forgotten what you were thinking about when you wrote it. You can improve it later if you feel you need to. Commented Aug 14, 2022 at 7:28
  • 2
    P.S. You can also post your code, after you've written it, to codereview.stackexchange.com to get some opinions and suggestions from people. You can then take from that what makes sense to you, and update your implementation (or not, up to you). Commented Aug 14, 2022 at 7:33
  • Does this answer your question? If there are two ways of approaching a task, how should one choose between them? Commented Aug 15, 2022 at 8:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.