Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 12:39 28 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Why I hate software libraries

Author Message
Gizmo

Admin Group

Joined: 05/06/2004
Location: Australia
Posts: 5078
Posted: 08:36am 12 Jun 2023
Copy link to clipboard 
Print this post

I hate software libraries. And github.

I especially hate a function I used, PHPOffice, which I needed to use in my commercial ap.

My software can use MS Word or Libra Office documents as templates. These templates could be custom invoices, print job pages, quotes, checklists, etc. The user creates the templates, and my software will take the template, search for and replace keywords, and save the template as a new file. I used the PHPOffice library to do this, but this library contains over 1000 files!, most of which is unused. Why are there so many files? On closer inspetions I found several layers of sub folders, and copies of the same files in different locations, just a real mess. But, it was what everyone was using, apparently.

I hate waste, I'm old school where a application had to fit into a few kb of ram, or download quickly on a 300bd modem. So I asked OpenAI to help me write my own function to replace PHPOffice. I asked for a function in php that would open a word DOCX file, replace certain words, and then save the file as a new file.

The AI came back with a comprehensive solution that used, wait for it, PHPOffice. So I asked it to try again, this time without using the PHPOffice library.

The result was about 10 lines of code, no library.

phpCopy code$zip = new ZipArchive;
$docxFile = 'path/to/original/docx/file.docx';
$zip->open($docxFile);

$documentXml = $zip->getFromName('word/document.xml');

// Find and replace the keyword
$keywordToReplace = 'log';
$replacement = 'dog';
$newDocumentXml = str_replace($keywordToReplace, $replacement, $documentXml);

// Save the modified file as a new DOCX file
$newDocxFile = 'path/to/new/docx/file.docx';
$zip->addFromString('word/document.xml', $newDocumentXml);
$zip->close();
copy($docxFile, $newDocxFile);

Here's how this example works:
First, we create a new instance of the ZipArchive class and open the original DOCX file.
Next, we retrieve the contents of the word/document.xml file from the DOCX file using the ZipArchive::getFromName() method.
We then search for the keyword to replace in the XML content using the str_replace() function.
We create a new DOCX file and add the modified XML content to it using the ZipArchive::addFromString() method.
Finally, we close the original DOCX file and save the new file as a copy of the original file.
Note that this example only demonstrates how to find and replace text in the word/document.xml file. If you need to modify other parts of the document, you will need to modify the corresponding XML files in the DOCX file.


Thats it. That was all I needed to do what I wanted. On reading the code and the AI's explanation, the penny dropped and I could see just how easy it is to handle and manipulate DOCX files.

Since then I've expanded on the code to add a few more functions of my own, the result is about 40 lines of code, that replaces about 1000 files in a library that everyone said was the solution.

I would like to add, I dont hate all libraries, some of them are very useful, compact and well written. What I hate is the thinking that we "need" to use a library. Where ever I looked for a solution to my docx keyword replacement need, I was pointed towards the PHPOffice library. This is the problem. We include libraries even though we only need a small part of its code.

Since then I've looked at other libraries I use, and with OpenAI's help, have written my own code to replace the libraries, saving both space and CPU time.

Why do I hate Github? Because it encourages this sort of bloated code as I found in the PHPOffice library. Many of the files in the library were parts of Githubs structure for sharing code. Its all becoming very messy.

Glenn
Edited 2023-06-12 18:37 by Gizmo
The best time to plant a tree was twenty years ago, the second best time is right now.
JAQ
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 571
Posted: 08:48am 12 Jun 2023
Copy link to clipboard 
Print this post

I am with you on hating lib's. All you want is to do x but no they include
 half the alphabet that is hard to get only the bits you really need.

 I miss the days when the whole program went into a folder nothing else
 then if you did not need any more just nic the folder and its all gone.

 No matter the OS they all did this when disk disk storage was small, costly
 and the OS/programs had to do more GUI's so as to be easier for users.

 my 2cents
 Quazee137
Edited 2023-06-12 18:49 by Quazee137
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 08:55am 12 Jun 2023
Copy link to clipboard 
Print this post

Yes, these days people treat disk, RAM and CPU as if they are unlimited.

Another issue with libraries and plugins (especially in the WEB/Internet world) is that the author/maintainer might just decide to close shop and do something else.  Or even worse, they push an update which breaks your code.

Often it is not worth betting your application on something you do not control.

Geoff
Geoff Graham - http://geoffg.net
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4043
Posted: 09:09am 12 Jun 2023
Copy link to clipboard 
Print this post

  Geoffg said  Yes, these days people treat disk, RAM and CPU as if they are unlimited.


