Forum > Other
how often do you opt for new implementation vs re-using someone’s code
Weiss:
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:
--- Quote from: Weiss on July 09, 2024, 11:23:53 pm ---Or is it a norm, for each to build his own suite of coded solutions? How it works in real world?
--- End quote ---
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.
Thaddy:
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)
Eugene Loza:
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.
gidesa:
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.
Navigation
[0] Message Index
[#] Next page