Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-27 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Wednesday, 27 August 2014 at 05:45:34 UTC, eles wrote: While this may be true in this case, I think that, in general, you cannot draw such a clear line between what's recoverable and what's not. If you really want to push things to the extreme, the sole unrecoverable error shall be

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-27 Thread Mike Parker via Digitalmars-d-learn
On 8/27/2014 2:39 PM, Vladimir Panteleev wrote: On Monday, 25 August 2014 at 03:19:09 UTC, Mike Parker wrote: I use Exception for recoverable errors and Error for those that aren't. Sorry, you're right, that description of Exception/Error is correct. But I don't think that SDL initialization

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-26 Thread Vladimir Panteleev via Digitalmars-d-learn
On Monday, 25 August 2014 at 03:19:09 UTC, Mike Parker wrote: I use Exception for recoverable errors and Error for those that aren't. Sorry, you're right, that description of Exception/Error is correct. But I don't think that SDL initialization is a non-recoverable error. The program might

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-26 Thread eles via Digitalmars-d-learn
On Wednesday, 27 August 2014 at 05:45:34 UTC, eles wrote: On Wednesday, 27 August 2014 at 05:39:59 UTC, Vladimir Panteleev wrote: On Monday, 25 August 2014 at 03:19:09 UTC, Mike Parker wrote: failure and the SIGKILL. (and SIGKILL just because you cannot catch it, otherwise you could

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-26 Thread eles via Digitalmars-d-learn
On Wednesday, 27 August 2014 at 05:39:59 UTC, Vladimir Panteleev wrote: On Monday, 25 August 2014 at 03:19:09 UTC, Mike Parker wrote: Sorry, you're right, that description of Exception/Error is correct. But I don't think that SDL initialization is a non-recoverable error. The program might

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-24 Thread Mike Parker via Digitalmars-d-learn
On 8/23/2014 7:19 PM, nikki wrote: How would you write it? ``` // Put this somewhere you can import it into any module calling SDL class SDLError : Error { public this( string msg, string file = __FILE__, size_t line = __LINE__ ) { import std.string; import std.conv;

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-24 Thread Vladimir Panteleev via Digitalmars-d-learn
On Monday, 25 August 2014 at 02:17:47 UTC, Mike Parker wrote: // Put this somewhere you can import it into any module calling Small modification for even terser error handling: T sdlEnforce(T)(T result, string message = null) { if (!result) throw new SdlException(SDL error: ~

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-24 Thread Mike Parker via Digitalmars-d-learn
On 8/25/2014 11:35 AM, Vladimir Panteleev wrote: On Monday, 25 August 2014 at 02:17:47 UTC, Mike Parker wrote: // Put this somewhere you can import it into any module calling Small modification for even terser error handling: T sdlEnforce(T)(T result, string message = null) { if (!result)

'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread nikki via Digitalmars-d-learn
I am learning SDL by following the lazyfoo SDL2 tuorials, I am alos new to D so I have a question: I the lazyfoo tutorials there are many functions that have a bool success whiich gets set at various places when something goes wrong to be returned afterwards.

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread ketmar via Digitalmars-d-learn
On Sat, 23 Aug 2014 10:19:58 + nikki via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: don't use '==' to check for nulls. the right way is: if (foo is null) {} if (bar !is null) {} '==' transforms to opEquals call (see 'operator overloading') and 'is' not. as for 'best

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread nikki via Digitalmars-d-learn
Oops well writing the above post made me realise what to look for : http://dlang.org/errors.html ;)

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread nikki via Digitalmars-d-learn
On Saturday, 23 August 2014 at 10:29:04 UTC, ketmar via Digitalmars-d-learn wrote: On Sat, 23 Aug 2014 10:19:58 + nikki via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: don't use '==' to check for nulls. the right way is: if (foo is null) {} if (bar !is null) {} '=='

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread bearophile via Digitalmars-d-learn
nikki: How would you write it? I don't know how much idiomatic this is, but you can start cleaning up the code: - Renaming the function with something more clear; - using a D enumeration for the various constants. - I have used a . before the module-level variables to denote better they

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread bearophile via Digitalmars-d-learn
ketmar: don't use '==' to check for nulls. the right way is: if (foo is null) {} if (bar !is null) {} '==' transforms to opEquals call (see 'operator overloading') and 'is' not. I use is and !is for class references and == != for pointers. But now I think you are right, and in D it's

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread ketmar via Digitalmars-d-learn
On Sat, 23 Aug 2014 10:53:03 + bearophile via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: I use is and !is for class references and == != for pointers. But now I think you are right, and in D it's better to always use is and !is for both, to avoid present and future bugs

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread hane via Digitalmars-d-learn
On Saturday, 23 August 2014 at 10:19:59 UTC, nikki wrote: I am learning SDL by following the lazyfoo SDL2 tuorials, I am alos new to D so I have a question: I the lazyfoo tutorials there are many functions that have a bool success whiich gets set at various places when something goes wrong

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread monarch_dodra via Digitalmars-d-learn
On Saturday, 23 August 2014 at 10:33:02 UTC, nikki wrote: A good to know! thanks. I'd still be interrested to see the idiomatic D version of that function, what would that depend on ? Honestly, I wouldn't change it much. If it didn't throw exceptions before, then it probably would have

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread Kagamin via Digitalmars-d-learn
On Saturday, 23 August 2014 at 11:07:23 UTC, ketmar via Digitalmars-d-learn wrote: and foo is null is nice to read. ;-) Meh, looks like a guest from pascal or basic.

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread ketmar via Digitalmars-d-learn
On Sat, 23 Aug 2014 15:10:22 + Kagamin via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Meh, looks like a guest from pascal or basic. so let's replace writeln() with %^#$#%^ then. this looks like a function name for Real Hackers. signature.asc Description: PGP signature

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread Kagamin via Digitalmars-d-learn
On Saturday, 23 August 2014 at 11:07:23 UTC, ketmar via Digitalmars-d-learn wrote: and foo is null is nice to read. ;-) function bool init begin rem Initialization flag bool success assign true; rem Initialize SDL if execute SDL_Init SDL_INIT_VIDEO lt 0 begin