Recent

Author Topic: how often do you opt for new implementation vs re-using someone’s code  (Read 1798 times)

Weiss

  • Full Member
  • ***
  • Posts: 156
Kind of a broad question on code-writing in general. I find myself writing my own implementations of well-known math and numerical routines. I have “code recipes in Pascal” but stopped using it. My go-to book now is numerical analysis, with no code, where I have to build it from math itself. There are various reasons for that. For one, I am still foggy on most things related to licensing the published code. I also still struggle with my ability to read and fix someone’s else errors. But mostly, I have fun.

Now, I am not going to change that, but feel that this isn’t normal. I also see that I would solve problems faster, and roll on to next ones, if I was more comfortable re-using existing code more efficiently. Or is it a norm, for each to build his own suite of coded solutions? How it works in real world?

440bx

  • Hero Member
  • *****
  • Posts: 4344
Or is it a norm, for each to build his own suite of coded solutions? How it works in real world?
I think the "norm", if there is one, is to customize as necessary if and when necessary.

For instance, I normally use the sort and search routines found in ntdll and find that there is no reason for me to write my own sort routine when the one in ntdll is quite good (to say the least.)  (that said, for small tables with a small number of elements I have my own shell sort but I stopped using it because ntdll's qsort does well on small number of elements too.)

the binary search routine is a different ballgame.  the regular bsearch returns nil if the target element isn't found in the table but, there are occasions when it is convenient to have it return a pointer to the element that is _closest_ to the target if the target was not found.  That required a minor change in the standard algorithm.

OTH, for other algorithms I use Sedgewick's Algorithms and I don't think I've ever used one of those algorithms without thoroughly customizing it (it's fair to say, in the great majority of cases, a complete rewrite.)

It also depends on what my ultimate goal is, if the code is proof of concept or throw away code, I'll likely use whatever is available with an absolute minimum of changes. OTH, if the code is for a "real app" I intend to use long term then, I'll re-invent the wheel as many times as necessary until I'm satisfied I got the wheel I want.


(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 15220
  • Censorship about opinions does not belong here.
I try use as many things from the libraries in the standard distribution as possible.
If I can find high quality code available for my task at hand I will use that.
If what I can find is of sub-standard quality it may inspire me to do a rewrite
If I can't find it - like the ternary and fuzzy logics I published, hashes, PRNG's, audio filters, LFO's - I do a complete implementation from scratch and add it to my tool kit.
There are some things that I re-implement all the time because the algorithms are etched in my brains and I am too lazy to look it up, like singly and doubly linked lists and several types of trees. And sometimes I forgot that I already implemented something and one of the forum members alerts me that I wrote code for something myself years ago.
So basically, it depends.
But, a bit like you, I also tend to implement certain things from the math itself, especially if it is about data analyses or logic.
Professionally I wrote lot's of code in other languages, C(++), java, fortran, cobol, ada, basic, some of that not available, but implementable in Pascal, so nowadays I sometimes do that if I am bored. 47 years of code is a rich resource.
I still do some COBOL consultancy in the financial services industry and sometimes I might find some gems that I could probably do in Pascal.
side note : COBOL proficiency is a bit of a gold mine, so if you are there are many very well payed jobs available. There is not only a shortage, but outright starvation. You can basically ask what you want. Or if the industry knows you know COBOL you get offered ridiculous hourly rates. ( am now at a project with a major bank where I am the youngest at near 67..oldest is 75.. in the team.. so be versed in geriatrics)
« Last Edit: July 10, 2024, 08:58:58 am by Thaddy »
My great hero has found the key to the highway. Rest in peace John Mayall.
Playing: "Broken Wings" in your honour. As well as taking out some mouth organs.

Eugene Loza

  • Hero Member
  • *****
  • Posts: 711
    • My games in Pascal
After MathCad issue back in 2002-2003 when it was yielding "real part of imaginary root" as a result of cubic root instead of apparent real number I have serious trust issues with third-party code when doing math modeling - so always prefer to know every bit of code I'm working with (aka write it myself so I know who to blame if the calculation results don't make sense and more importantly - to know the assumptions I've been making when writing the code).

However, in a less important context I'm all up for reusing some code. Like using a Lazarus UI. Or whole subsystems of a game engine. In my gamedev experience I've came across many plugins, but I must admit that I don't remember a single one which I didn't have any problems with and sometimes I estimated that it would have taken me less time to write my own implementation than to struggle with bugs of the plugin.

And... I guess I just love reinventing the bicycle.
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

gidesa

  • Jr. Member
  • **
  • Posts: 96
Hello,
writing from zero some math algorithm can be interesting and fun.
But there are tons of libraries, not written in Pascal, that concentrate decades of improvements
and experience. For example, Lapack for matrices.
So, if you are doing professional/sensitive coding, the choice depends on what is your task: a simple ("school") implementation from zero without any special performance/optimized code;   or using an external "de facto standard" library, almost always not written in Pascal.


gidesa

  • Jr. Member
  • **
  • Posts: 96
( am now at a project with a major bank where I am the youngest at near 67..oldest is 75.. in the team.. so be versed in geriatrics)

I know a Cobol consultant of 80, regularly working in office every morning :-) Yes, there are still many active Cobol programs around (question for another thread: why this?), and less and less experts.


