[Gambas-user] MkXXX$() functions

Benoît Minisini gambas at ...1...
Sun Jan 16 15:29:47 CET 2011


> > 
> > Here is what I thought when I have written that:
> > 
> > - Gambas has now structures.
> > - Structures contents can be written to a stream by the WRITE
> > instruction. - Streams have support for endianness.
> > 
> > Now, when you write something to an UDP socket, one writes equals one
> > message, so you cannot send a message with successives writes.
> > 
> > Hopefully, when writing a structure, a temporary string is used for
> > storing the intermediate writes, and so only one write is finally done
> > to the UDP socket.
> > 
> > So, please, can you try that? Instead of using strings, create one
> > structure for each message you send to your UDP socket, fill the
> > structure with the message contents, and use the WRITE instruction to
> > send the structure to it. And tell me if it works! :-) And if you
> > finally find it cleaner or not.
> > 
> > Thanks in advance.
> > 
> > Regards,
> 
> I read the documentation on structures and they look interesting if not
> tricky. Sounds like a good solution to sending groups of variables of
> differing datatypes as a single UDP packet, but who knows until I change
> my code to use structures. Will maintain current build for now to keep
> moving forward, but will use structures if they are more efficient or
> the other functions are removed. ASC() and STR() should be removed then,
> too. Kidding...

Asc() and Str$() have nothing to do with the MkXXX$() family. Asc() returns 
the ASCII code of a character, and Str$() converts an expression into a string 
by using the current localization. So they won't disappear.

But MkXXXX$() do not seem to be useful:

- They can be replaced by structures. 

- Moreover, they can lead to bad design : data sent to the network must be 
big-endian, and MkXXXX$() cannot guarantee that. For example, ARM CPUs can be 
big-endian, and they become more and more important!

- And, finally, your code will be cleaner and easier to read if you replace a 
bunch of MkXXXX$() by structures. And a little bit faster! :-)

I hope I will convince you to rewrite your code. :-s

P.S. Did you write an article for Slashdot recently?

-- 
Benoît Minisini




More information about the User mailing list