Article Publishing
~ string driver like writeln text file driver
Freepascal has a text file driver or writeln driver system where you can write a special code to replace the functionality of of write/writeln. For example you can make writeln basically do whatever you want, instead of writing to stdout you could write to a socket over tcp/ip, or write to a string buffer.

Why not offer a String that has similar features? Many people do amazing different things with strings. For example I (and probably others too) invented the CapString/CapArray idea to grow a string in chunks instead of growing only by small amounts of characters at a time. So if you could write a driver for a string just like you can write a Text/Writeln driver, then you could use strings for different things, instead of just the plain and boring string you were given with your compiler.

These driver/plugin ideas for data structures does open up the system for abuse, but it offers you power too.

Why not just use an object instead of using a string? i.e. use object orientation? Well for one thing that requires free/create for the object whereas strings are much less verbose when writing code. That's why a lot of people use strings for many things, as they are easy to use without the need for creating/freeing them.

Imagine your programming language gives you a basic string. But you want to do more.. you want the string to grow only in 2048 byte chunks at a time to reduce memalloc calls. So you simply write a "Driver" or plugin that modifies the original string behaviour. This may be easier said than done: writing a compiler with a driver/plugin system to redefine the behaviour of a string may not be easy. I am not familiar with how difficult it was to write this system for writeln/write text driver for fpc/delphi. Plain C even has something similar for its stdout features AFAIK.

So are these languages trying to use an object oriented style of plugin/driver design without fully being object oriented? Possibly - as you are reusing a string object to do many things. But the advantage is that you do not have to create/free the string each time you use it, compared to say an obnoxious stringlist that requires TStringList.Create and Free whenever you use it.

Simple question: if it was possible to write a driver/plugin system for freepascal's Text writeln/write system, would it be possible to write a plugin system for a String? Would GoLang offer something like this, or the next version of C that's not C++ (if that's not GoLang itself)?
Copyright © War Strategists, M.G. Consequences 2009-2017    Help! Edit Page