`with` across function calls
Nicholas Wilson
iamthewilsonator at hotmail.com
Sun Jan 20 00:12:59 UTC 2019
On Saturday, 19 January 2019 at 22:55:49 UTC, luckoverthere wrote:
> That's pretty awful too, let's not propagate that any further
> with with. But not really what I mean, at the very least with
> that default value you know that function access a global for
> some reason, and should probably be avoided.
Globals are bad, yes, conceptually every function that takes a
global does that except you can't ever specify something
different in place of the global. This is trying to get rid of
them.
> Lol I can only imagine this, does anyone actually even grep.
Thats not the point. If it works for grep, it will work for ^f,
it will work for an intelligent editor etc.
> Yes you have with in scope, but that's it. You'd have to look
> through every function in that with scope to see which
> functions are affected by it. In the event something is wrong.
And the situation is _far worse_ with a global. Thats why they
are considered to be so bad. At least in this case there is one
specific type you are interested, also `-vcg-ast` will tell you
exactly what the code does. So will debug info.
> It is NOT _exactly_ the same,
That was w.r.t. the mechanism (which it is), not the effect on
readability, which, while not perfect by any means, is far better
than using globals, which is the only other way to do it.
> This is honestly why I don't use with() basically at all. And
> neither does anyone else really. It just makes logic harder to
> reason about.
Again the baseline for comparison is globals, which are worse.
> Yikes, I wouldn't be celebrating making that a single call.
> Especially since you are effectively passing 3 different sets
> of arguments in one line of code. That's not something to be
> celebrating.
For reference, CUDA does this as:
kernel<templateargs><<<shape,args, queue>>>(parameters, of,
kernel);
and is IMO the sole reason it is soooo much more popular than
OpenCL (and therefore a significant part of the reason Nvidia is
valued so much higher). I modelled the DCompute call off that.
Both are completely type safe, but CUDA does the magic behind the
scenes in the compiler whereas I do it in the library. Now not
all kernels are templated, so most of the time that will be just
two.
The reason to not go yikes at it is because that is a single
logical operation (launch me this function with these
configuration parameters on this queue, and these function
parameters). The fact that it is a while load of calls is
irrelevant to the user: what they want is to launch a kernel.
More information about the Digitalmars-d
mailing list