Re: Conditional compilation of array of structs initializer

2017-11-09 Thread Tony via Digitalmars-d-learn

Thanks Mike!


Re: Distinct "static" parent property contents for children

2017-11-09 Thread Timoses via Digitalmars-d-learn
On Thursday, 9 November 2017 at 14:34:10 UTC, Steven 
Schveighoffer wrote:

On 11/9/17 7:34 AM, Timoses wrote:



I suppose this is what Adam suggested, correct?


Yes, more or less. It's just an actual implementation vs. a 
description in case it wasn't clear.


[...]

It's not much different from what Adam and I suggested. The 
only thing you are missing is the ability to call the virtual 
member without an instance. But if you name your functions 
properly, and follow a convention, it will work for you.


-Steve


Greatly elaborated! Thank you, Steve!

I hope the vtable stuff is gonna be mentioned in the lectures I'm 
currently watching : P.


Re: Conditional compilation of array of structs initializer

2017-11-09 Thread Michael V. Franklin via Digitalmars-d-learn

On Friday, 10 November 2017 at 06:22:51 UTC, Tony wrote:
Doing a port of some C code that has an #ifdef in the middle of 
an initialization for an array of structs. I am getting a 
compile error trying to get equivalent behavior with "static 
if" or "version". Is there a way to achieve this other than 
making two separate array initialization sections?


struct a {
   int y;
   int z;
}

immutable string situation = "abc";

int main()
{
   a[] theArray = [
  { 10, 20 },
// version(abc)
static if (situation == "abc")
{
  { 30, 40 },
}
  { 50, 60 }
  ];
   return 0;
}


Here's my attempt. There's probably a more elegant way, but it's 
the best I could do.


import std.stdio;

struct a {
int y;
int z;
}

enum situation = "abc";

int main()
{
enum head = "a[] theArray = [ {10, 20},";
static if (situation == "abc")
{
enum middle = "{ 30, 40},";   
}
else
{
enum middle = ""; 
}
enum tail = "{ 50, 60 }];";
mixin(head ~ middle ~ tail);

writeln(head ~ middle ~ tail);

return 0;
}

The use of enums for this is called manifest constants 
(https://dlang.org/spec/enum.html#manifest_constants).  It's more 
analogous to #define in C.


Mixins are documented here 
(https://dlang.org/spec/statement.html#mixin-statement)


Mike


ircbod2 - easy IRC bots in D

2017-11-09 Thread Basile B. via Digitalmars-d-announce
Nothing fantastic but I've refreshed an old library called 
"ircbod", it allows to create IRC bots very easily.


https://code.dlang.org/packages/ircbod2
https://github.com/BBasile/ircbod2

"easily" means "register callbacks".


Conditional compilation of array of structs initializer

2017-11-09 Thread Tony via Digitalmars-d-learn
Doing a port of some C code that has an #ifdef in the middle of 
an initialization for an array of structs. I am getting a compile 
error trying to get equivalent behavior with "static if" or 
"version". Is there a way to achieve this other than making two 
separate array initialization sections?


struct a {
   int y;
   int z;
}

immutable string situation = "abc";

int main()
{
   a[] theArray = [
  { 10, 20 },
// version(abc)
static if (situation == "abc")
{
  { 30, 40 },
}
  { 50, 60 }
  ];
   return 0;
}


Re: Project Elvis

2017-11-09 Thread Adam Wilson via Digitalmars-d

On 11/6/17 12:20, Michael wrote:

I can't quite see why this proposal is such a big deal to people - as
has been restated, it's just a quick change in the parser for a slight
contraction in the code, and nothing language-breaking, it's not a big
change to the language at all.

On Monday, 6 November 2017 at 19:13:59 UTC, Adam Wilson wrote:

I am all for the Elvis operator, however I have two reservations about
it. The first is that I don't see much use for it without a
null-conditional. The second is that the current proposed syntax ?: is
MUCH to easily confused with ?.

This is not easy to read: obj1?.obj2?.prop3?:constant.

When designing syntax sugar, ergonomics are very important, otherwise
people won't use it. Microsoft spent a LOT of time and treasure to
learn these lessons for us. I see no reason to ignore them just
because "we don't like Microsoft"

My proposal would be to copy what MSFT did, expect that I would I
would introduce both operators at the same time.

Syntax as follows: obj1?.obj2?.prop3 ?? constant

In practice I don't see much use of the idiom outside of null's. The
ONLY other thing that would work there is a boolean field and you
might as well just return the boolean itself because the return values
have to match types.


I feel this is kind of embellished somewhat. When you write


This is not easy to read: obj1?.obj2?.prop3?:constant.


you're not separating it out as you do when you write your preferred
version:


Syntax as follows: obj1?.obj2?.prop3 ?? constant


How is


obj1?.obj2?.prop3 ?: constant


not as easy to read as



obj1?.obj2?.prop3 ?? constant




You're right, I didn't, that was intentional, because sometimes people 
write things like that. And it took a while for anyone to say anything 
about it. That is my point.


But that's the thing. The ?? is significantly more obvious in the 
condensed version.


This is something that a UX designer would recognize instantly, but 
human factors are very definitely not our strong skill as engineers. 
FWIW, my human factors experience comes from the deep study of airline 
crashes that I do as a pilot.



to me they are the same in terms of readability, only with ?? you have
greater chances of mistyping and adding a second ? in there somewhere,
whereas the ?: is just a contraction of the current syntax, I really
don't think it's that difficult, so I'm not sure what people's hang-ups
are, but I don't think the argument that ?? is easier to read than ?:
holds any weight here, because one *is* a change to the language, and
the other is a change to the parser and a contraction of a standard
convention.



Two things. ?: is ALSO a change a to language (lexer+parser). As to the 
whole "it's no more likely to typo the colon than the question" 
argument, sure, but that depends on the keyboard layout more than 
anything else, what works for you may not work elsewhere. And in either 
case, it's an easy compiler error. So you don't win anything with the 
?:, but you win readability with the ??. MSFT spends a LOT of time 
studying these things. It would be wise to learn for free from the money 
they spent.



--
Adam Wilson
IRC: LightBender
import quiet.dlang.dev;


Re: [OT] mobile rising

2017-11-09 Thread jmh530 via Digitalmars-d

On Friday, 10 November 2017 at 01:19:06 UTC, codephantom wrote:


Well, everytime I wanted to find something, I had to google 
it...


Then I realised I had to pay for it as well...and, that's when 
i gave up.


Bill Gates wasn't the richest man in the world for so long 
without reason. ;)


Re: [OT] mobile rising

2017-11-09 Thread codephantom via Digitalmars-d

On Thursday, 9 November 2017 at 14:42:41 UTC, Joakim wrote:
As I said earlier, the mobile OS story is not over yet, there 
are more changes to come.


Yeah...like more factories making more dongles.

You want a dongle?

https://www.youtube.com/watch?v=-XSC_UG5_kU



Re: [OT] mobile rising

2017-11-09 Thread codephantom via Digitalmars-d

On Friday, 10 November 2017 at 01:15:26 UTC, Jerry wrote:
Not much of a technie nerd if it "just finished" and you've 
already exhausted your knowledge and have given up :). Just 
sayin'.


