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.

  • 9
    You're allowed to use anything that has a licence compatible with your project. Otherwise you're just wasting your time. (The right kind of) laziness is good – Richard Tingle Sep 18 '16 at 18:51
  • Assuming your curriculum includes them, I doubt using a linear algebra package in itself will prevent you from learning <vector>, <algorithm> and <list>. – Brandin Sep 19 '16 at 6:50
  • @RichardTingle: one is allowed to use anything as long as the superiors don't forbid it ;-) – Doc Brown Sep 19 '16 at 8:11
  • Change lazy to sensible in your title, and the answer is "yes" (assuming you're doing a task that involves linear algebra, of course). – Jerry Coffin Sep 20 '16 at 15:13

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.

  • 1
    You touch on it, but since the question does mention classwork, it's important not to use a package or library for the piece you're trying to learn. If you're trying to learn how to build a neural network, feel free to use a library for argument parsing, file io, but write the neural network yourself. – Alan Shutko Sep 19 '16 at 1:55
  • 3
    An important point missing on your list is future maintenance. When considering to use a third party lib, and it is either closed source, or open source but too complex to allow future maintenance by the own organization, one need to make sure the library vendor will provide future maintenance services (including evolvement of the lib) for certain amount of time. That is one of the topmost reasons why certain software companies don't use certain libs and prefer to create their own, even if that looks wasteful at a first glance. – Doc Brown Sep 19 '16 at 8:04

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.