Question

First, let me give some background before I actually state the question. I study physics and all my programming classes have been in easy programming languages like MATLAB. By easy I mean that the language does much of the thinking for you... For the next years I will be taking computer science courses and I am thinking of pursuing a career in programming.

Considering a lot of college courses are in C++, will using a linear algebra package (Armadillo) with similar syntax to MATLAB be considered lazy?

I am coding up a genetic algorithm right now, and while it went fast in MATLAB its taking a lot of time in C++ without the aid of these packages.

How does it work in real life? What packages are you allowed to use?

For example I wouldn't like to build my C++ knowledge with armadillo and not have deep knowledge of other more widely used packages like "vector.h" "algorithm" "list" etc.

Was it helpful?

Solution

Richard's comment is most of the answer already. Whenever you're programming for anything but a class exercise, you'll want to reuse as much existing code as possible, with just a few other considerations to balance.

The advantages of code reuse are:

  • You work faster, because some work has already been done.
  • The existing code has a good chance of being better than anything you would write from scratch, because it probably has been around longer, has been better tested, and better optimized.
  • Often enough, the existing code is in a domain you're not that familiar with. For example, you're doing physics simulations, but that doesn't mean you know very much about how to make linear algebra efficient to compute. Using code written by others means you can lean on their expertise.

There are just some things to consider:

  • Licensing. The author of the code you want to reuse holds the copyright to it, and you cannot use the code without his permission. Libraries will come with a license that tells you what you can do with them, and if you want to use the library, you have to comply with the license. Armadillo is under the Mozilla Public License 2.0, which means you can use it freely.
  • Integration. If your project is larger, it may be fairly complex to integrate 3rd party libraries. Depending on the amount of use you get out of the library, it may not be worth it.
  • Distribution. If a library is only available as DLLs, or needs some registration with the system, but your method of distribution must consist of "copy this executable somewhere", you may not be able to use the library.

As the saying goes, in a programmer, laziness is a virtue.

OTHER TIPS

What do you ever mean by "allowed"? I guess I might add something here which might help clarify a misconception of some beginner students: you're asked to write your own code and algorithms etc. etc. in the university, because you're learning a course and you want to consolidate what you've learned in the classes by actually writing the code yourself. Such coding is an aide to your learning process. For example, after learning a particular data structure/algorithm, you write your own code to see how it actually works out and deepen your understanding. This makes sense.

When you're doing a real-life programming project, you're not writing code as an aide to learning some concepts/knowledge; you're trying to produce an engineering product. Engineering is not really about invention, but building on the foundations laid out by others already, to address a particular practical need. There's a saying that programming is 80% reading/reusing others' libraries/codes and 20% writing your own. Might be a bit exaggerated but you get the spirit.

In your case, if you're doing a programming project for a course and it explicitly asks you to code your own algorithm, you wouldn't want to use external libraries. If you're doing your own engineering project, then use as many libraries as possible before trying to come up with your own.

Get this distinction clear, and you'll understand what you're doing.

Licensed under: CC-BY-SA with attribution
scroll top