Joanna

  • Hero Member
  • *****
  • Posts: 872
I think it’s admirable that you want to redo code instead of using libraries. You can look at code in library and improve it and it’s a good way to practice programming.
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

VisualLab

  • Sr. Member
  • ****
  • Posts: 391
Now, I am not going to change that, but feel that this isn’t normal. I also see that I would solve problems faster, and roll on to next ones, if I was more comfortable re-using existing code more efficiently. Or is it a norm, for each to build his own suite of coded solutions? How it works in real world?

This is certainly normal behavior. At least that's what I did (or, more precisely, I was forced to do). And I will certainly do it more than once, out of necessity. The example with numerical libraries is absolutely appropriate here. FPC does not have large, convenient and well-equipped numerical libraries that would be part of the package (Lazarus). What I mean here is that there are various GUI data containers in FCL, that LCL includes support for basic controls, etc. However, the standard Lazarus equipment does not include extensive numerical libraries* (matrices, functions, differentiation, etc.). This is completely understandable, because:

- few programs use it (only engineering and scientific ones), - it is difficult and time-consuming to implement and test. There are "external" numerical libraries, you have to install them additionally. Besides, in the case of C, C++ it is similar, only there are slightly more of these libraries (including commercial ones). And now if someone just needs, let's say, implement an approximation, sometimes it's worth implementing it yourself.

And it's similar in other areas, e.g. handling the downloading (capturing) of static images and video recordings from cameras or recording and processing sound. The library doesn't always fit well into the project being developed. Then you have to adapt it to your needs.

This also affects the growth of your own experience. After all, those who wrote libraries considered professional also had to gain this experience at some point.

wp

  • Hero Member
  • *****
  • Posts: 12161
FPC does not have large, convenient and well-equipped numerical libraries
I guess you have not seen NumLib which comes with fpc? Matrices, vectors, determinants, (simple) fitting, root finding, special functions - most of what you need. A disadvantage is its awkward syntax. But it can be managed, and I was able to write a wiki for it: https://wiki.lazarus.freepascal.org/NumLib_Documentation

Thaddy

  • Hero Member
  • *****
  • Posts: 15220
  • Censorship about opinions does not belong here.
Yes, and it is very good indeed. It only shows it is written by academics and for academics. Most of that can be "solved" by aliasing the function names. It is also one of the oldest fpc libraries, which means a lot: the code is tried and tested.
Thanks for the wiki entry, one of the better ones!
« Last Edit: July 10, 2024, 03:36:00 pm by Thaddy »
My great hero has found the key to the highway. Rest in peace John Mayall.
Playing: "Broken Wings" in your honour. As well as taking out some mouth organs.

Curt Carpenter

  • Sr. Member
  • ****
  • Posts: 470
I suspect that the ability to reuse code without feeling too uncomfortable about it is the mark of a professional that is working in a team with budget and time constraints.   Otherwise, I recall a line from Numerical Recipes somewhere that begins "If you hate black boxes as much as we do..."

Joanna

  • Hero Member
  • *****
  • Posts: 872
I wonder how much malware gets put into software by companies trying to scrimp on hiring developers. Why bother hacking when people will voluntarily download malware to save money? :D
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

Thaddy

  • Hero Member
  • *****
  • Posts: 15220
  • Censorship about opinions does not belong here.
You examine the code, only then you use the code.
If you see a "black box" you are basically blind.
If you do not understand the code, leave it alone.

When sources are available and you compile from source, the "black box" is you, never the code.





« Last Edit: July 10, 2024, 07:54:12 pm by Thaddy »
My great hero has found the key to the highway. Rest in peace John Mayall.
Playing: "Broken Wings" in your honour. As well as taking out some mouth organs.

Weiss

  • Full Member
  • ***
  • Posts: 156
thank you all, interesting take, echoes my own in most cases. I did not mention trust issues and blackboxes, but those are part of reasons for re-inventing the wheel. Also, 440 mentioned custom implementations for “real app”. Which made me think, new as I am, everything I make is a “real app”. Like for teenager, everything is important and real.

I imagine things are different when working in a team with budget and time pressure. I work on a ship which was highly digitized like that, on a budget and under time constraints. 4 years into service, we are still dealing with some dramatic issues with software that runs the ship. Soft written in C, slapped together to make things work. I am not complaining, in these 4  years ships of this class have carried millions of passengers from one shore to the other, so business-wise it is a plausible strategy, just different.

Curt Carpenter

  • Sr. Member
  • ****
  • Posts: 470
Sounds like an interesting life!

One of my first jobs long ago (interlude before the military) was working a few months on a Supervisory Control System for the nuclear power industry.  People should be terrified at how a lot of software gets made. :)

 

TinyPortal © 2005-2018