Well, everytime I wanted to find something, I had to google it...

Then I realised I had to pay for it as well...and, that's when i 
gave up.


Re: [OT] mobile rising

2017-11-09 Thread Jerry via Digitalmars-d

On Friday, 10 November 2017 at 01:04:05 UTC, codephantom wrote:
On Friday, 10 November 2017 at 00:23:03 UTC, Jonathan M Davis 
wrote:
I don't disagree that there are differences between FreeBSD 
and Linux, but my point is that for most folks, the 
differences are small enough that it's not all that different 
from trying to convince someone to use one Linux distro or 
another - especially if you're trying to convince a Windows 
user, since Windows is so drastically different from both.


My Windows 10 just finished downloading.

I installed it, and even a technie nerd like me couldn't work 
it out.


I think Windows 10 is enough to convince users to switch ... to 
anything ;-)


https://www.youtube.com/watch?v=KHG6fXEba0A


Not much of a technie nerd if it "just finished" and you've 
already exhausted your knowledge and have given up :). Just 
sayin'.


Re: [OT] mobile rising

2017-11-09 Thread codephantom via Digitalmars-d
On Friday, 10 November 2017 at 00:23:03 UTC, Jonathan M Davis 
wrote:
I don't disagree that there are differences between FreeBSD and 
Linux, but my point is that for most folks, the differences are 
small enough that it's not all that different from trying to 
convince someone to use one Linux distro or another - 
especially if you're trying to convince a Windows user, since 
Windows is so drastically different from both.


My Windows 10 just finished downloading.

I installed it, and even a technie nerd like me couldn't work it 
out.


I think Windows 10 is enough to convince users to switch ... to 
anything ;-)


https://www.youtube.com/watch?v=KHG6fXEba0A



Re: [OT] mobile rising

2017-11-09 Thread codephantom via Digitalmars-d
On Friday, 10 November 2017 at 00:23:03 UTC, Jonathan M Davis 
wrote:
Plenty of us do get picky about details, which would lead us to 
one or the other, depending on our preferences, but there are 
way more similarities than differences - to the point that to 
many folks, the differences seem pretty superficial.


- Jonathan M Davis


No, the diffs really are considerable. FreeBSD is not Linux.

For example, FreeBSD doesn't have systemd ;-)

https://www.youtube.com/watch?v=MpDdGOKZ3dg



Re: [OT] mobile rising

2017-11-09 Thread Jonathan M Davis via Digitalmars-d
On Thursday, November 09, 2017 23:42:37 codephantom via Digitalmars-d wrote:
> On Wednesday, 8 November 2017 at 11:47:32 UTC, Jonathan M Davis
>
> wrote:
> > Oh, I'm all for using FreeBSD, but most of the arguments for
> > using FreeBSD over Windows apply to Linux. And if you can't get
> > someone to switch from Windows to Linux, you're not going to
> > get them to switch to FreeBSD. FreeBSD and Linux are definitely
> > different, but the differences are small when compared with
> > Windows.
>
> Except, that Linux/GNU is basically a clone of a clone.
>
> BSD is...just BSD..from which all the clones are made ;-)
>
> More importantly, is the GPL vs BSD licence thing.
>
> If you examine GPL code, and think..mmm..that looks good, I might
> use it in my appthen you're in trouble is you distribute that
> app without also distributing your code.
>
> BSD gives you 'genuine freedom' to use the code as you see fit -
> just don't try claiming that you wrote it, or you'll be in
> trouble.
>
> There is also the 'distribution' thing...FreeBSD is a single,
> managed, complete distrbution. Linux is just a kernel. It's
> combined with various GNU stuff to make up a distribution, and
> most distrubtions make their own little changes here and there,
> and you never really know what's going on. With FreeBSD there is
> only the FreeBSD distribution.
>
> So there maybe similiarities between FreeBSD and Linux/GNU, but
> their differences are really significant and warrant attention.
>
> Oddly enough, whatever draws me to FreeBSD, also draws me to D -
> I'm still not sure what it is...but the word 'freedom' keeps
> coming to mind. I cannot say that for Linux as much. I cannot say
> that for golang. They offer freedom, and at the same time setup
> out to restrict it.

I don't disagree that there are differences between FreeBSD and Linux, but
my point is that for most folks, the differences are small enough that it's
not all that different from trying to convince someone to use one Linux
distro or another - especially if you're trying to convince a Windows user,
since Windows is so drastically different from both. In most cases, whether
you run FreeBSD or Linux really comes down to preference. For the most part,
they both serve people's needs very well and on the surface aren't very
different.

I definitely prefer the BSD license to the GPL as well as how the BSDs
typically go about designing things, but if you don't care about the
licensing situation, whether it even matters to you which you're using
starts getting down to some pretty specific stuff that would seem fairly
esoteric to a lot of folks (especially non-geeks). It's even the case that
most software that runs on one runs on the other - including the desktop
environments - so while the differences definitely matter, they tend to be
pretty small from the end user's point of view. Plenty of us do get picky
about details, which would lead us to one or the other, depending on our
preferences, but there are way more similarities than differences - to the
point that to many folks, the differences seem pretty superficial.

- Jonathan M Davis



Re: How you guys go about -BetterC Multithreading?

2017-11-09 Thread rikki cattermole via Digitalmars-d-learn

On 09/11/2017 4:00 PM, Petar Kirov [ZombineDev] wrote:

On Thursday, 9 November 2017 at 13:00:15 UTC, ParticlePeter wrote:
On Thursday, 9 November 2017 at 12:19:00 UTC, Petar Kirov [ZombineDev] 
wrote:

On Thursday, 9 November 2017 at 11:08:21 UTC, ParticlePeter wrote:

Any experience reports or general suggestions?
I've used only D threads so far.


It would be far easier if you use druntime + @nogc and/or de-register 
latency-sensitive threads from druntime [1], so they're not 
interrupted even if some other thread calls the GC. Probably the path 
of least resistance is to call [2] and queue @nogc tasks on [3].


If you really want to pursue the version(D_BetterC) route, then 
you're essentially on your own to use the threading facilities 
provided by your target OS, e.g.:


https://linux.die.net/man/3/pthread_create
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682516(v=vs.85).aspx 



Though you need to be extra careful not to use thread-local storage 
(e.g. only shared static and __gshared) and not to rely on (shared) 
static {con|de}structors, dynamic arrays, associative arrays, 
exceptions, classes, RAII, etc., which is really not worth it, unless 
you're writing very low-level code (e.g. OS kernels and drivers).


[1]: https://dlang.org/phobos/core_thread#.thread_detachThis
[2]: https://dlang.org/phobos/core_memory#.GC.disable
[3]: https://dlang.org/phobos/std_parallelism#.taskPool


Forgot to mention, I'll try this first, I think its a good first step 
towards -BetterC usage. But in the end I want to see how far I can get 
with the -BetterC feature.


In short, the cost / benefit of going all the way version(D_BetterC) is 
incredibly poor for regular applications, as you end up a bit more 
limited than with modern C++ (> 11) for prototyping. For example, even 
writers of D real-time audio plugins don't go as far.


I just did some work for Guillaume Piolat (p0nce author of dplug), guess 
what is going to be used again, druntime!





Re: [OT] mobile rising

2017-11-09 Thread codephantom via Digitalmars-d
On Wednesday, 8 November 2017 at 11:47:32 UTC, Jonathan M Davis 
wrote:


Oh, I'm all for using FreeBSD, but most of the arguments for 
using FreeBSD over Windows apply to Linux. And if you can't get 
someone to switch from Windows to Linux, you're not going to 
get them to switch to FreeBSD. FreeBSD and Linux are definitely 
different, but the differences are small when compared with 
Windows.


Except, that Linux/GNU is basically a clone of a clone.

BSD is...just BSD..from which all the clones are made ;-)

More importantly, is the GPL vs BSD licence thing.

If you examine GPL code, and think..mmm..that looks good, I might 
use it in my appthen you're in trouble is you distribute that 
app without also distributing your code.


BSD gives you 'genuine freedom' to use the code as you see fit - 
just don't try claiming that you wrote it, or you'll be in 
trouble.


There is also the 'distribution' thing...FreeBSD is a single, 
managed, complete distrbution. Linux is just a kernel. It's 
combined with various GNU stuff to make up a distribution, and 
most distrubtions make their own little changes here and there, 
and you never really know what's going on. With FreeBSD there is 
only the FreeBSD distribution.


So there maybe similiarities between FreeBSD and Linux/GNU, but 
their differences are really significant and warrant attention.


Oddly enough, whatever draws me to FreeBSD, also draws me to D - 
I'm still not sure what it is...but the word 'freedom' keeps 
coming to mind. I cannot say that for Linux as much. I cannot say 
that for golang. They offer freedom, and at the same time setup 
out to restrict it.




Re: [OT] mobile rising

2017-11-09 Thread Ola Fosheim Grøstad via Digitalmars-d

On Thursday, 9 November 2017 at 14:42:41 UTC, Joakim wrote:
Do you blame them, given such anti-competitive measures long 
undertaken by MS and Apple?


Big businesses do what they can get away with. Once upon a time 
governments cared about anti-trust (E.g. AT and IBM), but 
nowadays it seems like they don't care much about enabling 
competition where smaller players get a shot. Governments seem to 
let the big multi-national corporations do what they want. It's 
not like MS was punished much for their behaviour…


(EU has mounted a little bit of resistance, but only thanks to 
individuals.)


There is some truth to this, but if you cannot compete with a 
free product- cough, cough, Windows Mobile- I don't know what 
to tell you.


I actually think the Microsoft phones looked quite appealing, but 
I didn't get the sense that Microsoft would back it up over time. 
Perception is king. Google had the same problem with Dart. They 
kept developing Dart, but after they announced that it didn't get 
into Chrome, many started to wonder if that was the beginning of 
the end.


 In other words, google cannot afford to spend a fraction of 
the money on Android that Apple spends on iOS, because google 
makes so little money off of Android by comparison, so there 
are disadvantages to their free model too.


As far as I can tell from the iOS APIs the internals doesn't seem 
to change all that much anymore. I'm sure they do a lot on 
hardware, drivers and tooling.


As I said earlier, the mobile OS story is not over yet, there 
are more changes to come.


Yes, that probably is true. The teenager/young adults segment can 
shift things real fast if someone push out a perfect mobile 
gaming-device.





Re: [OT] mobile rising

2017-11-09 Thread Jerry via Digitalmars-d

On Thursday, 9 November 2017 at 14:42:41 UTC, Joakim wrote:
There is some truth to this, but if you cannot compete with a 
free product- cough, cough, Windows Mobile- I don't know what 
to tell you.  In other words, google cannot afford to spend a 
fraction of the money on Android that Apple spends on iOS, 
because google makes so little money off of Android by 
comparison, so there are disadvantages to their free model too.
 It is one of the reasons why they have now plunged into the 
high-end smartphone market with their recent Pixel line.


I think the lack of a viable business model for Android 
vendors, other than Samsung, is a huge problem for the 
platform, as Apple hoovers up two-thirds of the profit with 
only a tenth of the phones sold:


https://www.counterpointresearch.com/80-of-global-handset-profits-comes-from-premium-segment/

As I said earlier, the mobile OS story is not over yet, there 
are more changes to come.


People that buy Android I find tend to keep their phones for 
longer. People with Apple phones keep buying new ones. Part of 
that is how many phone Apple claims are on the latest version. So 
developers only target the latest one, then their apps don't run 
on old phone and it encourages people to "upgrade". Android apps 
tend to support more versions as well, it's a more diverse OS. 
I've even seen websites that just straight up drop support for 
old versions of Safari. Can't get the latest version of Safari 
cause you can't update your phone. Then you go to firefox just to 
find out you can't install it cause it's no longer support for 
that iOS version. Can't even download an old version of firefox 
that did support it cause it's Apple's store and they don't 
support that.


[Issue 17935] [scope] auto-generated destructor not scope aware

