Hello.
I was reading some stuff in a C++ source file and I also use it in PHP too, but not sure how to convert it to Aurora. Here is the code in question...
return (Link==NULL || Link->Anchor)? NULL : Link;
Lewis
That is a ternary operator which is a shorthand IF statment. It translates to:
if(Link==NULL || Link->Anchor)
return NULL
else
return Link;
Ok, thanks a lot Paul.
Lewis
That's one of the things that is probably best left out of Aurora. While it's convenient, you can create some incredibly unreadable code with it and probably one of the most abused expressions in the C/C++ language.
I heavily agree, please leave ternary operators out.
I can't count the number of translations I have done where they threw me off.
I never had problems with the ternary operator usage but it was usually in the form of the inline IF command in Clipper language, which was more readable than the C++ version. It's not the ternary operator that's bad but the way it tis written in certain languages.
RETURN IIF(Link==NULL OR Link->Anchor, NULL, Link)
Barney
Quote from: Mike Stefanik on December 17, 2006, 12:48:34 PM
That's one of the things that is probably best left out of Aurora. While it's convenient, you can create some incredibly unreadable code with it and probably one of the most abused expressions in the C/C++ language.
I like conditional expressions and IMHO they are extremely simple to understand and they can make code alot cleaner. :)
Yeah, sure. Until you see someone write something like this:
if ((a > 0 ? x = ((b !=c && d != e ? f-- : f++) && (g < 1 ? q++ : q = 0)) : x = q--) != 0)
{
....
}
That's not what I would exactly call "extremely simple to understand".
Edit: And before someone says that no one would actually write code that looks that bad, you would be wrong. When I used to do UNIX systems programming, I saw a lot of programs written that used constructs even more convoluted than that, complete with zero comments and variable names that were 1-2 characters all over the place.
Yeah mike I think I agree there. At least if it is done with IF statements you can see it indented, so it is a lot easier to read. Thats just silly, I don't know why anyone would want to do that other than perhaps in a macro, so its all on one line.
Lewis
Ok I've now got some more stuff to convert :D
What do I do if a function returns a C++ class ??? Its not a .Net one or anything, just standard win32.
Lewis
Quote from: Barney on December 18, 2006, 01:47:26 AM
I never had problems with the ternary operator usage but it was usually in the form of the inline IF command in Clipper language, which was more readable than the C++ version. It's not the ternary operator that's bad but the way it tis written in certain languages.
RETURN IIF(Link==NULL OR Link->Anchor, NULL, Link)
Barney
I often put an IIF function for strings in my programs. It helps formatting.
sub main()
{
OpenConsole();
print("The answer is " + IIF(true,ÂÃ, "True", "False") + ".");
print("The answer is " + IIF(false, "True", "False") + ".");
while GetKey()=="";
CloseConsole();
}
sub IIF(int bCondition, string sTrueString, string sFalseString), string
{
ÂÃ, Ã‚Ã, if(bCondition == true)
{
return sTrueString;
}
ÂÃ, Ã‚Ã, else
{
return sFalseString;
}
}
I first saw IIF() in a spreadsheet. I don't find this particular construction hard to read (although you could nest it enough to be so if you wantedÂÃ, ;) ).
Quote from: Zen on December 18, 2006, 04:03:29 AM
Ok I've now got some more stuff to convert :D
What do I do if a function returns a C++ class ??? Its not a .Net one or anything, just standard win32.
Lewis
Is it a class, or a pointer to a class? win32 has nothing to do with it.
The function returns a pointer to a class. I have the C++ class declarations for the class it points to.
Lewis
Then conversion should be easy.
sub myfunction(),cmyclass *
{
cmyclass *pRet = NEW(cmyclass,1);
return pRet;
}
Ohh so all i need to do is convert the class definition to aurora and it should work? I didnt mean i need to return a pointer to a class. In the dll i am using there is a function that returns a c++ class.
Lewis
If it's a DLL then it would be a pointer to a class the DLL is returning. I can't guarantee that will work for you in Aurora. Depends on the complexity of the class being returned. Our vtable follows the same format as C++ generally.
Paul.
Ok thanks Paul.
I will give it a go anyway.
Lewis