I understand the point, but for most purposes they practically are. the fact that it isn't true for the 'mites is one of the things that makes them interesting to me.

  Geoffg said  Another issue with libraries and plugins (especially in the WEB/Internet world) is that the author/maintainer might just decide to close shop and do something else.  Or even worse, they push an update which breaks your code.

Often it is not worth betting your application on something you do not control.


It's a balancing act, am I using enough functionality of that library to take on that dependency or should I reinvent the small cog I actually need? And if you do use the library then you just want to be friends, not marry the thing ... which is the problem with application frameworks, that is almost always a marriage. With a library in theory the linker will only bring it the functions you actually need ... if its static, these days libraries are mostly dynamic and thus the DLL hell of third parties breaking your application for you.

I guess in the MMBasic world I'm striving to be part of the problem since I do have a significant library, fortunately no-one other than myself seems to use it, but even as the solo user versioning and its size are becoming a problem (too may functions/subs for the poor old PicoMite). One of the tools I started on over Easter and should finish over the summer will, having linked/included multiple files into a monolithic .bas file, then analyse that file and remove all unused functions/subs. Of course by adding transpiling and linking steps you are then losing some of the immediacy of BASIC.

Best wishes,

Tom
Edited 2023-06-12 19:19 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
aFox
Regular Member

Joined: 28/02/2023
Location: Germany
Posts: 76
Posted: 09:20am 12 Jun 2023
Copy link to clipboard 
Print this post

It's like illegal copying at school.
If you don't know if what your neighbor wrote might be right, you've already lost.

Most of the time it turns out that you have to check the code used again. You can often learn a lot from the correction. On the other hand, one often wonders how this is supposed to work at all.

Or the well-known code publisher denies any malfunction in a harsh reaction. Only to find out himself that something isn't working  years later . But then you no longer feel like helping out him with the workaround you created yourself.

Gregor
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3804
Posted: 09:33am 12 Jun 2023
Copy link to clipboard 
Print this post

  Gizmo said  The result was about 10 lines of code, no library.

phpCopy code$zip = new ZipArchive;


ZipArchive is in effect the same as a library...

But yes lots of people hurry to make something and include lots of excess stuff, or maybe don't have the talent to avoid that.

John
 
IanRogers

Senior Member

Joined: 09/12/2022
Location: United Kingdom
Posts: 151
Posted: 09:16pm 13 Jun 2023
Copy link to clipboard 
Print this post

All of my production stuff uses libraries made by me. If I have to use a library from another coder, I will rewrite it to suit me. Microsoft libraries, for example, Tons of unnecessary code as they write for every derivative. You are allowed to hack the crap out of their libraries to suit your needs.

Funny thing is, the linker is only supposed to link code used from said libraries.

BUT!!! when debugging ALL the code is listed. Albeit grayed out, but all still there.

Once I'm happy with MY interpretation I never need to touch it again.

Microchip brought "Harmony" to the table. It should be called "How not to teach programming". Not a big fan.

Sorry for my rant.
I'd give my left arm to be ambidextrous
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3804
Posted: 09:37pm 13 Jun 2023
Copy link to clipboard 
Print this post

Good linkers can avoid including unused code but when you turn debug on you're getting in the linker's way or else debugging would be harder. It's a trade-off.

Some systems show you the code that wasn't linked so you get the context of the code that is actually there.

On smaller systems (e.g. Pico) you probably have to turn debug off all the time as debugging anything with interrupts, even using a hardware debugger, is at best awkward.

John
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 479
Posted: 08:35pm 14 Jun 2023
Copy link to clipboard 
Print this post

Would you like to see a real library hell? Try to work with nodejs and npm. You will easily have a node_modules directory with a ton of dependencies and 10x to 100x bigger than you code. It's terrible
 
pwillard
Senior Member

Joined: 07/06/2022
Location: United States
Posts: 292
Posted: 11:40am 15 Jun 2023
Copy link to clipboard 
Print this post

But people love it because they can make stuff without knowing how to code.

Nodejs is the web code equivalent of Arduino.
Edited 2023-06-15 21:41 by pwillard
 
IanRogers

Senior Member

Joined: 09/12/2022
Location: United Kingdom
Posts: 151
Posted: 11:52am 15 Jun 2023
Copy link to clipboard 
Print this post

  Quote  But people love it because they can make stuff without knowing how to code.


But therein lies a problem. People (They) NEVER learn how it works, just that it does. THEN!! as Geoff said, Library owners change something and break your code. The liability isn't with them as they have that covered.

I suppose the nuub programmers will just change their code to suit, but If you take a library, modify and make it your own, your good..
I'd give my left arm to be ambidextrous
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024