2017-11-09 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17935

--- Comment #2 from github-bugzi...@puremagic.com ---
Commits pushed to master at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/c9ff5810a2f449f19a39172461d511c895dcb519
fix Issue 17935 - [scope] auto-generated destructor not scope aware

https://github.com/dlang/dmd/commit/0bb4ad1668fa7ea6539c2bf2c7035309afabbdd4
Merge pull request #7283 from WalterBright/fix17935

fix Issue 17935 - [scope] auto-generated destructor not scope aware
merged-on-behalf-of: Mathias Lang


--


[Issue 17935] [scope] auto-generated destructor not scope aware

2017-11-09 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17935

github-bugzi...@puremagic.com changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--


Re: How you guys go about -BetterC Multithreading?

2017-11-09 Thread Jacob Carlborg via Digitalmars-d-learn

On 2017-11-09 17:52, Petar Kirov [ZombineDev] wrote:

Thanks for reminding me, I keep forgetting that it should just work 
(minus initialization?).


What do you mean "initialization"? Any type that can be used in C in TLS 
should work in D as well (except for macOS 32bit, if anyone cares).


--
/Jacob Carlborg


[Issue 17467] BitArray are broken with <<= 64

2017-11-09 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17467

--- Comment #1 from github-bugzi...@puremagic.com ---
Commits pushed to master at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/997eb6229981bb1a28f160175c89dba0e52eae96
Fix Issue 17467 - BitArray are broken with <<= 64

https://github.com/dlang/phobos/commit/2534841d3ccc5412610a4dc85206e63faee5995f
Merge pull request #5842 from
Darredevil/issue-17467-bitArray-rollLeft-rollRight

Fix Issue 17467 - BitArray are broken with <<= 64
merged-on-behalf-of: Andrei Alexandrescu 

--


[Issue 17467] BitArray are broken with <<= 64

2017-11-09 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17467

github-bugzi...@puremagic.com changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--


[Issue 17975] D produces mangling incompatible with C++

2017-11-09 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17975

ki...@gmx.net changed:

   What|Removed |Added

 CC||ki...@gmx.net

--- Comment #1 from ki...@gmx.net ---
Well, when using a proper signature in D (transitive const!), it seems to work
fine:

extern (C++) int foo(pwchar* b, int bs, const(char)* it, const(char)* ite,
const(char)** itr);

=> https://godbolt.org/g/V7eR52

--


Re: Any book recommendation for writing a compiler?

2017-11-09 Thread Jim Hewes via Digitalmars-d-learn


Thanks for those references! I'm also interested in looking through 
those. I had computation theory in college a long time ago but never 
took a compiler course.



On 11/7/2017 5:26 AM, Tony wrote:
Author Allen Holub has made his out-of-print book, Compiler Design in C, 
available as a free pdf download:


http://holub.com/compiler/


And Torben Mogensen is doing the same with his more recent Basics of 
Compiler Design:


http://www.diku.dk/~torbenm/Basics/



---
This email has been checked for viruses by AVG.
http://www.avg.com





Re: How you guys go about -BetterC Multithreading?

2017-11-09 Thread Petar via Digitalmars-d-learn
On Thursday, 9 November 2017 at 16:08:20 UTC, Jacob Carlborg 
wrote:

On 2017-11-09 13:19, Petar Kirov [ZombineDev] wrote:

Though you need to be extra careful not to use thread-local 
storage


I think TLS should work, it's the OS that handles TLS, not 
druntime.


Thanks for reminding me, I keep forgetting that it should just 
work (minus initialization?).


Re: How you guys go about -BetterC Multithreading?

2017-11-09 Thread Jacob Carlborg via Digitalmars-d-learn

On 2017-11-09 13:19, Petar Kirov [ZombineDev] wrote:


Though you need to be extra careful not to use thread-local storage


I think TLS should work, it's the OS that handles TLS, not druntime.

--
/Jacob Carlborg


Re: How you guys go about -BetterC Multithreading?

2017-11-09 Thread Petar via Digitalmars-d-learn

On Thursday, 9 November 2017 at 13:00:15 UTC, ParticlePeter wrote:
On Thursday, 9 November 2017 at 12:19:00 UTC, Petar Kirov 
[ZombineDev] wrote:
On Thursday, 9 November 2017 at 11:08:21 UTC, ParticlePeter 
wrote:

Any experience reports or general suggestions?
I've used only D threads so far.


It would be far easier if you use druntime + @nogc and/or 
de-register latency-sensitive threads from druntime [1], so 
they're not interrupted even if some other thread calls the 
GC. Probably the path of least resistance is to call [2] and 
queue @nogc tasks on [3].


If you really want to pursue the version(D_BetterC) route, 
then you're essentially on your own to use the threading 
facilities provided by your target OS, e.g.:


https://linux.die.net/man/3/pthread_create
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682516(v=vs.85).aspx

Though you need to be extra careful not to use thread-local 
storage (e.g. only shared static and __gshared) and not to 
rely on (shared) static {con|de}structors, dynamic arrays, 
associative arrays, exceptions, classes, RAII, etc., which is 
really not worth it, unless you're writing very low-level code 
(e.g. OS kernels and drivers).


[1]: https://dlang.org/phobos/core_thread#.thread_detachThis
[2]: https://dlang.org/phobos/core_memory#.GC.disable
[3]: https://dlang.org/phobos/std_parallelism#.taskPool


Forgot to mention, I'll try this first, I think its a good 
first step towards -BetterC usage. But in the end I want to see 
how far I can get with the -BetterC feature.


In short, the cost / benefit of going all the way 
version(D_BetterC) is incredibly poor for regular applications, 
as you end up a bit more limited than with modern C++ (> 11) for 
prototyping. For example, even writers of D real-time audio 
plugins don't go as far.
If you're writing libraries, especially math-heavy template code, 
CTFE and generic code in general, then version(D_BetterC) is a 
useful tool for verifying that your library doesn't need 
unnecessary dependencies preventing it from being trivially 
integrated in foreign language environments.


Well if you like generic code as much as I do, you can surely do 
great with version(D_BetterC) even for application code, but you 
would have to make alomst every non-builtin type that you use in 
your code a template parameter (or alternatively an extern 
(C++/COM) interface if that works in -betterC), so you can easily 
swap druntime/phobos-based implementations for your custom ones, 
one by one, but I guess few people would be interested in 
following this path.


Re: [OT] mobile rising

