Sign in to follow this  
kirkd

Code management

Recommended Posts

I've been programming for a while, and I know have a rather large collection of scripts, classes, functions, etc. that I find useful in different situations, but I find it difficult to manage them. Does anyone use a code management application, or does one even exist? I haven't found much thus far in my searches. One requirement would be different languages - C++, Java, Python, R...

-Kirk

Share this post


Link to post
Share on other sites
Describe what you mean by "management". Are you talking about managing versions of them, i.e. using version control software? Or perhaps separating them into standalone libraries that you can quickly re-use?

Share this post


Link to post
Share on other sites
Good question. Not so much managing versions (in the SVN sense), but more the latter, a tool (database?) where I can collect the routines/libraries I use, and easily access them for later reuse.

Share this post


Link to post
Share on other sites
Unless you're using Lisp, Smalltalk or one of its descendants, reuse generally isn't practical since very little code actually is reusable.

For Java, there is Maven. Create POMs for each reusable artefact, keep it in suitable repository.
For C# there is at very least nuget.
C++ is... a mess.
R has CPAN-like project called CRAN.

And so on.

Reuse of small fragments is not practical due to language design - reusing fragments brings in the entire project with it, unless the code was design from scratch to minimize dependency surface.

Hence all of the above projects require you to define code in well-defined contexts which may be reusable.

Share this post


Link to post
Share on other sites
antheus - thanks for the response.

NuGet seems to be most closely with what I'm looking for. Unfortunately, I don't write in C#. It would be nice if there was something like this for C++.

Share this post


Link to post
Share on other sites
[quote name='kirkd' timestamp='1335456993' post='4935111']
antheus - thanks for the response.

NuGet seems to be most closely with what I'm looking for. Unfortunately, I don't write in C#. It would be nice if there was something like this for C++.
[/quote]

[code]{
std::vector<int> foo;
}[/code]

Congratulations, you just included entire Linux or Windows kernel, all 50 million lines of it.

Share this post


Link to post
Share on other sites
[quote name='Antheus' timestamp='1335457130' post='4935114']
[quote name='kirkd' timestamp='1335456993' post='4935111']
antheus - thanks for the response.

NuGet seems to be most closely with what I'm looking for. Unfortunately, I don't write in C#. It would be nice if there was something like this for C++.
[/quote]

[code]{
std::vector<int> foo;
}[/code]

Congratulations, you just included entire Linux or Windows kernel, all 50 million lines of it.
[/quote]



OK. I'm not sure I follow you on that one. No. I'm certain I don't.

Share this post


Link to post
Share on other sites
[quote name='kirkd' timestamp='1335457442' post='4935116']
OK. I'm not sure I follow you on that one. No. I'm certain I don't.
[/quote]

In theory, definition of vector<> complies with standard, so typing above will work anywhere. While vector itself is very well tested, it's not completely portable.

It includes, for example, std::allocator. Implementation of that allocator may be stateful or stateless, which affects the rest of the code and algorithms.

But how is allocator itself implemented? It might need to make a syscall somewhere or call malloc which does the same. Malloc is not defined, it's provided by OS kernel. And OS kernel needs to manage these blocks. And blocks themself are defined arbitrary by OS writers, so there's a linked list somewhere. And this linked list will be making some special ring-0 calls specific to CPU. And the output of all of this is determined by C++ compiler which generates assembly while itself uses same implementation.

Or, C++ code might be compiled to an OS which has no strict kernel and no virtual memory, so vector's allocator would map directly to DRAM, causing slightly different behavior on edge cases, such being unable to support same handling of invalid memory accesses.


C and C++ do not come with abstraction layer that would allow code to be reliably reusable, it depends on everything, from compiler implementation, OS design, build toolchain and standard library implementation. Standard library works pretty well, but just about any other code is completely bound compiler settings and version of OS kernel. Change any of that and things can break in a million ways, while remaining standard-compliant C or C++ code.

Share this post


Link to post
Share on other sites
[quote name='kirkd' timestamp='1335459212' post='4935125']
I see your point. It's a bit of an extreme example, but I do get your point.
[/quote]

Simpler version is that any real world C++ source depends on implementation of compiler (less so these days) and the OS (down to version) it runs on.

Consider a simple DX example - it implies version of Windows, version of Visual Studio and version of DX. You could copy paste it, but unless you replicate the environment, chances are it won't compile, won't work correctly or will have subtle bugs.

Ideally, all code would seek to minimize external dependencies, but in practice it's too expensive.

Same applies to, say, Python which depends on VM version and implementation (2 vs. 3, CPython, PyPy, Jython, ...) as well as any hidden dependencies, such as native C code used by project. But all of these would be called Python code and snippet might be copyable between them.

Share this post


Link to post
Share on other sites
Antheus, I'm not convinced your hyperbolic arguments are helpful here. Reusing code (in particular low level code like C++) has challenges, but it is not quite the Everest you are making it out to be.

Tone it down.

Share this post


Link to post
Share on other sites
I'm really looking for something smaller scale. I have a couple of dozen C++ classes I wrote that I use regularly (custom exception handler, parameter file parsing, data file clean up, etc.), a large number of Python scripts that do a whole variety of things, and a few R scripts that I use for general data mining, chart generation etc. The issue I run into, is that when I start a project, I find myslef doing many of these things over and over and I find myself looking through my directory tree to find the script I wrote that did this last time, trying to remember where I saved it. I'm just looking for something that will conveniently organize the classes/scripts/etc., and maybe give me the ability to more simply find the ones I've already written. Maybe searchable keywords - that sort of thing.

Again, I'm not doing anything monumental here. I would just like to organize the pieces I have a little (lot) better.

Share this post


Link to post
Share on other sites
Why not just include a comments section in each script, where you list keywords you think you might like to search by later?

Then you could just use the search built into your OS.

Share this post


Link to post
Share on other sites
[quote name='mrbastard' timestamp='1335465523' post='4935159']
Why not just include a comments section in each script, where you list keywords you think you might like to search by later?

Then you could just use the search built into your OS.
[/quote]

Yeah, I thought of that, too. I was interested in how others manage their code, and hoping for something a bit more elegant.

Share this post


Link to post
Share on other sites
You could try putting code you reuse in a personal wiki. Almost all such software has search functionality and versioning. Some also have tagging.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this