Index page of tutorial / teaching / pedagogical topics (draft articles for documentation)

Forum for discussion about the documentation project.
Posts: 9947
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Index page of tutorial / teaching / pedagogical topics (draft articles for documentation)

Postby fxm » May 13, 2018 13:09

Getting Started and Basics with FreeBASIC

Starting with the FBeginner Book (PDF format below) is still a good way to learn FreeBASIC. Some topics in the book are probably deprecated by now or even missing, but it maybe worth reading for anyway.

  • Freebasic Beginners Guide (FBeginner.pdf file)
      Preamble: FBeginner is a concise, hands-on beginner's guide to FreeBasic and is aimed at the novice programmer. The book assumes no prior programming knowledge.....
      Note: This book does not take into account the changes and functionalities developed after the FreeBASIC version 0.17 released.

Indexes of Advanced Articles from Documentation Forum

The list below provides links to all the tutorial / teaching / pedagogical topics that have been grouped in the Documentation forum.
These such topics were developed for the most part from topics already existing in all forums by rewording and complementing, in order to create draft articles for documentation.

  1. How to Manage a Critical Section of the code of a Thread in FB (article of 11 posts)
      Preamble: A critical section is a part of a multi-threading program that may not be concurrently executed by more than one of the program threads (it's a piece of a program that requires mutual exclusion of access).
      Typically, the critical section accesses a shared resource, such as a data structure, a peripheral device, or a network connection, that does not allow multiple concurrent accesses.....
  2. How to Overload the Operator '->' (ptr to member access) and Build a Smart Pointer in FB (article of 1 post)
      Preamble: The operator '->' (pointer to member access) is used to access any member of an object (instance) via a pointer to this instance (under normal circumstances, the left operand of this operator must be a pointer to an object instance).
      Overloading of this operator allows you to create a pointer wrapper class and let it behave like the pointer itself.....
  3. How to Solve the Flickering Issue when Refreshing a Window in FB Graphics Mode (article of 1 post)
      Preamble: Refreshing (redrawing without precaution) a window in graphics mode can result in annoying flickering (this is due to the display of unwanted intermediate images picked up during the user refreshing phase).
      The phenomenon is obviously intensified if the entire window is first erased before being completely updated, and this repeatedly.....
  4. How to Use 'On [Local] Error Goto' statement in FB (article of 1 post)
      Preamble: 'On [Local] Error Goto label' causes a program jump to a specified label as soon as an error occurs. Such errors can be triggered by built-in statements such as 'Open', 'Get', 'Put', or when the 'Error' statement is used.
      The error checking for built-in statements is only enabled if the program is compiled with one of the '-e', '-ex' or '-exx' options. Otherwise, no jump will be performed, but the command will still consume processor time.....
  5. How to Debug Macro at Compile Time in FB (article of 1 post)
      Preamble: Macros offer a powerful way to extend the language and create reusable code. One reason macros are used is performance.
      They are a way of eliminating procedure call overhead because they are always expanded in-line. There is no alternative for this in FreeBASIC because it does not support inline procedures.
      Using macros can be extremely unsafe and they hide a lot of pitfalls which are very hard to find.....
  6. How to Use the Lbound / Ubound Size information of Array in FB (article of 1 post)
      Preamble: LBound / UBound returns the lower / upper values of size information for an array: the dimension of the array (number of usable indexes) and the index bounds for each dimension. The array name is specified in the first parameter, and the dimension selection in the second parameter.
      These sizing information are available both for a fixed-length array (sizing fixed at compile-time) and for a variable-length array (bounds sizing adjustable during run-time).....
  7. How to Use some Implicit Conversion for getting compatibility from Zstring to Ubyte in FB (article of 1 post)
      Preamble: Since the introduction of the Zstring type in FreeBASIC by v1ctor (through already fbc version 0.13 beta in April 2005!), this compatibility from Zstring to Ubyte exists (if using particular syntax recalled a little from time to time).
      Some people may have used it consciously. No doubt more people did so by inattention, not realizing that they were in principle making an invalid and forbidden assignment, but luckily corrected under the hood by an implicit conversion rule of compiler that was unknown to them.....
  8. How to Manage Dynamic Memory (Allocation / Deallocation) in FB (article of 1 post)
      Preamble: FreeBASIC supports three basic types of memory allocation:
      - Static allocation occurs for static/global variables. Memory is allocated once when the program runs and persists throughout the life of program.
      - Stack allocation occurs for procedure parameters and local variables. Memory is allocated when the corresponding block is entered, and released when the block is left, as many times as necessary.
      - Dynamic allocation is the subject of this article.....
  9. How and Why to Define Constructors, Assignment-Operators, and Destructor, for UDTs in FB (article of 1 post)
      Preamble: Some member procedures, which have a predefined name in the Type, have a specific role that is constructing, assigning, and destroying objects. These are the constructors, the assignment-operators, and the destructor.
      Of these, some are special because a version will be automatically built by the compiler if they are needed and not explicitly defined by the user. These are the default-constructor, the copy-constructor, the copy-assignment operator, and the destructor.
      This article takes into account Type inheritance and virtuality.....
  10. How to properly Use Dynamic (variable-length) Arrays in FB UDTs (article of 1 post)
      Preamble: When declaring a dynamic (variable-length) array member in a Type, 'Any' must be always specified in place of the array bounds in order to create a dynamic array with a certain amount of dimensions that is determined based on the number of 'Any' specified.
      In FreeBASIC, Type data structures must ultimately be fixed-size, such that compiler knows how much memory to allocate for objects of that Type.
      Nevertheless, a Type may contain dynamic (variable-length) field members: strings and even arrays.....
  11. How to Manage FB Reusable Procedures by Including Source Modules (vs. compiled modules) (article of 1 post)
      Preamble: When old OSs (like DOS) were used, compiling by separate modules was mandatory as soon as the program was not very short, because of the small memory size available for the compiler (about 200 KB with Quick Basic 4.5).
      Now, with modern PC and OS, this compilation limit is pushed back by a factor of about 10000, and the compile time of a large file in one go has become acceptable especially with FreeBASIC.
      This allows to use another method (than a library of compiled files) to manage the reusable user procedures. One other reason with FreeBASIC (as many other languages) is it does not support multiple inheritance.....
  12. How to properly Choose between Composition, Aggregation, and Inheritance, for UDTs in FB (article of 1 post)
      Preamble: Complex type structures can be built through composition, aggregation, and inheritance.
      Composition or aggregation (specialized form of association) is the process of creating more complex types from simple ones, while inheritance is the process of creating more complex type by acquiring the attributes and behaviors of existing ones.
      There is a very famous design principle which says “Favor composition over inheritance“, or also "Don’t use inheritance just to get code reuse". One other reason to favor composition with FreeBASIC (as with many other languages) is it does not support multiple inheritance.....

  13. How and Why to make Abstraction by Object Encapsulation, with FB Syntax in UDTs (basics) (article of 1 post)
      Preamble: Abstraction is a way of expressing a task without showing the underlying implementation details. For example, adding two vectors is the two-by-two addition of each of its components. Its abstraction is the overload of the + operator for the vector Type/Class.
      Encapsulation is a way of facilitating abstraction. A Type/Class is forced to hide its internal elements (in the private part of the Type/Class) so that a user of the Type/Class is forced to go through the abstractions that have been defined (the public part of the Type/Class) to use it.....

  14. How and Why to make Abstraction by Subtype Polymorphism, with FB Syntax in UDTs (advanced) (article of 1 post)
      Preamble: Subtype polymorphism is the concept of providing a single interface to entities that can have different types (abstraction). More precisely, a same interface is implemented by a member routine having the same identifier in each type belonging to the same inheritance hierarchy.
      Thanks to the abstract/virtual procedures, one can write a code using only the base type that will automatically call the derived type procedures.
      By using the same procedure name for several different types, the polymorphism allows a much more generic programming (abstraction). The coder does not have to know, when calling a base procedure, the precise type of object on which the procedure will apply. He just needs to know that this type will implement the procedure.....
  15. Why, When and How to Declare / Implement Constructors, Destructor, ..., for UDTs in FB (advanced) (article of 1 post)
      Preamble: The default constructor and the destructor are two special member procedures that are called to the creation and the destruction of an object.
      Any type has an implicit default constructor and an implicit destructor provided by the compiler if they are needed and not overloaded by user.
      These constructors and destructors call the default constructors and destructors of the base types and type member data, but apart from that, they may eventually do nothing else.
      It is therefore often necessary that user defines an explicit default constructor and an explicit destructor, in order to execute actions that must take place during the creation of an object and their destruction.....
  16. How FB supports References (pass and return byref, byref variables), and How to Use them (article of 1 post)
      Preamble: References and pointers are closely related. Indeed, a variable and its different references have the same address, since they allow access to the same object.
      In FB, a reference is implemented under the hood through an internal pointer which holds the address of the variable.
      The reference encapsulates the manipulation of the address of the variable and is used as a dereferenced pointer. The difference lies here in the fact that one does not have to perform the dereferencing.
      References are much easier to handle than pointers, so they make code much safer.....
  17. How to Replace Any Recursion with Simple Iteration or Unlimited Iteration with its Own Stack, in FB (article of 1 post)
      Preamble: Iteration and recursion are two very useful ways to program, especially to perform a certain number of times a certain script, and thus allow optimization of the code. If iteration is relatively easy to understand, recursion is a concept not necessarily obvious at the beginning.
      When speaking of a recursive procedure (sub or function), we refer to a syntactic characteristic: the procedure, in its own definition, refers to itself (it calls itself).
      But when talking about recursive process, linear or tree, we are interested in the process flow, not in the syntax of the procedure's writing.
      Thus, a procedure can have a recursive definition but correspond to an iterative process.....
  18. How FB supports Sub-Type Polymorphism, demonstrated by Emulation very Close to Real Operating (article of 1 post)
      Preamble: The ability to redefine a method in a derived-type (sub-type) inheriting from a base-type (super-type) is called specialization. It is then possible to call the method of an object without worrying about its intrinsic type: it is the inheritance polymorphism (sub-type polymorphism).
      This makes it possible to abstract the details of the specialized types of an object family, by masking them by a common interface which is the base-type.
      For example a method 'moving()' will perform the appropriate movement according to the real derived-type of the instance referenced at the time of the call. This will allow the program to say 'instance.moving()' without having to worry about the real derived-type of 'instance'.....
  19. How using RTTI from FB built-in OBJECT to extract Typename and those of all Bases of an instance (article of 1 post)
      Preamble: The Object built-in type provides the RTTI capacity for all types derived from it using the Extends declaration. The RTTI capacity allows to determine the real type of an object at runtime, which can be different of its at compile-time.
      The operator Is (Run-Time Type Information) uses it to check if an object is compatible to a type derived from its compile-time type, because RTTI provides not only the runtime typename of the object but also all typenames of its base types, up to the Object built-in type.
      The stored typenames by RTTI are mangled names. Some C++ implementations produce a human-readable typename. Others, most notably gcc, return the mangled name (convertible to human-readable form using implementation-specific API). But FreeBASIC returns nothing.
      The aim of this article is to provide a description of the RTTI structure, and to propose user procedures to extract the typenames (mangled and also demangled).....
Last edited by fxm on May 20, 2019 20:18, edited 28 times in total.
Posts: 9947
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Index page of tutorial / teaching / pedagogical topics (draft articles for documentation)

Postby fxm » Jul 22, 2020 8:39

Remaining articles or parts of articles from the above post not integrated in the Programmer's Guide (or elsewhere in the Wiki)
Articles or parts of articles from the above post already integrated in the Programmer's Guide and where precisely

Return to “Documentation”

Who is online

Users browsing this forum: No registered users and 1 guest