Re: How can I convert Hexadecimal to RGB Color and vice-versa?
// Função hex2rgb() uint hex2rgb(string hexcolor) nothrow { try { uint value; hexcolor.stripLeft("#").formattedRead!"%x"(value); return value; } catch(Throwable){return 0;} } // Função rgb2hex() string rgb2hex(uint rgbcolor) nothrow { try { return "#%s".format(toHex(cast(const(BigInt)) rgbcolor)); } catch(Throwable){return "";} }
Re: rgba.ptr[0] vs rgba[0]
On Monday, 23 November 2020 at 17:39:09 UTC, Adam D. Ruppe wrote: On Monday, 23 November 2020 at 17:34:27 UTC, visitor wrote: Hi all, I would like to know why in the code below, rgba.ptr[0] is used instead of rgba[0] and allowing the method to be @safe The .ptr[0] skips bounds checking. Since this example is static length with a constant index it shouldn't matter anyway; the compiler can see it is obviously in bounds and skip it too. But if there's any runtime value there's a bounds check with `foo[0]` and that can be surprisingly expensive in certain situations. So `foo.ptr[0]` skipping that can give a nice performance boost. Just without bounds checking the code is obviously trusting the programmer... hence @trusted is required instead of safe. indeed because of the the static length and constant index, it was puzzling me ... Thanks Adam for clarification
Re: rgba.ptr[0] vs rgba[0]
On Monday, 23 November 2020 at 17:34:27 UTC, visitor wrote: Hi all, I would like to know why in the code below, rgba.ptr[0] is used instead of rgba[0] and allowing the method to be @safe The .ptr[0] skips bounds checking. Since this example is static length with a constant index it shouldn't matter anyway; the compiler can see it is obviously in bounds and skip it too. But if there's any runtime value there's a bounds check with `foo[0]` and that can be surprisingly expensive in certain situations. So `foo.ptr[0]` skipping that can give a nice performance boost. Just without bounds checking the code is obviously trusting the programmer... hence @trusted is required instead of safe.
Re: Reflection on the book D web development.
On Saturday, 21 November 2020 at 16:18:39 UTC, Alaindevos wrote: It's not my related to a lack of knowledge of the d-language but the complexity of the vibe.d framework itself. What I understand are : 1: jade/diet .dt templates, inheritance,includes,markdown. 2: A simple form with POST method. Then it stops. What I find too complex: - Sessions, session data , session variables - Handler functions and delegates, compile-time reflection, prefixes, annotation. - Authentication - Validating user input This can be improved by improving documentation in very small steps. As comparison here a tutorial of ruby-flask which uses only small steps so everything can easily and completely be understood. Something like that for vibe.d would be very interesting. https://www.youtube.com/watch?v=3mwFC4SHY-Y May or may not be related, but I eventually gave up on that book myself. It felt as if it were written for experienced web developers wanting to use D for things they were doing in other languages. It's been a long time now, though, so I don't recall anything specific.
rgba.ptr[0] vs rgba[0]
Hi all, I would like to know why in the code below, rgba.ptr[0] is used instead of rgba[0] and allowing the method to be @safe float[4] rgba = 0; ref inout(float) r() inout pure @trusted { pragma(inline, true); return rgba.ptr[0]; } why not : ref inout(float) r() inout pure @safe { pragma(inline, true); return rgba[0]; } avoid an allocation maybe ? Thanks for your time.