2017-11-09 Thread Joakim via Digitalmars-d
On Thursday, 9 November 2017 at 14:22:22 UTC, Ola Fosheim Grøstad 
wrote:
I also think we should add to this discussion that Google was 
hellbent on going forward with Android even when it was clearly 
inferior. Apple tried to squish out Google's services from 
their iOS products for a while. And that is exactly what Google 
tries to prevent by funding things like Chrome and Android.


Do you blame them, given such anti-competitive measures long 
undertaken by MS and Apple?


So for Google Chrome and Android does not have to make sense in 
business terms, it is basically an anti-competitive tool to 
protect their own hegemony (relative monopoly) by retaining 
critical mass and making it difficult for competitors to build 
up a competing product over time (you need a source of income 
while your product is evolving from mediocre to great to do 
that).


There is some truth to this, but if you cannot compete with a 
free product- cough, cough, Windows Mobile- I don't know what to 
tell you.  In other words, google cannot afford to spend a 
fraction of the money on Android that Apple spends on iOS, 
because google makes so little money off of Android by 
comparison, so there are disadvantages to their free model too.  
It is one of the reasons why they have now plunged into the 
high-end smartphone market with their recent Pixel line.


I think the lack of a viable business model for Android vendors, 
other than Samsung, is a huge problem for the platform, as Apple 
hoovers up two-thirds of the profit with only a tenth of the 
phones sold:


https://www.counterpointresearch.com/80-of-global-handset-profits-comes-from-premium-segment/

As I said earlier, the mobile OS story is not over yet, there are 
more changes to come.


Re: Distinct "static" parent property contents for children

2017-11-09 Thread Steven Schveighoffer via Digitalmars-d-learn

On 11/9/17 7:34 AM, Timoses wrote:



I suppose this is what Adam suggested, correct?


Yes, more or less. It's just an actual implementation vs. a description 
in case it wasn't clear.






This is a more general question: Why is it not possible to 
implement/override static methods?


Static methods aren't virtual. There isn't a notion of a vtable for 
static methods on a class -- they are simply normal functions in a 
different namespace. I know other languages allow this, D does not.



interface I // or abstract class I
{
     static int fun();


This is actually a non-virtual method, it needs an implementation.


}
class A : I
{
     static int fun() { return 3; }


Note, that this isn't necessary to implement I. In other words:

class A : I {}

also works.


}
void main()
{
     I i = new A();
     i.fun();    // <--- linker error


This is calling I.fun, which has no implementation.


}

or replacing interface with an abstract base class.

Static overriding would be quite interesting in terms of compile-time 
handling of objects.


In a way, static overriding *does* work at compile time:

class A
{
  static int i() { return 1; }
}

class B : A
{
  static int i() { return 2; }
}

assert(A.i == 1);
assert(B.i == 2);

But what you are asking is to have an instance of B, even when 
statically typed as A, call the derived version of the static method. In 
essence, this is super-similar to a virtual method, but instead of 
taking an instance, it wouldn't need to. But the key here is you *need* 
an instance for it to make any sense.


It's not much different from what Adam and I suggested. The only thing 
you are missing is the ability to call the virtual member without an 
instance. But if you name your functions properly, and follow a 
convention, it will work for you.


-Steve


Re: [OT] mobile rising

2017-11-09 Thread Joakim via Digitalmars-d
On Thursday, 9 November 2017 at 14:15:47 UTC, Ola Fosheim Grøstad 
wrote:

On Thursday, 9 November 2017 at 00:09:32 UTC, Joakim wrote:
smaller search company, did with Android, leaving aside Apple 
because of your silly claims that their existing software gave 
them a headstart, which is why those former computing giants 
are all either dead or fading fast.


It is hardly a silly claim:

NextStep (1989) ==> OS-X (2001) ==> iOS (2007)

That is 18 years of evolution and experience, and it also meant 
that they had the development tooling ready + experienced 
developers for their platform (macOS programmers). It also 
mattered a lot that Apple already had the manufacturing 
experience with prior attempts and also the streamlining of the 
iPod-line as well as the infrastructure for distribution and 
following up customers (again from the iPod line).


So, for Apple it was a relatively modest step to go from

 iPod + Mac frameworks + standard 3rd party chips + existing 
tooling + iTunes


 =>

iPhone

I think you are forgetting that hardly anyone wanted to develop 
apps for Android in the first few years. Android was pariah, 
and everybody did iOS apps first, then if it was a big success 
then maybe they would try to port it over to Android (but 
usually not).


I agree that Apple had an advantage in getting into the 
smartphone market, but MS, RIM, Nokia, etc. had much larger 
advantages in this regard.  And you continue to ignore that 
Android and google started their mobile OS from scratch and now 
ship on the most smartphones.  Of course, they just grabbed 
existing tech like the linux kernel, Java, and various other OSS 
projects and put it all together with code of their own, but 
that's something any of the computing giants and many other 
upstarts like HTC or Asus could have done.


Yet, they didn't, which suggests a lack of vision or some other 
technical ability than "OS expertise."


Re: [OT] mobile rising

2017-11-09 Thread Ola Fosheim Grøstad via Digitalmars-d
I also think we should add to this discussion that Google was 
hellbent on going forward with Android even when it was clearly 
inferior. Apple tried to squish out Google's services from their 
iOS products for a while. And that is exactly what Google tries 
to prevent by funding things like Chrome and Android.


So for Google Chrome and Android does not have to make sense in 
business terms, it is basically an anti-competitive tool to 
protect their own hegemony (relative monopoly) by retaining 
critical mass and making it difficult for competitors to build up 
a competing product over time (you need a source of income while 
your product is evolving from mediocre to great to do that).


Re: ddox empty public methods/interfaces etc

2017-11-09 Thread Steven Schveighoffer via Digitalmars-d-learn

On 11/8/17 10:45 PM, Andrey wrote:


I just added to dub.json this:


"-ddoxFilterArgs": [
    "--min-protection=Public"
]


i.e. without --only-documented option, in this way ddox will generate 
documentation for all public methods, even if there is no docstring.


Interesting. I misunderstood then how ddox works. I thought the json it 
gets is the output from the ddoc generator, but now I realize it's the 
output from the parser itself.


So sure, this makes sense. Sorry for the misinformation!

-Steve


Re: [OT] mobile rising

2017-11-09 Thread Ola Fosheim Grøstad via Digitalmars-d

