Monday 25 July 2011

Legacy types, type baggage, and CamelCase

I've been thinking about clearly separating some functionality out into a standard Legacy namespace. For example, function pointers. I already had plans to Standardise a small JIT functionality, and this will give me the opportunity that I need. I want to make it very clear that function pointers should not be used for regular code anymore.

func(float, float) -> int {
    return 1;
}
std.functional.function(int(float, float)) my_func(func);
std.legacy.function_jit("cdecl", int(float, float)) my_func_jit(my_func);
std.legacy.function_pointer("cdecl", int(float, float)) my_func_ptr = my_func_jit; // implicit cast


Other things I'm expecting to put in the legacy namespace will be tools for dealing with C-strings, for example, as well as (maybe?) things like error codes. Perhaps instead of legacy, it should be interop, and I'll add things for dealing with things like BSTRs, other string encodings, that kind of thing.

Another thing I've been thinking about is type baggage. For example, if you look at a C++ type, then they don't just have member functions and member variables (and static variables)- they also have typedefs and constants, which I am terming compile-time baggage. Now, in "DeadMG++", the simplest way to do this would be to just pack the baggage into a struct. However, of course, a struct is not a type and cannot be used to declare types, which would be somewhat problematic. Fortunately, casts are here to the rescue. Effectively, this would be given the same treatment as bool- language constructs which expect a type, such as variable definitions, would explicitly cast the result of any expression to 'type'. Of course, users might find that an implicit or even automatic cast would be the right thing to do, but that's none of my business.

More, I've been thinking about naming conventions. I always have a naming convention problem. I suck up the naming convention of code I'm using like a vacuum cleaner, which makes my code a bit rough when I'm dealing with std::vector<T>::push_back() and ReadFile in the same code. That's why I've decided that "DeadMG++" will use the Windows API conventions- which are also followed by C# and (close to) Java. That is, I will likely use things like Standard.Legacy.FunctionPointer, as opposed to std.legacy.function_ptr. Oh, and I also decided to use the dot notation for namespaces- they're objects like everything else, right?

The simple fact is that now that using definitions are not broken, then you can effectively re-name it however you like, and it also makes using verbose names much less of a big deal. You can see this in C#- who complains about System.Collections.Generic.Dictionary? Nobody, because everybody just does using namespace System; using namespace Collections; using namespace Generic;.

No comments:

Post a Comment