Saturday, January 28, 2023

🆕 STRUCT, STRUCTURE, and RECORD (alternative keywords for TYPE)

"Out of the box" wwwBASIC implements the "TYPE" keyword as found in QBasic and QB64/QB64pe.

This is really handy for creating complex "composite" data types, which gather any number of variables (with whatever data types) all under one data type name.

For example:

TYPE player

   name as string

   batting_avg as double

end TYPE


dim as player pitcher


pitcher.name = "Johnny"

pitcher.batting_avg = 97.8


print pitcher.name, pitcher.batting_avg


But the keyword "TYPE" semantically annoys me.

After juggling the synonyms that  we find in various programming languages (TYPE, RECORD, STRUCTURE, STRUCT), not entirely satisfied with any of them, I decided: the heck with it, I'm setting them all up.

You decide which you prefer, based on your pros/cons/preferences:

  • TYPE - END TYPE (like QBasic, QB64, QB64pe, ...)
  • RECORD - END RECORD (like Pascal, ...)
  • STRUCTURE - END STRUCTURE (like PureBasic ...)
  • STRUCT - END STRUCT (like C, C++ ...)





No comments:

Post a Comment

🖥 Pongy game

This program is a port (and slight mod) of the QB64pe program by SierraKen.  (SierraKen's program shared with the QB64pe community in th...