Re: Deep nesting vs early returns
On Thursday, 4 October 2018 at 06:43:02 UTC, Gopan wrote: Certain people recommend that there be only one return statement (usually at the end) from a function. The said advantage is that, in a maintenance code, if you later want to do something before returning, you can add it just above the return statement. I have seen people enclosing the function logic inside a while(1) merely to stick on to single return at the end. while(1) { ... break; //otherwise return would come here. ... break; } return ...; In terms of code maintenance, multiple break statements have no difference from multiple return statements. Those people are just trying to deceive themselves.
Confusing TLS
Code: import std.stdio; import core.thread; import core.time; auto arr = new ubyte[1]; // THIS SHOULD NOT COMPILE int main(string[] args) { new Thread({ arr[0]++; }).start(); new Thread({ arr[0]++; }).start(); Thread.sleep(1.seconds); writefln("arr[0] = %s", arr[0]); return 0; } https://glot.io/snippets/ez54cl239e In fact, it works as it should. But this behavior confuses beginners. They expect each thread to work with its own copy of the TLS-array. I believe, such initialization of mutable TLS-variables should lead to a compilation error, as is done for classes: class Foo {} Foo foo = new Foo(); // doesn't compile
Re: How to extract the AA type?
auto foo(T: V[K], V, K)(T t) { CopyConstness!(T, V[K]) aa = t; return aa; } https://run.dlang.io/is/LSMa5C
Re: Temporary objects as function parameters or when-is-this-shit-going-to-end?
On Friday, 13 October 2017 at 10:55:24 UTC, rikki cattermole wrote: On 13/10/2017 11:40 AM, Jack Applegame wrote: Please create an issue for this Done. https://issues.dlang.org/show_bug.cgi?id=17897 To anybody else, the poster is willing to pay a token to have this fixed. [0] https://issues.dlang.org/buglist.cgi?quicksearch=postblit%20not%20called Not only this. There are many related bugs. For example posted by me: https://issues.dlang.org/show_bug.cgi?id=17128 https://issues.dlang.org/show_bug.cgi?id=17257
Temporary objects as function parameters or when-is-this-shit-going-to-end?
Sorry, I mistakenly placed my post in the wrong section. Consider, please: https://forum.dlang.org/thread/oxucajbsjbsuraqtn...@forum.dlang.org
Re: gdc is in
On Sunday, 8 October 2017 at 08:38:15 UTC, Iain Buclaw wrote: Donating for the upkeep of our infrastructure is also welcome. ;-) How to do this?
Re: LDC, ARM: unnecessary default initialization
On Friday, 18 August 2017 at 17:28:38 UTC, kinke wrote: On Friday, 18 August 2017 at 12:09:04 UTC, kinke wrote: On Friday, 18 August 2017 at 09:42:25 UTC, Jack Applegame wrote: For some reason, the LDC default initializes the structure, even if initialization of all its members is specified as void. I believe that this is wrong. Afaik, this has been brought up multiple times already and is so by design. Every aggregate has an init symbol, omitting that (and accordingly the default initialization of all instances) by initializing each field with void doesn't work. The initialization isn't performed fieldwise, but is a bitcopy of T.init. You can skip initialization of specific instances though - `S s = void;` - but again not if `s` is a field of another aggregate. Sorry, I forgot some workaround code: void ResetHandler() { Foo foo = void; foo.__ctor(10); // or: std.conv.emplace(&foo, 10); } Thanks for the answer. Also I found another workaround code: test.d module test; import core.bitop : volatileStore; struct Foo { uint[64] m = void; // no default initialization static auto opCall(uint a) { Foo foo = void; foreach(ref b; foo.m) volatileStore(&b,a++); return foo; } } void ResetHandler() { auto foo = Foo(10); } assembly <_D4test12ResetHandlerFZv>: 0: b0c0sub sp, #256; 0x100 2: 2000movsr0, #0 4: 4669mov r1, sp 6: f100 020a add.w r2, r0, #10 a: f841 2020 str.w r2, [r1, r0, lsl #2] e: 3001addsr0, #1 10: 2a49cmp r2, #73 ; 0x49 12: d1f8bne.n 6 <_D4test12ResetHandlerFZv+0x6> 14: b040add sp, #256; 0x100 16: 4770bx lr
LDC, ARM: unnecessary default initialization
I explore the possibility of using D for bare metal ARM programming. For some reason, the LDC default initializes the structure, even if initialization of all its members is specified as void. I believe that this is wrong. test.d module test; import core.bitop : volatileStore; struct Foo { uint[64] m = void; // no default initialization this(uint a) { foreach(ref b; m) volatileStore(&b,a++); } } void ResetHandler() { auto foo = Foo(10); } $ldc2 -mtriple=thumb-none-linux-eabi -mcpu=cortex-m3 -c --betterC --boundscheck=off -relocation-model=static -O3 -vcolumns test.d test.o assembly <_D4test12ResetHandlerFZv>: 0: b510push{r4, lr} 2: b0c0sub sp, #256; 0x100 -+ 4: 466cmov r4, sp | default initialization 6: f44f 7180 mov.w r1, #256; 0x100 | a: 4620mov r0, r4 | WHY??? c: f7ff fffe bl 0 <__aeabi_memclr4> -+ 10: 2000movsr0, #0 12: f100 010a add.w r1, r0, #10 16: f844 1020 str.w r1, [r4, r0, lsl #2] 1a: 3001addsr0, #1 1c: 2949cmp r1, #73 ; 0x49 1e: d1f8bne.n 12 <_D4test12ResetHandlerFZv+0x12> 20: b040add sp, #256; 0x100 22: bd10pop {r4, pc} *
Re: Move construction from !is(T == typeof(this))
On Tuesday, 25 April 2017 at 08:53:22 UTC, Stanislav Blinov wrote: On Tuesday, 25 April 2017 at 07:58:43 UTC, Jack Applegame wrote: On Monday, 24 April 2017 at 18:48:00 UTC, Stanislav Blinov wrote: Suddenly, we can't copy the pointer, or at least make a shallow copy of it, without violating const, and the latter is UB. Because transitive const/immutable is shit. And that shit had to introduce another shit - Rebindable. D const/immutable system is very big PITA. I hate it. Don't use it then. Life is so exciting when everything may change at any time. I can't. I need immutable pointers to mutable data and vica versa. D const system is better then nothing.
Re: Move construction from !is(T == typeof(this))
On Monday, 24 April 2017 at 18:48:00 UTC, Stanislav Blinov wrote: Suddenly, we can't copy the pointer, or at least make a shallow copy of it, without violating const, and the latter is UB. Because transitive const/immutable is shit. And that shit had to introduce another shit - Rebindable. D const/immutable system is very big PITA. I hate it.
Re: Something wrong with reflection inside struct destructor
On Tuesday, 14 March 2017 at 14:33:49 UTC, John Colvin wrote: bug report? https://issues.dlang.org/show_bug.cgi?id=17257
Re: Something wrong with reflection inside struct destructor
This is completely unacceptable: DPaste(https://dpaste.dzfl.pl/f54f578c4ec9) import std.stdio; import std.string; import std.experimental.allocator; import std.experimental.allocator.mallocator : Mallocator; struct Bar(E) { E* ptr = null; void allocate(int m) { ptr = Mallocator.instance.make!Foo(m); } ~this() { if(ptr !is null) Mallocator.instance.dispose(ptr); } } struct A { int m; ~this() { writefln("A.~this(%s)", m); } } struct Foo { A a; Bar!Foo bar; this(int m) { a = A(m); } } void main() { auto foo = Foo(1); foo.bar.allocate(10); } Output: A.~this(1) Expected output: A.~this(10) A.~this(1) Can someone to fix this ASAP for $100?
Re: Something wrong with reflection inside struct destructor
On Tuesday, 14 March 2017 at 12:44:16 UTC, Jack Applegame wrote: Workaround: Avoid reflection in the destructor. Do reflection in normal function and then call it from destructor. This doesn't work - https://dpaste.dzfl.pl/5a1d93f7a277 Call from destructor changes compiler behavior. This is terrible.
Something wrong with reflection inside struct destructor
I'm trying to write reference counted dynamic array and encountered a trouble with compile time reflection at recursive template instantiation. for dynamic arrays (and AA too) it is normal to use recursive declarations: struct S { S[] arr; } struct S { Array!S arr; } Look at this code: (DPaste - https://dpaste.dzfl.pl/2010191369fe) import std.string : format; struct Bar(E) { void fun() { pragma(msg, format("fun: Foo.__xdtor - %s", __traits(hasMember, E, "__xdtor"))); pragma(msg, format("fun: Bar.__xdtor - %s", __traits(hasMember, Bar, "__xdtor"))); pragma(msg, format("fun: Foo.__dtor - %s", __traits(hasMember, E, "__dtor"))); pragma(msg, format("fun: Bar.__dtor - %s", __traits(hasMember, Bar, "__dtor"))); } ~this() { pragma(msg, format("~this: Foo.__xdtor - %s", __traits(hasMember, E, "__xdtor"))); pragma(msg, format("~this: Bar.__xdtor - %s", __traits(hasMember, Bar, "__xdtor"))); pragma(msg, format("~this: Foo.__dtor - %s", __traits(hasMember, E, "__dtor"))); pragma(msg, format("~this: Bar.__dtor - %s", __traits(hasMember, Bar, "__dtor"))); } } struct Foo { Bar!Foo foo; ~this() {} } void main() {} Output: ~this: Foo.__dtor - true<--- Foo has __dtor, OK, ~this: Bar.__dtor - true ~this: Foo.__xdtor - false <--- but hasn't __xdtor. WAT??? ~this: Bar.__xdtor - true fun: Foo.__dtor - true fun: Bar.__dtor - true fun: Foo.__xdtor - true fun: Bar.__xdtor - true Global object.destroy(ref T) function detects destructor presence by __traits(hasMember, T, "__xdtor") (https://github.com/dlang/druntime/blob/v2.073.2/src/object.d#L2440) and does nothing in such cases. Workaround: Avoid reflection in the destructor. Do reflection in normal function and then call it from destructor. But it looks weird and should be fixed. Also see related topic: https://forum.dlang.org/thread/okbzqkjijuwvmvstj...@forum.dlang.org
Re: Bug or feature?
Sorry, right link - https://forum.dlang.org/thread/okbzqkjijuwvmvstj...@forum.dlang.org
Bug or feature?
https://forum.dlang.org/post/yjddbxzqzvmlvqrht...@forum.dlang.org
Re: Database of practicality will be an important factor for development of D language in the future
On Thursday, 2 February 2017 at 13:28:48 UTC, Shachar Shemesh wrote: On 02/02/17 14:50, Adam D. Ruppe wrote: On Thursday, 2 February 2017 at 05:33:57 UTC, FrankLike wrote: For example, I want to do the execution of stored procedure for MSSql、MySQL database. I found in Mysql-d, Mysql-Native, arsd, DDBC, etc. there is no result. db.query("CALL my_procedure(args...)"); Generally speaking, you really don't want to do that. Ever. This code is how SQL injection vulnerabilities are born. Arguments should ALWAYS be passed out of line of the actual call command, so that the server has no chance of confusing arguments and commands. Sadly, that typically requires a DB library specific to the DB in use. Shachar Do you really think that Adam does not know what is SQL-injection?
Re: It is still not possible to use D on debian/ubuntu
On Saturday, 14 January 2017 at 18:41:21 UTC, Russel Winder wrote: On Sat, 2017-01-14 at 17:28 +, Elronnd via Digitalmars-d wrote: On Friday, 13 January 2017 at 11:50:25 UTC, Russel Winder wrote: > LDC which is packaged by both Debian and Fedora is the > only practically usable D compiler on both these platforms. What's impractical about downloading and installing an rpm? For that matter, downloading the source and compiling it isn't all that impractical either. Downloading and installing an RPM outside of dnf. What do you mean "outside"? I use DMD on CentOS, and I installed it by command: yum install http://downloads.dlang.org/releases/2.x/2.072.2/dmd-2.072.2-0.fedora.x86_64.rpm From your point of view it is "outside" or "inside" of yum?
Re: Red Hat's issues in considering the D language
On Thursday, 22 December 2016 at 08:33:55 UTC, Daniel Kozák wrote: ? I am on fedora and I have dmd, so it is not true :P Dejan Lekic via Digitalmars-d napsal St, pro 21, 2016 v 6∶36 : On Wednesday, 21 December 2016 at 16:41:56 UTC, hardreset wrote: Moving the reference compiler to LLVM as was suggested in the list. LDC is the only compiler on Fedora/CentOS anyway! I am on CentOS and I have dmd too. :)
Re: How do we accelerate the development of precise GC, RC and so on?
So, who wants to do a good deed and make some money? We can create an issue and start fundraising on Bountysource. We can also donate to the D Language Foundation, but I personally would like to see the funds were used to develop precise GC and DIP74 (https://wiki.dlang.org/DIP74).
How do we accelerate the development of precise GC, RC and so on?
We look forward to sane GC over the years. How do we accelerate the development of precise GC, RC and so on? Maybe we should organize a fundraiser on Kickstarter or somewhere else? I'm not ready to write precise GC, but I'm willing to donate to those who are ready.
Challenge on Russian Stack Overflow
I found funny (from my point of view) challenge in Russian Stack Overflow. Any language accepted. You need to make the loop for (int x=0; x<3; ++x) {} endless. Rules: - you can't modify the loop's code itself; - you can't modify the loop's variable inside the body of loop; - you can't wrap the loop in an outer infinite loop or insert an infinite loop inside the body; For example, C++ solution: int main() { #define int bool for (int x=0; x<3; ++x); return 0; } This is my D solution - http://ru.stackoverflow.com/a/589748/218208 Solution with the highest rating wins.
D Language Foundation
Is there a way to donate to the D Language Foundation?
Re: How about a special null template parameter?
On Friday, 19 August 2016 at 18:25:06 UTC, Engine Machine wrote: It replaces the current method of having to define a non-templated class and a templated class. e.g., class Type { int x; } class Type(T) : Type { static if (T is Dog) int y; } What are you talking about? This code doesn't compile. Because you can't define a class and a template with the same name.
Re: Make D language as Apache foundation project
On Wednesday, 27 July 2016 at 15:44:21 UTC, Seb wrote: http://dlang.org/foundation.html Wow. This page details Andrei's full name: Tudor Andrei Cristian Alexandrescu. (o_O)
Re: I hate new DUB config format
On Thursday, 26 November 2015 at 09:41:38 UTC, ponce wrote: On Thursday, 26 November 2015 at 09:04:27 UTC, Ilya Yaroshenko wrote: Single language, json based configuration engine is simpler for IDE development and configuration tools. For example, Sublime Text.This is very important to make language used by big amount of users. Ilya Sublime Text configuration has no comments and this kind of sucks compared to eg. a webserver key-value configuration file, or sc.ini, so I'm not sure you chose the best example. Sublime Text configuration has a lot of comments: // Place your settings in the file "User/Preferences.sublime-settings", which // overrides the settings in here. // // Settings may also be placed in file type specific options files, for // example, in Packages/Python/Python.sublime-settings for python files. { // Sets the colors used within the text area "color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme", // Note that the font_face and font_size are overridden in the platform // specific settings file, for example, "Preferences (Linux).sublime-settings". // Because of this, setting them here will have no effect: you must set them // in your User File Preferences. "font_face": "", "font_size": 10, // Valid options are "no_bold", "no_italic", "no_antialias", "gray_antialias", // "subpixel_antialias", "no_round" (OS X only), "gdi" (Windows only) and // "directwrite" (Windows only) "font_options": [],
Re: opDispatch and compile time parameters
On Monday, 19 October 2015 at 17:50:02 UTC, Nikolay wrote: On Monday, 19 October 2015 at 08:41:46 UTC, Jack Applegame wrote: D template system is very powerful. This is more generic solution: http://dpaste.dzfl.pl/791c65d0e4ee Wow! I can't believe that it is possible and there is so straightforward way. You should post this answer to SO Thanks! Done
Re: opDispatch and compile time parameters
D template system is very powerful. This is more generic solution: import std.stdio; class B { auto p1(T)(T arg) { writeln( "p1: ", arg ); } auto p2(T, int C)(T s) { writeln( "p2: ", s, " / ", C); } } class C(T) { T b = new T; template opDispatch(string s) { template opDispatch(TARGS...) { auto opDispatch(ARGS...)(ARGS args) { static if(TARGS.length) return mixin("b." ~ s ~ "!TARGS(args)"); else return mixin("b." ~ s ~ "(args)"); } } } } void main() { auto b = new C!(B)(); b.p1("abc"); b.p2!(int, 10)(5); } http://dpaste.dzfl.pl/791c65d0e4ee
Re: Polymorphic recursive class
Yes! It works: http://dpaste.dzfl.pl/b9c6a2a958e5
Re: Polymorphic recursive class
On Monday, 13 July 2015 at 13:51:51 UTC, Dmitry Olshansky wrote: You can do it no problem, it just requires to manually implement boxing and make `right` a template that casts to the right type. The reason is that D doesn't provide an extra abstraction layer that is "auto-magically" there in typical FP language. Not tested but this should work: class Nested(T){ T left; void* right_; // or use opaque type if allergic to void* @property auto right()(){ // empty template to prevent recursion return cast(Nested!(T[])right_; } @property auto right(U)(Nested!U type){ // empty template to prevent recursion right_ = cast(void*)right_; } // and lastly the constructor should be templated this(U)(T l, Nested!(U) r) { left = l; right = r; } } Wow! Template properties is nice idea. Thanks.
Re: Polymorphic recursive class
On Monday, 13 July 2015 at 12:53:12 UTC, deadalnix wrote: On Monday, 13 July 2015 at 11:36:48 UTC, Jack Applegame wrote: Yes, that is I intended. It is a pretty useless example, just for demonstrating the lack of support polymorphic recursive data types. So the point is that we should add feature to the language to support useless use cases ? Not all cases are useless. For example, typical functional programming patterns like recursive compile-time trees and lists.
Re: Polymorphic recursive class
On Monday, 13 July 2015 at 10:33:17 UTC, Dmitry Olshansky wrote: You might mean Nested!A[] ? No. Else it looks like making a construct that is: left - an element, right - { left - an array, right - { left - an array of arrays, right - { left- an array of array of arrays right - an so on ... WTF? } } } Yes, that is I intended. It is a pretty useless example, just for demonstrating the lack of support polymorphic recursive data types.
Re: Polymorphic recursive class
On Monday, 13 July 2015 at 09:03:20 UTC, deadalnix wrote: Just use static if and be done with it. How?
Re: Polymorphic recursive class
On Monday, 13 July 2015 at 08:05:05 UTC, thedeemon wrote: On Monday, 13 July 2015 at 06:31:33 UTC, Jack Applegame wrote: But is there any reason why D can't follow MLton way - instantiate a class type template ONLY when a constructor of given class is used? Because if constructor isn't used doesn't mean the class isn't used: there can be some static methods or other stuff. Ok, lets instantiate it only when we use some stuff.
Polymorphic recursive class
This code doesn't compile, because recursive template expansion. class Nested(A) { A left; Nested!(A[]) right; this(A l, Nested!(A[]) r) { left = l; right = r; } } void main() { Nested!int nested = new Nested(1, null); } But it successfully compiles in Java an C#. And yes, I know about Java type erasure and C# run-time instantiation. But is there any reason why D can't follow MLton way - instantiate a class type template ONLY when a constructor of given class is used?
Re: Which D IDE do you use?(survey)
Sublime Text 3
Re: D in my trashbin
On Friday, 24 October 2014 at 02:42:13 UTC, frustrated wrote: Two days later and I still cant get a 'Hello World' to compile. It is far beyond me how a project can exist for so many years and still not have a straightforward installation that works out of the box. Yes.. read the forums and search google for solutions that may or may not work depending on the phases of the moon, I have to ask you: Why bother ? Why would anybody trust a compiler written by people who regard making it run out of the box an after-thought ? Natural selection in action. You saved the D community from yourself. Thank you very much!
Re: Library Typedefs are fundamentally broken
You can use module name and line number as unique tag.
Re: std.allocator ready for some abuse
Passing -g flag to the linker causes a linker error on win32. Very simple program: import std.allocator; void main() {} Compilation commands: dmd.exe -g -debug -c std/allocator.d -ofallocator.obj dmd.exe -g -debug -c main.d -ofmain.obj dmd.exe out.exe -g allocator.obj main.obj Output: dmd.exe out.exe -g allocator.obj main.obj OPTLINK (R) for Win32 Release 8.00.13 Copyright (C) Digital Mars 1989-2010 All rights reserved. http://www.digitalmars.com/ctg/optlink.html allocator.obj(allocator) Error 42: Symbol Undefined __aligned_malloc allocator.obj(allocator) Error 42: Symbol Undefined __aligned_free allocator.obj(allocator) Error 42: Symbol Undefined __aligned_realloc --- errorlevel 3 Without -g flag on the last command (dmd.exe out.exe allocator.obj main.obj) no linker error appears.