On Thursday, 9 November 2017 at 00:09:32 UTC, Joakim wrote:
smaller search company, did with Android, leaving aside Apple 
because of your silly claims that their existing software gave 
them a headstart, which is why those former computing giants 
are all either dead or fading fast.


It is hardly a silly claim:

NextStep (1989) ==> OS-X (2001) ==> iOS (2007)

That is 18 years of evolution and experience, and it also meant 
that they had the development tooling ready + experienced 
developers for their platform (macOS programmers). It also 
mattered a lot that Apple already had the manufacturing 
experience with prior attempts and also the streamlining of the 
iPod-line as well as the infrastructure for distribution and 
following up customers (again from the iPod line).


So, for Apple it was a relatively modest step to go from

 iPod + Mac frameworks + standard 3rd party chips + existing 
tooling + iTunes


 =>

iPhone

I think you are forgetting that hardly anyone wanted to develop 
apps for Android in the first few years. Android was pariah, and 
everybody did iOS apps first, then if it was a big success then 
maybe they would try to port it over to Android (but usually not).





Re: [OT] mobile rising

2017-11-09 Thread Joakim via Digitalmars-d

On Thursday, 9 November 2017 at 12:27:49 UTC, Paulo Pinto wrote:

On Thursday, 9 November 2017 at 00:09:32 UTC, Joakim wrote:

...
I think you greatly overestimate what was needed to compete in 
this mobile market at that time.  I'm not saying it was easy, 
but the PC and mobile giants before iOS/Android clearly didn't 
have the vision or ability to execute what google, a much 
smaller search company, did with Android, leaving aside Apple 
because of your silly claims that their existing software gave 
them a headstart, which is why those former computing giants 
are all either dead or fading fast.


Google bought the company responsible for Hiptop, which was 
already developing Android, where the majority of employees 
were former BeOS employees, many of which are still on the 
Android team.


Not quite, the company responsible for the Hiptop was Danger, 
which was acquired by MS in 2008:


https://en.m.wikipedia.org/wiki/Danger_Inc.

Some key people left Danger to start Android before that, which 
is what you're thinking of.  I mentioned that 2005 google 
acquisition of Android earlier in this thread.  I'm not sure what 
point you're trying to make though, as HP, Sony, MS, Nokia, etc. 
had enough money to buy 50 such companies, ie google didn't have 
any resource or "OS expertise" advantage over those computing 
giants.  They certainly had a better vision for mobile and 
arguably other technical skills.


It's funny, everybody is now ridiculing the dismissive statements 
made by those giants when Android launched a decade ago:


https://www.engadget.com/2007/11/05/symbian-nokia-microsoft-and-apple-downplay-android-relevance/


[Issue 17974] getSymbolsByUDA is returns unusable symbols when used in foreach

2017-11-09 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17974

--- Comment #3 from Artem Borisovskiy  ---
Thanks, but I already found another way of doing it, by using
__traits(getMember...). Anyway, both my and your solutions are ugly hacks. They
make code even less readable than it was before. It's possible to get rid of
some repetition, though:

alias symbols = getSymbolsByUDA!(FUBAR, Attr);
static foreach (i; symbols.length.iota)
pragma(msg, getUDAs!(symbols[i], Attr));

