Why the Global Functions in modules

BlitzMax Forums/BlitzMax Programming/Why the Global Functions in modules

burpy(Posted 2011) [#1]
Hi all,
Given the general desire to keep things nicely encapsulated and data-hidden etc, what is the reason for the extensive use of helper functions like ListAddLast(list, object), rather than using list.AddLast(object)? Im sure there is a good reason, otherwise they wouldnt be there, I am just curious to know what it is..
Many thanks.
Marc (burpy)


H&K(Posted 2011) [#2]
Its so procedural programmers can use Bmax out of the Box without learning to be object programmers.


ziggy(Posted 2011) [#3]
Keep in mind that lots of early BlitzMax coders came from Blitz3D, wich is a procedural language so, in order to facilitate the transition, Max was provided with a procedural interface for its APIs


Czar Flavius(Posted 2011) [#4]
I think it is a very nice solution. Rather than C++ which is half-oo half not, BlitzMax lets you reside purely in one or the other as you please.


ImaginaryHuman(Posted 2011) [#5]
And it's easier and faster to write and remember.


Htbaa(Posted 2011) [#6]
Czar Flavius: How is C++ "half-oo half not"? OOP is much more advanced in C++ than it is in BlitzMax. Also, you could still program in a procedural style in C++.


H&K(Posted 2011) [#7]
@Htbaa, hes not claiming that it isnt possible to program c++ in a procedural way. The point hes making, to use c++ out of the box, half of the libs/mods are procedural front ends and half are oo front ends.


Czar Flavius(Posted 2011) [#8]
Htbaa, how do you convert std::string to uppercase?


Htbaa(Posted 2011) [#9]
I really didn't know (or rather remember it) so I looked it up: std::toupper()

At least it's namespaced...


Czar Flavius(Posted 2011) [#10]
It gets worse, that only converts a single character. You have to do this

void stoupper(std::string& s)
	{
	  std::string::iterator i = s.begin();
	  std::string::iterator end = s.end();
	 
	  while (i != end) {
	    *i = std::toupper((unsigned char)*i);
	    ++i;
	  }
	}


Source: http://www.dreamincode.net/forums/topic/15095-convert-string-to-uppercase-in-c/

Last edited 2011


Htbaa(Posted 2011) [#11]
Good grief am I glad I've left C++ behind me 3 years ago!

Why in the world wouldn't they simply include that function (or method!) to begin with? Because of possible unicode issues? Other languages have solved this problems ages ago...


Czar Flavius(Posted 2011) [#12]
String is an OOP wrapper of a char buffer, but advanced manipulations use the algorithm-oriented parts of the language. It's not that one way is better than the other, just that it is inconsistant. They could have added a method to string to do this for you, but I guess they decided not to because you could use the iterators already. We wouldn't like it to be too easy, would we? ;)


burpy(Posted 2011) [#13]
Thanks for the info guys - I figured similar. So there is no functional reason to not do things like access lists directly (list.addlast), etc..... No input checking ever or anything like that?
Marc


Czar Flavius(Posted 2011) [#14]
There is no difference. It is purely style. Use whichever you feel most comfortable with.

What input checking do you need? You can always make your own functions to check input and call them.

Last edited 2011