Hot answers tagged

194

A Python module is simply a Python source file, which can expose classes, functions and global variables. When imported from another Python source file, the file name is treated as a namespace. A Python package is simply a directory of Python module(s). For example, imagine the following directory tree in /usr/lib/python/site-packages: mypackage/__init__....


38

There doesn't seem to be an argument in favor of the big repo in this thread, so here's one: The advantage of a big repo with all your code in it, is that you have a reliable source of truth. All the state in your overarching project is represented in that repo's history. You don't have to worry about questions like "What version of libA do I need to build ...


35

Git tends to experience performance problems when used with large repositories. To quote Linus: And git obviously doesn't have that kind of model at all. Git fundamnetally never really looks at less than the whole repo. Even if you limit things a bit (ie check out just a portion, or have the history go back just a bit), git ends up still always ...


27

Your code appears to have one feature you can use to your advantage here: all those grouping comments. You can use those comments as the basis for breaking up the method into chunks by extracting smaller methods. You pull out each chunk into its own method, then call that method from the code's original location. As you start to pull these pieces out, you ...


26

To achieve highly organized and decoupled modularity, you can follow the Hierarchical MVC architectural pattern, sometimes known as Presentation–abstraction–control (although they aren't strictly the same pattern). Kohana, Alloy, Fluency and FuelPHP support HMVC natively* and Kohana's HMVC approach is discussed in Scaling Web Applications with HMVC and ...


22

They want [something that can] show their changes across all projects instead of trying to remember what project they made a change [to]. Sourcetree (a free-as-in-beer GUI Git frontend) allows you to register multiple repositories, organise them into logical groups, and then view status across all of them at once: I am not affiliated with them in any way.


22

The concept of a module is different from the instantiation of that concept. Java has always had modules. A method is a module, so is a class and so is a package. A module is a unit of organisation in which internal details are hidden, and that communicates with other modules via agreed contracts. For example, a method is a module because it has hidden ...


21

The following annotation in the Framework Design Guidelines Section 3.3. Names of Assemblies and Dlls offers insight into why namespaces and assemblies are separate. BRAD ABRAMS Early in the design of the CLR we decided to seperate the developer view of the platform (namespaces) from the packaging and deployment view of the platform (assemblies). This ...


21

You should put the unit tests in the same repository because otherwise someone has to answer to the question "Where are the tests?" every time the project is handed over from one person to another. References to other repositories tend to get invalid over time when repositories are relocated and people change from one version control system to another. Just ...


20

Refactor Slowly. Expect this to take some time to complete, and may occur over several iterations before you can completely remove your Utils assembly. Overall Approach: First take some time and think of how you want these utility assemblies to look when you're done. Don't worry too much about your existing code, think of the end goal. For example, you ...


20

You're dealing with multiple teams and multiple projects. Likely decades of work went into the codebase. The short answer is that your teams and projects have varying needs and varying dependencies. The monolithic repository approach reduces commits to "Everything is stable in this configuration!!!" (i.e. unrealistic, huge commits sourced from many teams). ...


17

You do the simplest thing that works for you. For a one function module, there is absolutely no point in creating a package. Packages are useful for creating an additional namespace and/or for organising your code across multiple modules. The json and unittest modules in the Python standard library are really packages for example, for code organisation ...


16

A module, encapsulates code and data to implement a particular functionality. has an interface that lets clients to access its functionality in an uniform manner. is easily pluggable with another module that expects its interface. is usually packaged in a single unit so that it can be easily deployed. For example, dapper.net encapsulates database access. ...


16

TL;DR; the equivalent of a git repository is a CVS module, not a CVS repository. CVS is designed with a notion of modules being a subdivision of a repository, and it is common to use CVS repositories with several modules having a quite independent life. As an example, it is easy to have branches specific to one module and not present in another. git has ...


15

Ideally, all work which can be thought of as part of re-usable code, should be created in the form of library. The balance work, is application which should be separate where main() will reside. But main() alone doesn't have to sit in isolation. Functions like parse_arguments(argc,argv) should be along with main rather then separate.


14

What you encountered is the so-called "God object", because it does all or knows all. Run away from it (if you can). There isn't a definite number of LOC per module, but it should be something that makes it easy to browse the code and easily understand what the methods are doing. From my personal experience, if your module goes beyond 1k lines*, you are ...


12

Module might be an overloaded term, so much that Wikipedia describes it under the term Modular Programming when discussing its use relative to software. They discuss it in terms of structured programming which was based on a top-down design approach. Key characteristics of modularity related to the use of low coupling and high cohesion. My usage has been ...


12

A python module is nothing but a package to encapsulate reusable code. Modules usually, but not always, reside in a folder with a __init__.py file inside of it. Modules can contain functions but also classes. Modules are imported using the import keyword. Python has a way to put definitions in a file and use them in a script or in an interactive ...


10

Doing the same thing twice is nearly always a bad idea. (see DRY) You have to change it in two places if your validation changes increasing your chance of bugs. My advice would be have both Save and Validate call another method that validates the input. Its still a good idea to check on save as well as validate as you should never trust user input. They ...


10

The math module is a builtin, so short of modifying the Python interpreter itself, I don't think you can modify it. However, writing a module is definitely something you can do. If you structure your files like this: somefolder mymath.py myprogram.py ...you could simply do import mymath inside myprogram.py, and use any functions or classes inside ...


10

Let me hazard at an answer, though much of it may be assumptions/splitting hairs/ranting, etc. Are they the same thing? Well, yes and no From this JavaWorld article about "Modularity in Java 9": Packages as a modular solution Packages attempt to add a level of abstraction to the Java programming landscape. They provide facilities for unique coding ...


10

Your approach is not technically wrong (except a minor detail, see footnote) but it goes against established usage patterns and obfuscates code. I.e. it lowers readability and increases the likelihood of errors. That might be justified if it is outweighed by a clear and significant advantage somewhere else. And here lies the problem. Sjoerd already pointed ...


8

Seems like event-driven architecture, but I don't know of any examples exactly like what you are doing. Is your co-worker asking out of curiosity or could it be a veiled criticism (i.e. why did you do things in this way)?


8

Simply put, that is the way it was designed. You mentioned Java as a counter example - the Java language designers wanted to make classloading somewhat implicit, so they check the same directory before throwing ClassNotFound. Outside of that you need to qualify, just like in Python. As Tom Anderson said, C does the same thing as Python, and it's a compiled ...


8

How many modules do you have? Are they hardcoded? If you're in a case where you have only ten possible modules which are written once and require the whole update of the entire application if they need to be updated, then you can easily use checks which will propagate through the models and be used by the views to adjust the user interface (for example by ...


8

Looks like a wrong approach, for several reasons: The things that you don't want to be "visible" to outside, should not go into headers. Instead they go into anonymous namespace in the source file. Your __local__ things are still visible, and everyone can access them


7

Our coding standard requires that main() is in main.c. Other methods in main.c tend to be high level error handlers and helper functions for main (refer @Dipan answer "parse_arguments", as well as things like "display_help" etc. A good rule to go by is when a funcion starts to do more than support the running application and start doing business logic, it'...


7

There isn't a formal definition of a module, and what a module is (or isn't) in the context of your project largely depends on the nature and design of the project. Generally speaking a module is a standalone piece of code that provides specific and tightly coupled functionality, modules define and enforce logical boundaries in your code.


7

You want the version of the tests to match the version of the code, so that implies you keep the tests in the same repository as the code. That goes for automatic code generation scripts, build scripts, etc. too.


7

This really depends on the modules. You are saying the service require all the modules to exist - but do the modules require the service(or other modules) to exist? If you have a module that's an integral part of the project, but you have it as it's own module for organization reasons(example - models, views and controllers modules in MVC architecture), ...


Only top voted, non community-wiki answers of a minimum length are eligible