MQL equivalent to Python's None type? - page 6

 
Amir Yacoby:
We talked about it already and I said it clearly. You also acknoledged it. Then you come back to it, among other wrong ideas that it should be public or I must clutter etc. Well no, it shouldnt be public and for me its the better solution. Anyway, our stands are clear as I said, let the people choose. Thats it, its your thread but I think there are many people that will agree with me also so I wrote here. Have a good day.

What did I acknowledge?


I asked you a pertinent question that you never answered... Would you also propose that the global constants, such as DBL_MAX, also be removed from the global scope and inserted as protected members of CObject and only accessible to its descendants? 

 
nicholi shen:

What did I acknowledge?


I asked you a pertinent question that you never answered... Would you also propose that the global constants, such as DBL_MAX, also be removed from the global scope and inserted as protected members of CObject and only accessible to its descendants? 

Acknowledged that I only target class scope. 
As for the question, if None was a part of global mql5 that was ideal because MQL5 is for both oo and procedural. But trying to force it with static classes for me is not worth. I still say you can do it, its matter of style and prefernce, dont feel discouraged just because someone does differently. Enough for today.
 
Amir Yacoby:
Acknowledged that I only target class scope. 
As for the question, if None was a part of global mql5 that was ideal because MQL5 is for both oo and procedural. But trying to force it with static classes for me is not worth. I still say you can do it, its matter of style and prefernce, dont feel discouraged just because someone does differently. Enough for today.

So just to confirm I understand you. You are okay with everything except using a class like a c++ namespace?

 
nicholi shen:

So just to confirm I understand you. You are okay with everything except using a class like a c++ namespace?

To be honest, I find drawbacks in both implementations. I can argue for both. 
I can see your point as well. And static methods without state, should be ok (psychologically I don't like it though).

Also, they don't quite make it as part of a CObject, because they are stateless and not belong to particular object, which makes it somewhat duplicated. 
I though also of making it static methods in CObject, which seems slightly more correct, and would also allow for the scope to be global, which will allow to call CObject::None(typename) from all over, but then it would also make sense to move them away to a different class as you did.

And it does appeal to have it from any scope. So, I am not against your idea at all.  
 
Amir Yacoby:
To be honest, I find drawbacks in both implementations. I can argue for both. 
I can see your point as well. And static methods without state, should be ok (psychologically I don't like it though).

Also, they don't quite make it as part of a CObject, because they are stateless and not belong to particular object, which makes it somewhat duplicated. 
I though also of making it static methods in CObject, which seems slightly more correct, and would also allow for the scope to be global, which will allow to call CObject::None(typename) from all over, but then it would also make sense to move them away to a different class as you did.

And it does appeal to have it from any scope. So, I am not against your idea at all.  

I'm glad that we're on the same page. 😃

Regarding it's implementation in CObject, however, I think the only way it would work without breaking a lot of classes out there is if/when MQ ever implements multiple inheritance. 

class MyNewClass : public CObject, public NoneMixin;

Otherwise, it would wreck the current ecosystem we have with only single inheritance. 

 
nicholi shen:

I'm glad that we're on the same page. 😃


Nothing changed though, I am not sure I will adopt this at all because static methods still are not good in my view. And maybe the CObject is the least price altgether. Will give it a second thought, maybe something will come up.
 
Amir Yacoby:
Nothing changed though, I am not sure I will adopt this at all because static methods still are not good in my view. And maybe the CObject is the least price altgether. Will give it a second thought, maybe something will come up.

In this context, there is no functional difference between static methods and globally defined functions other than namespace encapsulation. But if it pleases you to not use a class as a pseudo-namespace then perhaps this is the right version for you?


//+------------------------------------------------------------------+
//|                                                         none.mqh |
//|                                      Copyright 2018, nicholishen |
//|                                                    interwebs.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, nicholishen"
#property link      "interwebs.com"
#ifdef __MQL4__
#property strict
#endif 


double   __none(double _)     { return DBL_MAX;   }
int      __none(int _)        { return INT_MAX;   }
uint     __none(uint _)       { return UINT_MAX;  }
long     __none(long _)       { return LONG_MAX;  }
ulong    __none(ulong _)      { return ULONG_MAX; }
char     __none(char _)       { return CHAR_MAX;  }
uchar    __none(uchar _)      { return UCHAR_MAX; }
short    __none(short _)      { return SHORT_MAX; }
ushort   __none(ushort _)     { return USHORT_MAX;}
string   __none(string _)     { return "__NONE-*-*-STRING__";}
color    __none(color _)      { return clrNONE;   }
datetime __none(datetime _)   { return -1;        }
template<typename T>
T        __none(T _)          { return NULL;      }

#define NONE(T)  __none((T)NULL)

#define NONE_DOUBLE  DBL_MAX
#define NONE_INT     INT_MAX
#define NONE_UINT    UINT_MAX
#define NONE_LONG    LONG_MAX
#define NONE_ULONG   ULONG_MAX
#define NONE_CHAR    CHAR_MAX
#define NONE_UCHAR   UCHAR_MAX
#define NONE_SHORT   SHORT_MAX
#define NONE_USHORT  USHORT_MAX
#define NONE_COLOR   clrNONE
#define NONE_DATETIME -1
#define NONE_POINTER NULL
#define NONE_STRING  "__NONE-*-*-STRING__"
 
nicholi shen:

In this context, there is no functional difference between static methods and globally defined functions other than namespace encapsulation. But if it pleases you to not use a class as a pseudo-namespace then perhaps this is the right version for you?


Actually, it is enough to add those defines in CObject, and be done with it. The rest is overkill. 
And each time, instead of writing for instance NONE(double) - just write NONE_DOUBLE. 
Those defines are there to be used anyway, so why not settle with it?
#define NONE_DOUBLE  DBL_MAX
#define NONE_FLOAT   FLT_MAX
#define NONE_INT     INT_MAX
#define NONE_UINT    UINT_MAX
#define NONE_LONG    LONG_MAX
#define NONE_ULONG   ULONG_MAX
#define NONE_CHAR    CHAR_MAX
#define NONE_UCHAR   UCHAR_MAX
#define NONE_SHORT   SHORT_MAX
#define NONE_USHORT  USHORT_MAX
#define NONE_COLOR   clrNONE
#define NONE_DATETIME -1
#define NONE_POINTER NULL
#define NONE_STRING  "__NONE-*-*-STRING__"
 
bool IsNone( const double   &Value ) { return(Value == DBL_MAX); }
bool IsNone( const float    &Value ) { return(Value == FLT_MAX); }
bool IsNone( const int      &Value ) { return(Value == INT_MAX); }
bool IsNone( const uint     &Value ) { return(Value == UINT_MAX); }
bool IsNone( const long     &Value ) { return(Value == LONG_MAX); }
bool IsNone( const ulong    &Value ) { return(Value == ULONG_MAX); }
bool IsNone( const char     &Value ) { return(Value == CHAR_MAX); }
bool IsNone( const uchar    &Value ) { return(Value == UCHAR_MAX); }
bool IsNone( const short    &Value ) { return(Value == SHORT_MAX); }
bool IsNone( const ushort   &Value ) { return(Value == USHORT_MAX); }
bool IsNone( const color    &Value ) { return(Value == clrNONE); }
bool IsNone( const datetime &Value ) { return(Value == -1); }
bool IsNone( const string   &Value ) { return(Value == "__NONE-*-*-STRING__"); }

template <typename T>
bool IsNone( const T* const &Value ) { return(Value == NULL); }

template <typename T>
bool IsNone( const T &Value ) { return(false); }
 
fxsaber:
nice
Reason: