I'm a Java programmer for the most part. I'm very familiar with the Python syntax, but I've never used it for big projects. When I started a larger project in python, I found myself confused about where to start in the design process.

I think the biggest issue I encountered coming from Java is that I'm used to the idea of an "interface" (For those not familiar, it's basically a design-by-contract way of doing multiple inheritance, defining a bunch of methods that the class that implements it will include). Certain classes in python "expect" their arguments to have certain methods. Since I'm not designing by contract, how do I define what methods these are? I don't even know how to conceptualize what these methods are. I'm so used to defining an interface for a class and not worrying about which one of those functions/methods the function/method will call.

Another issue I'm having is instance variables. Should I be defining those in my design, even though you can just change them on the fly?

I guess my problem is that I'm so used to the static nature of the code reflecting the static nature of the design, but since the structure of the code can basically change on the fly, I start to wonder whether the design should reflect that somehow.

Recommended Answers

All 3 Replies

In my experience this is one of a big issues with python. There is no methodology for design. No online resource about how to turn requirements into code skeleton. I think that is because there are rarely big projects (with more than 10 developer at a time), and the few that are there roll their own solution.

If you come from Java, you can design your classes and processes the same way. There are interfaces in python (kind of), look at the abstract base classes, file like objects, mappings. Try to reuse python's builtin patterns and data structures (dictionary, set, property, duck typing, singleton->modul global) etc. You will find, that most design issues in Java are solved by an idiom.

Changing code on the fly is not a good idea in python either. Neither is to create instance variables by the client code. Only use it if necessary.

You should design your instance variables and methods. The fact, that python uses other idioms for that does not change that. You should design the calling stack, and the object states if needed. Design by code is not a good idea.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.