Still, `static foreach (symbol; getSymbolsByUDA!(FUBAR, Attr))' would be nicer.

--


Re: Cannot reduce an empty iterable w/o an explicit seed value

2017-11-09 Thread Nicholas Wilson via Digitalmars-d-learn

On Thursday, 9 November 2017 at 12:40:49 UTC, Vino wrote:

Hi All,

  Request your help, when i execute the below line of code i am 
getting an error message as "Cannot reduce an empty iterable 
w/o an explicit seed value" , The below lie of code will 
iterate several file system and will report the size of the 
folder (level 1) which is greater than 10GB.


The reason you get this is because when evaluating an empty 
directory there are no files, so it is like you are trying to do

   [].sum

which can give no sensible result.



Re: Cannot reduce an empty iterable w/o an explicit seed value

2017-11-09 Thread Nicholas Wilson via Digitalmars-d-learn

On Thursday, 9 November 2017 at 12:40:49 UTC, Vino wrote:

Hi All,

  Request your help, when i execute the below line of code i am 
getting an error message as "Cannot reduce an empty iterable 
w/o an explicit seed value" , The below lie of code will 
iterate several file system and will report the size of the 
folder (level 1) which is greater than 10GB.



Program:
auto coSizeDirList (string FFs, int SizeDir) {
float subdirTotal;
float subdirTotalGB;
Array!string Result;
	auto dFiles = Array!string ((dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir))[].map!(a => a.name));

foreach (d; parallel(dFiles[], 1)) {
	auto SdFiles = Array!float ((dirEntries(join(["?\\", d]), 
SpanMode.depth).filter!(a => a.isFile))[].map!(a => 
to!float(a.size)));

{
	subdirTotalGB = ((reduce!((a,b) => a + b)(SdFiles)) / 1024 / 
1024 / 1024);

}
 if (subdirTotalGB > SizeDir) {
Result.insertBack(d); 
Result.insertBack(to!string(subdirTotalGB));

}
}
return Result;
}

From,
Vino.B


The problem is
subdirTotalGB = ((reduce!((a,b) => a + b)(SdFiles)) / 1024 / 1024 
/ 1024);
with reduce you need to give it a seed (an initial value to start 
with).

See
https://dlang.org/phobos/std_algorithm_iteration.html#.reduce


int[] arr = [ 1, 2, 3, 4, 5 ];
// Sum all elements
auto sum = reduce!((a,b) => a + b)(0, arr);
writeln(sum); // 15

// Sum again, using a string predicate with "a" and "b"
sum = reduce!"a + b"(0, arr);
writeln(sum); // 15


To your actual use case, you can do:

foreach (d; parallel(dFiles[], 1)) {
float subdirTotalGB = dirEntries(join(["?\\", d]), 
SpanMode.depth)

.filter!(a => a.isFile))
.map!(a => to!float(a.size)))
.fold!((a, b) => a + b)(0) // Provide an explicit seed.

if (subdirTotalGB > SizeDir) {
Result.insertBack(d);
Result.insertBack(to!string(subdirTotalGB));
}
}




Re: How you guys go about -BetterC Multithreading?

2017-11-09 Thread ParticlePeter via Digitalmars-d-learn
On Thursday, 9 November 2017 at 12:19:00 UTC, Petar Kirov 
[ZombineDev] wrote:
On Thursday, 9 November 2017 at 11:08:21 UTC, ParticlePeter 
wrote:

Any experience reports or general suggestions?
I've used only D threads so far.


It would be far easier if you use druntime + @nogc and/or 
de-register latency-sensitive threads from druntime [1], so 
they're not interrupted even if some other thread calls the GC. 
Probably the path of least resistance is to call [2] and queue 
@nogc tasks on [3].


If you really want to pursue the version(D_BetterC) route, then 
you're essentially on your own to use the threading facilities 
provided by your target OS, e.g.:


https://linux.die.net/man/3/pthread_create
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682516(v=vs.85).aspx

Though you need to be extra careful not to use thread-local 
storage (e.g. only shared static and __gshared) and not to rely 
on (shared) static {con|de}structors, dynamic arrays, 
associative arrays, exceptions, classes, RAII, etc., which is 
really not worth it, unless you're writing very low-level code 
(e.g. OS kernels and drivers).


[1]: https://dlang.org/phobos/core_thread#.thread_detachThis
[2]: https://dlang.org/phobos/core_memory#.GC.disable
[3]: https://dlang.org/phobos/std_parallelism#.taskPool


Forgot to mention, I'll try this first, I think its a good first 
step towards -BetterC usage. But in the end I want to see how far 
I can get with the -BetterC feature.


Re: How you guys go about -BetterC Multithreading?

2017-11-09 Thread ParticlePeter via Digitalmars-d-learn
On Thursday, 9 November 2017 at 12:43:54 UTC, Petar Kirov 
[ZombineDev] wrote:
On Thursday, 9 November 2017 at 12:30:49 UTC, rikki cattermole 
wrote:

On 09/11/2017 12:19 PM, Petar Kirov [ZombineDev] wrote:
On Thursday, 9 November 2017 at 11:08:21 UTC, ParticlePeter 
wrote:

Any experience reports or general suggestions?
I've used only D threads so far.


It would be far easier if you use druntime + @nogc and/or 
de-register latency-sensitive threads from druntime [1], so 
they're not interrupted even if some other thread calls the 
GC. Probably the path of least resistance is to call [2] and 
queue @nogc tasks on [3].


If you really want to pursue the version(D_BetterC) route, 
then you're essentially on your own to use the threading 
facilities provided by your target OS, e.g.:


https://linux.die.net/man/3/pthread_create
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682516(v=vs.85).aspx


You can use a library like libuv to handle threads 
(non-language based TLS too, not sure that it can be tied in 
unfortunately).


Yeah, any cross-platform thread-pool / event loop library with 
C interface should obviously be preferred than manual use of 
raw thread primitives.


Essentially, try to follow Sean Parent's advice on "No 
Raw/Incidental *":

https://www.youtube.com/watch?v=zULU6Hhp42w


This all is good input, thanks.
I was looking into:
https://github.com/GerHobbelt/pthread-win32

Anyone used this?


Cannot reduce an empty iterable w/o an explicit seed value

2017-11-09 Thread Vino via Digitalmars-d-learn

Hi All,

  Request your help, when i execute the below line of code i am 
getting an error message as "Cannot reduce an empty iterable w/o 
an explicit seed value" , The below lie of code will iterate 
several file system and will report the size of the folder (level 
1) which is greater than 10GB.



Program:
auto coSizeDirList (string FFs, int SizeDir) {
float subdirTotal;
float subdirTotalGB;
Array!string Result;
	auto dFiles = Array!string ((dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir))[].map!(a => a.name));

foreach (d; parallel(dFiles[], 1)) {
	auto SdFiles = Array!float ((dirEntries(join(["?\\", d]), 
SpanMode.depth).filter!(a => a.isFile))[].map!(a => 
to!float(a.size)));

{
	subdirTotalGB = ((reduce!((a,b) => a + b)(SdFiles)) / 1024 / 
1024 / 1024);

}
 if (subdirTotalGB > SizeDir) {
Result.insertBack(d); Result.insertBack(to!string(subdirTotalGB));
}
}
return Result;
}

From,
Vino.B


Re: How you guys go about -BetterC Multithreading?

2017-11-09 Thread Petar via Digitalmars-d-learn
On Thursday, 9 November 2017 at 12:30:49 UTC, rikki cattermole 
wrote:

On 09/11/2017 12:19 PM, Petar Kirov [ZombineDev] wrote:
On Thursday, 9 November 2017 at 11:08:21 UTC, ParticlePeter 
wrote:

Any experience reports or general suggestions?
I've used only D threads so far.


It would be far easier if you use druntime + @nogc and/or 
de-register latency-sensitive threads from druntime [1], so 
they're not interrupted even if some other thread calls the 
GC. Probably the path of least resistance is to call [2] and 
queue @nogc tasks on [3].


If you really want to pursue the version(D_BetterC) route, 
then you're essentially on your own to use the threading 
facilities provided by your target OS, e.g.:


https://linux.die.net/man/3/pthread_create
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682516(v=vs.85).aspx


You can use a library like libuv to handle threads 
(non-language based TLS too, not sure that it can be tied in 
unfortunately).


Yeah, any cross-platform thread-pool / event loop library with C 
interface should obviously be preferred than manual use of raw 
thread primitives.


Essentially, try to follow Sean Parent's advice on "No 
Raw/Incidental *":

https://www.youtube.com/watch?v=zULU6Hhp42w


Re: How you guys go about -BetterC Multithreading?

2017-11-09 Thread rikki cattermole via Digitalmars-d-learn

On 09/11/2017 12:19 PM, Petar Kirov [ZombineDev] wrote:

On Thursday, 9 November 2017 at 11:08:21 UTC, ParticlePeter wrote:

Any experience reports or general suggestions?
I've used only D threads so far.


It would be far easier if you use druntime + @nogc and/or de-register 
latency-sensitive threads from druntime [1], so they're not interrupted 
even if some other thread calls the GC. Probably the path of least 
resistance is to call [2] and queue @nogc tasks on [3].


If you really want to pursue the version(D_BetterC) route, then you're 
essentially on your own to use the threading facilities provided by your 
target OS, e.g.:


https://linux.die.net/man/3/pthread_create
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682516(v=vs.85).aspx 


You can use a library like libuv to handle threads (non-language based 
TLS too, not sure that it can be tied in unfortunately).


Re: Distinct "static" parent property contents for children

2017-11-09 Thread Timoses via Digitalmars-d-learn
On Wednesday, 8 November 2017 at 18:33:15 UTC, Steven 
Schveighoffer wrote:

On 11/8/17 12:38 PM, Timoses wrote:

Hey,

wrapping my head around this atm..



[snip]

so what you want is a static variable per subclass, but that 
the base class can access.


What I would recommend is this:

abstract class Base
{
   int x();
}

class A : Base
{
  private static int _x = 1;
  int x() { return _x; }
}

class B : Base
{
  private static int _x = 2;
  int x() { return _x; }
}

Note that this doesn't do *everything* a static variable can, 
since x() requires an instance (i.e. you can't do A.x). But the 
actual variable itself is static since the backing is static. 
This is the only way to provide access of x to the Base that I 
can think of.


-Steve


I suppose this is what Adam suggested, correct?



This is a more general question: Why is it not possible to 
implement/override static methods?


interface I // or abstract class I
{
static int fun();
}
class A : I
{
static int fun() { return 3; }
}
void main()
{
I i = new A();
i.fun();// <--- linker error
}

or replacing interface with an abstract base class.

Static overriding would be quite interesting in terms of 
compile-time handling of objects.


Re: [OT] mobile rising

2017-11-09 Thread Paulo Pinto via Digitalmars-d

On Thursday, 9 November 2017 at 00:09:32 UTC, Joakim wrote:

...
I think you greatly overestimate what was needed to compete in 
this mobile market at that time.  I'm not saying it was easy, 
but the PC and mobile giants before iOS/Android clearly didn't 
have the vision or ability to execute what google, a much 
smaller search company, did with Android, leaving aside Apple 
because of your silly claims that their existing software gave 
them a headstart, which is why those former computing giants 
are all either dead or fading fast.


Google bought the company responsible for Hiptop, which was 
already developing Android, where the majority of employees were 
former BeOS employees, many of which are still on the Android 
team.


Re: How you guys go about -BetterC Multithreading?

2017-11-09 Thread Petar via Digitalmars-d-learn

On Thursday, 9 November 2017 at 11:08:21 UTC, ParticlePeter wrote:

Any experience reports or general suggestions?
I've used only D threads so far.


It would be far easier if you use druntime + @nogc and/or 
de-register latency-sensitive threads from druntime [1], so 
they're not interrupted even if some other thread calls the GC. 
Probably the path of least resistance is to call [2] and queue 
@nogc tasks on [3].


If you really want to pursue the version(D_BetterC) route, then 
you're essentially on your own to use the threading facilities 
provided by your target OS, e.g.:


https://linux.die.net/man/3/pthread_create
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682516(v=vs.85).aspx

Though you need to be extra careful not to use thread-local 
storage (e.g. only shared static and __gshared) and not to rely 
on (shared) static {con|de}structors, dynamic arrays, associative 
arrays, exceptions, classes, RAII, etc., which is really not 
worth it, unless you're writing very low-level code (e.g. OS 
kernels and drivers).


[1]: https://dlang.org/phobos/core_thread#.thread_detachThis
[2]: https://dlang.org/phobos/core_memory#.GC.disable
[3]: https://dlang.org/phobos/std_parallelism#.taskPool


SublimeLinter-contrib-dmd: dmd feedback as you type. v1.1.0: DUB integration.

2017-11-09 Thread Bastiaan Veelo via Digitalmars-d-announce
On Tuesday, 31 October 2017 at 16:06:24 UTC, Moritz Maxeiner 
wrote:

On Tuesday, 31 October 2017 at 13:32:34 UTC, SrMordred wrote:

Thank you , works perfectly!

One idea: Integrating with dub.
So you don´t have to manually set lib dirs and flags since its 
all on 'dub.json' already.


You can pretty much copy paste from sublide for this [1] (my 
own D plugin for ST3).


[1] 
https://github.com/MoritzMaxeiner/sublide/blob/master/dub.py#L40


Thank you Moritz!

The plugin now looks for DUB project configuration files in open 
folders and adds any required import paths that can be determined 
from those automatically.


If you have installed the plugin using Sublime Text's Package 
Control, you'll get the update automatically.


[Issue 17975] D produces mangling incompatible with C++

2017-11-09 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17975

ZombineDev  changed:

   What|Removed |Added

   Keywords||C++, mangling
 CC||petar.p.ki...@gmail.com

--


How you guys go about -BetterC Multithreading?

2017-11-09 Thread ParticlePeter via Digitalmars-d-learn

Any experience reports or general suggestions?
I've used only D threads so far.



Re: Distinct "static" parent property contents for children

2017-11-09 Thread Timoses via Digitalmars-d-learn
On Wednesday, 8 November 2017 at 17:46:42 UTC, Adam D. Ruppe 
wrote:

On Wednesday, 8 November 2017 at 17:38:27 UTC, Timoses wrote:

Are there better options/ways of achieving this?


What are you actually trying to achieve? What are you using 
these variables for?


Well, I have the following outline:

class File
{
Section[] sections;
}
abstract class Section
{
enum Part { Header, Content, Footer};
SectionEntry[Part] entries;
}
class SectionEntry
{
bool isComment;
string[] lines;
}

And then I'd like to have somthing like predefined sections, e.g.:

class SectionTypeA : Section
{
 // provide "static" information that is
 // always the same for this type of seciton
  // however, the Content part may vary
}


Are there more elegant ways of achieving this?


My first thought is you should abandon the variable approach 
and just use an abstract function that returns the value for 
each child via overriding. It won't be static, but it also 
won't take any per-instance memory.


Sounds like a good approach. I'll try this out for sure.


[Issue 17976] New: core.exception.AssertError@ddmd/dsymbolsem.d(1624)

2017-11-09 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17976

  Issue ID: 17976
   Summary: core.exception.AssertError@ddmd/dsymbolsem.d(1624)
   Product: D
   Version: D2
  Hardware: All
OS: All
Status: NEW
  Severity: normal
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: issues.dl...@jmdavisprog.com

I guess that this is technically an ICE, but it doesn't really cause problems.
The compiler really shouldn't be failing an assertion though. This code:

--
struct S
{
this(string a, string a)
{
}
}

void main()
{
}
--

results in this error

test.d(3): Error: constructor test.S.this parameter this.a is already defined
core.exception.AssertError@ddmd/dsymbolsem.d(1624): Assertion failure


The error message is correct, but the AssertError that happens afterwards
shouldn't be happening.

--