Why the Global Functions in modules
BlitzMax Forums/BlitzMax Programming/Why the Global Functions in modules
| ||
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) |
| ||
Its so procedural programmers can use Bmax out of the Box without learning to be object programmers. |
| ||
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 |
| ||
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. |
| ||
And it's easier and faster to write and remember. |
| ||
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++. |
| ||
@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. |
| ||
Htbaa, how do you convert std::string to uppercase? |
| ||
I really didn't know (or rather remember it) so I looked it up: std::toupper() At least it's namespaced... |
| ||
It gets worse, that only converts a single character. You have to do thisvoid 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 |
| ||
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... |
| ||
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? ;) |
| ||
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 |
| ||
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 |