[fpc-pascal] netdb, DNS and TCP

Michael Van Canneyt michael at freepascal.org
Mon Oct 12 09:49:39 CEST 2020



On Mon, 12 Oct 2020, Noel Duffy via fpc-pascal wrote:

> On 11/10/20 9:42 pm, Michael Van Canneyt via fpc-pascal wrote:
>> 
>> On Sun, 11 Oct 2020, Noel Duffy via fpc-pascal wrote:
>
>>> To avoid that duplication, the code would need to use a dynamic buffer and 
> fill it just before socket writing. The TCP variant would include its length 
> field in the buffer. Additionally, after reading the response from the 
> socket, the buffer contents would have to be copied into a record data 
> structure. It's a tradeoff between execution efficiency and simplicity.
>> 
>> It always is.
>> 
>> But I am inclined to think that DNS queries benefit more from execution
>> efficiency, hence the preference for avoiding the copying of buffers as 
> much
>> as possible.
>> 
>> One could of course argue that with TCP, the speed suffers in each case.
>
> Therein lies the rub. Once your code reads or writes to the network, all bets 
> are off with regard to speed.
>
>> 
>> If you have suggestions for a better implementation, I am all ears...
>
> Well, better depends on what you're optimizing for, of course. In many places 
> the DRY principle is considered a Holy Commandment graven on stone tablets 
> and breaking it tantamount to heresy.

Then I am a heretic :-)

I have a pragmatic approach to such things. DRY is a valuable principle.
But normally I will prefer clarity of code to DRY. I still want to understand
today's code 15 years from now at a glance. Or someone else's code today.

Michael.


More information about the fpc-pascal mailing list