I'ld like to organize my coding and projects better. Are there any folder-name and file-name defaults I should use or are there any preffered ones within the industry?
Thanks for any tips.
Coding C++ most of the time, I organize my folders according to the namespaces my classes reside in, under a global src/ folder. I mix header and source files, although I know a lot of people that keep headers and sources separate in src/ and include/ folders. I think this is rather a thing of preference - I see the advantages of both approaches.
My filenames are typically the same as the classes the source file belongs to - (at least) one source file per class. For non-class code, I try to organize the functions/data according to logical units with "speaking" names.
Related
I'm working with IntelliJ IDEA in a rather large tree of projects almost exclusively on about 5 folders nested deeply in the hierarchy. Ideally I just want to see those 5 folders most of the time - the other projects and the other folders in their projects are usually just visual clutter. How can I get a view as close as possible to this with IDEA?
I do want all projects accessible in my workspace, so I can't just throw away the others. And even that would not help too much, because those folders are deeply nested in their projects. The favorites view almost does what I want, since you can unfold the folders there - but if there are some new files they are often not visible there (not sure whether this is a bug or a feature). Do you have other ideas? Thank you very much!
It depends on what you are trying to do. You can create scopes by criteria.
Go to preferences (mac) -> appearance & behavior -> scopes
There you can create local and shared scopes. You can manually edit these or use a regex pattern. The current reference documentation is located here.
Here are some examples from the jetbrains website of using regex.
file[MyMod]:src/main/java/com/example/my_package//* - include in a project all the files from module "MyMod", located in the specified directory and all subdirectories.
src[MyMod]:com.example.my_package..* - recursively include all classes in a package in the source directories of the module.
lib:com.company..*||com.company..* - recursively include all classes in a package from both project and libraries.
test:com.company.* - include all test classes in a package, but not in subpackages.
[MyMod]:com.company.util.* - include all classes and test classes in the package of the specified module.
file:*.js||file:*.coffee - include all JavaScript and CoffeeScript files.
file:*js&&!file:*.min.* - include all JavaScript files except those that were generated through minification, which is indicated by the min extension.
I would like to add into project some files that shouldn't be compiled. I mean mainly text files with for example notes, concepts, comments etc.
I realized that it is possible only at module level. But it is not very convenient. I'd rather prefer to keep them on project level. Is it possible in any way?
And if not:
I have another idea: to create special module, name it for example "other_stuff", do not create src directory and put files there. Is it ok? I'm afraid of potential compilation problems when one of modules is artificial, with no sources but still has sdk assigned (it is probably impossible to leave module without sdk assigned).
While generating artifacts you can add any file into your artifact. Also, in modules you can have folders not declared as source, and they will not be compiled.
I'm learning/vetting CMake at the moment as I'm thinking of migrating our code to it. One thing we do a lot of with our current make system is to "subproject" common code files. For example, we have a lot of shared, generic headers (plus some c/cpp files) which get included in every project we create. I want to replicate this in CMake but I don't see an easy way of doing it. To be precise, I want to do something like:
Parent CMakeLists.txt
add_subdirectory(shared_folder shared_build_folder)
#Next line should somehow add in the files reference in the shared_folder
add_executable([specific files for this project] build_folder)
Child CMakeLists.txt (shared_folder)
#Somehow have a list of files here that get added to the parent project
So far I've found various "ways" of doing this, but all seem a little hacky. I'm coming to the conclusion that this is in fact the way I have to do things and CMake isn't really geared towards this style of development. For clarity, most of my solutions involve doing something like creating a variable at the parent level which consists of a list of files. This variable (via some shenanigans) can get "passed" to/from any children, filled in and then when I call add_exectuable I use that variable to add the files.
All my solutions involve quite a few macros/functions and seemingly quite a bit of overhead. Is this something other people have tried? Any clues on the best approach for doing this?
Thanks
Andrew
We were facing the exact same problem and after some time of crying we accepted the CMake-way and it resulted in a better structured project even if it meant to change some parts of our structure.
When using sub-directories the targets are automatically exported throughout the whole project (even in subsequent other add_subdirectory-calls) once the add_subdirectory-statement was processed: sub-projects which contain common code are creating libraries.
There is also the PARENT_SCOPE which you can use to export variables to parent CMakeLists.txt
For "other" things we simulated the FindPackage-mechanism by including .cmake-files into the main CMakeLists.txt with include. In doing so we can provide variables easily, change the include_directories and do other fancy things global to the project.
As there are no dependencies between cmake-variables, we don't use cmake to configure the source (features of the project), but only the build (compiler, includes, libraries...). This split was the key element of our build-system-refactoring.
using Cocos2d project template (for objective c)
I've got a nice little hierarchy setup in Xcode, e.g categorization with folders, multiple levels, however in the file structure, its just one big directory of files, should I leave it like that? Should I replicate the hierarchy in file structure manually? Should it be automated did I do something wrong?
As Protheus says, the group structure in XCode is for organizational purposes only and not synced with the file system. For some projects though, it might be worth to keep XCode's group structure and the file system in sync. For example, I like to edit my files with VIM from the command line sometimes. On big projects with several hundreds of files, it is much easier to find specific files if you have a logical structure in the file system.
I discuss this in more detail in this blog article.
As far as I know neither structure in xcode, nor structure in project folder affect the program.
You structure it all for your convinience only.
In Java we organize files in packages, Clojure has namespaces and Ruby has modules.
How to organize Objective-C files? any convention/best practice exists?
In Xcode everything is going under "classes" directory.
What I usually do is enforce physical folders (and groups within Xcode) for the files and have them added to the project from where they are. From there you can group files logically however you want them.
By default, it will create the file within the same Classes folder, and I find it difficult to navigate when dealing with an external source control client.
Leverage Categories to have separate files for separate logic for a particular class. For example I will have private method interface in the implementation file with a separate category name so that it is somewhat "private" to other implementations.
For uniqueness, you could try to prefix folders or groups of classes.
We use MVC on all but the smallest projects. So in the "Classes" folder we start by adding three folders, Model, View, and Controller. Under those directories we might create subfolders grouped by functionality with the app (controllers for various subsections, etc.). You can add files directly to Xcode or the folders themselves. Similarly we have a Resources directory, usually in the same directory as the .xcodeproj file and under that folders for Images, Nibs, Audio, etc.
Of course the above just describes a disk-based organization strategy. Since Objective-C is still C, you can build libraries and header files for APIs that you want to export. You can also use categories. Many of our projects reference a /Common directory that is outside of the project folder (and under Common we have Model, View, Controller, etc.). Sometimes we copy files from Common into the project if we expect to make significant changes to them that we don't want other projects to inherit.
I just organize things in XCode. Group files as appropriate. Yes, everything ends up in the Classes directory.