Re: How Different Are Templates from Generics

2019-10-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, October 12, 2019 9:48:02 PM MDT jmh530 via Digitalmars-d-learn 
wrote:
> On Saturday, 12 October 2019 at 21:44:57 UTC, Jonathan M Davis
>
> wrote:
> > [snip]
>
> Thanks for the reply.
>
> As with most people, I don't write a lot of D code that uses
> classes that much.
>
> The use case I'm thinking of is with allocators, which - to be
> honest - is not something I deal with much in my own code.
> Basically, some of the examples have stuff like
> ScopedAllocator!Mallocator, which would imply that there is a
> different ScopedAllocator for each allocator. However, if you
> apply Java's generics, then you would just have one. Not sure if
> it would make any kind of difference in real-life code, but still
> interesting to think about.

I wouldn't think that there would be enough different allocator types to
matter much. Certainly, the amount of code that gets generated by templates
for dealing with stuff like ranges would dwarf it. If program size really
becomes a problem, then examining how code uses templates and trying to
reduce how much they're used could certainly have an impact, but I'd expect
it to be fairly rare that attempting to emulate Java's generics would help
much - especially since it would only work when classes were involved. The
main place that such an approach would have much chance of having an impact
would be with regards to container implementations when the code puts a lot
of different types of class objects inside of containers, and even that
would easily be dwarfed by all of the other template usage in your typical D
program. For Java's approach to make much sense, you'd probably have to be
writing very Java-like code.

- Jonathan M Davis





Re: How Different Are Templates from Generics

2019-10-12 Thread jmh530 via Digitalmars-d-learn
On Saturday, 12 October 2019 at 21:44:57 UTC, Jonathan M Davis 
wrote:

[snip]



Thanks for the reply.

As with most people, I don't write a lot of D code that uses 
classes that much.


The use case I'm thinking of is with allocators, which - to be 
honest - is not something I deal with much in my own code. 
Basically, some of the examples have stuff like 
ScopedAllocator!Mallocator, which would imply that there is a 
different ScopedAllocator for each allocator. However, if you 
apply Java's generics, then you would just have one. Not sure if 
it would make any kind of difference in real-life code, but still 
interesting to think about.


Re: How Different Are Templates from Generics

2019-10-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, October 12, 2019 2:11:28 PM MDT jmh530 via Digitalmars-d-learn 
wrote:
> On Friday, 11 October 2019 at 17:50:42 UTC, Jonathan M Davis
>
> wrote:
> > [snip]
>
> A very thorough explanation!
>
> One follow-up question: would it be possible to mimic the
> behavior of Java generics in D?

Yes, but it's unlikely that it would make any sense to do so. You'd
basically have to do something like

auto foo(T)(T obj)
if(is(T : Object) && !is(T == Object))
{
return foo(cast(Object)obj);
}

auto foo(Object obj)
{
...
}

And for containers, you'd basically end up with a templated container that
was just a wrapper around a non-templated container that operated on Object.

If you went with such an approach, you'd get less code in the binary, but
you'd also end up with a deeper call stack because of all of the wrappers
needed to add the casts for you.

However, since Object can't do much of anything, having code that operates
on Object isn't usually very useful. You could have the code use a different
base class that had whatever operations you wanted, but you're still adding
a fair bit of extra machinery just to avoid a few template instantiations.

And since idiomatic D doesn't use classes much (rather, best practice is to
use a struct unless you need polymorphism or you need something to always be
a reference type), and it uses templates quite heavily (that's especially
true with range-based code), it would be pretty bizarre to try and use
Java's approach in D.

- Jonathan M Davis





Re: Blog Post #77: Notebook, Part I

2019-10-12 Thread Ron Tarrant via Digitalmars-d-learn
On Saturday, 12 October 2019 at 16:34:01 UTC, Carsten Schlote 
wrote:



Nice work, Ron!


Thanks, Carsten.

I'm just converted some of you examples into dub based 
projects, and compiled and run them a normal intel PC and a 
Raspberry. As a prerequisite I had to install the following on 
a Raspian Lite installation (from a NOOP sdcard, no GUI)


Well, that's pretty cool.

Ever considered to provide such dub based examples on 
GitHub/GitLab/... for easy access?


Yup! It's coming. Also, module-based stuff.

Such source examples could be very helpful for GTK newbies. And 
dub projects should work on Windows as well.


Yup, absolutely.




Re: How Different Are Templates from Generics

2019-10-12 Thread jmh530 via Digitalmars-d-learn
On Friday, 11 October 2019 at 17:50:42 UTC, Jonathan M Davis 
wrote:

[snip]


A very thorough explanation!

One follow-up question: would it be possible to mimic the 
behavior of Java generics in D?


Re: selective tests

2019-10-12 Thread Seb via Digitalmars-d-learn

On Saturday, 12 October 2019 at 13:50:46 UTC, IGotD- wrote:
On Saturday, 12 October 2019 at 09:52:59 UTC, Jonathan M Davis 
wrote:

[...]


This would be helpful. About all C++ unit test frameworks have 
named test and you can select a specific one or several in the 
command line. Very useful when you work on a specific test and 
other tests take some time to finish.


having

unittest OptionalName
{
   ...
}

would actually help a lot. I don't think this would be very 
difficult to implement and wouldn't break anything.


It wouldn't be hard, but someone would need to write a DIP for 
it. In the meantime you can use 
https://github.com/atilaneves/unit-threaded.


Re: Blog Post #77: Notebook, Part I

2019-10-12 Thread Carsten Schlote via Digitalmars-d-learn

On Tuesday, 8 October 2019 at 10:00:00 UTC, Ron Tarrant wrote:
Today starts a new series on the Notebook widget. Over the next 
few weeks, we'll dig in deep, looking at single-tab and 
multiple-tab demos, customizing the look of the actual tabs, 
adding and removing tabs... a whole ton of stuff. Sounds like 
fun, right?


Come on over and check it out: 
https://gtkdcoding.com/2019/10/08/0077-notebook-i-basics.html


Nice work, Ron!

I'm just converted some of you examples into dub based projects, 
and compiled and run them a normal intel PC and a Raspberry. As a 
prerequisite I had to install the following on a Raspian Lite 
installation (from a NOOP sdcard, no GUI)


$ sudo apt install libgstreamer-plugins-base1.0-0 
libgstreamer-plugins-bad1.0-0


I also installed dub and ldc2 on it:

$ sudo apt install dub ldc2

I prepared a new project

$ dub init gtk_test_0 gtk-d

and replaced the contents of source/app.d with your very first 
example 'Hello GtkD Imperative'.


Assuming you logged in with 'ssh -YXC pi@', you can 
compile and start it with


$ dub run

A nice empty GTK window should appear now. Of course a normal 
Raspbian installation with GUI should work as well.


Ever considered to provide such dub based examples on 
GitHub/GitLab/... for easy access?


Such source examples could be very helpful for GTK newbies. And 
dub projects should work on Windows as well.


Carsten



Re: selective tests

2019-10-12 Thread IGotD- via Digitalmars-d-learn
On Saturday, 12 October 2019 at 09:52:59 UTC, Jonathan M Davis 
wrote:
On Saturday, October 12, 2019 2:18:02 AM MDT Martin Brezeln via 
Digitalmars- d-learn wrote:
Is it possible to execute only certain modules or tests which 
are defined in certain directories?


For example, in go one can run "go test ./XYZ" to execute ony 
tests in ./XYZ or "go test ./..." to execute all the tests in 
and under the current directory.


Please don't get me wrong, i do not wish to start a discussion
about doing things the "go way". I am asking if there is a way 
to

achieve a similar result with dub (or maybe without dub?
樂)


The default test runner does not support running only some of 
the tests. It simply runs all of the unittest blocks in the 
binary prior to running main, and tests only get skipped when 
they're either not compiled in or when a previous unittest 
block in that module failed.


You could set up your build so that you had targets which only 
compiled specific directories so that the only unit tests that 
were run were the ones in those directories, but I don't think 
that it's possible to do anything like that with dub. 
Certainly, if it is, it would be a royal pain to set up.


Really, if you want to control which tests get run instead of 
simply always running them all, then you'll need to use an 
alternate test runner which supports that. There are a few test 
runners available on code.dlang.org, and I expect that at least 
one of them supports that (probably multiple do).


- Jonathan M Davis


This would be helpful. About all C++ unit test frameworks have 
named test and you can select a specific one or several in the 
command line. Very useful when you work on a specific test and 
other tests take some time to finish.


having

unittest OptionalName
{
   ...
}

would actually help a lot. I don't think this would be very 
difficult to implement and wouldn't break anything.





Re: What is the recommend tool for D linting from CI pipelines? Does such a tool exist at all?

2019-10-12 Thread Carsten Schlote via Digitalmars-d-learn

On Saturday, 12 October 2019 at 11:37:12 UTC, Andre Pany wrote:
- With next Dub version, d-scanner is integrated. Just call dub 
lint within your dub project folder. This also makes the CI use 
case much greater.


Sound like the best solution. Using dub seems to be the best way 
for build D apps, libs and even ddox. Having built-in linting 
with a proper return value and some usable output formats would 
make it perfect.


That said, we are just at the starting point of using d-scanner 
in CI. There might be here and there missing features.


That would be no problem, as long as things are evolving ;-)

Contribution in form of suggestions or even pull requests are 
highly welcome.


Yes, there are still some ideas. E.g. some kind of support to 
directly compile C source files and link their objects with the 
rest would be fine. It turned out, that sometimes it is much 
easier to have some thin C layer to call other libs, and just 
call the extern(C) wrapper function. This gives better control. 
For now, we use the preBuild/preGenerate hooks to call make on 
such files.


Carsten


Re: What is the recommend tool for D linting from CI pipelines? Does such a tool exist at all?

2019-10-12 Thread Andre Pany via Digitalmars-d-learn
On Saturday, 12 October 2019 at 04:55:02 UTC, Carsten Schlote 
wrote:

Hi,

many companies started to use CI pipelines, and as part of 
their pipelines they introduced mandatory linting for source 
code.


There are tools for many languages, esp. for C/C++. These tools 
usually return '0' on success, and something else on linting 
errors. That is pretty much the standard POSIX way to return a 
resultcode  back to the calling programm/shell. The CI pipeline 
aborts, when something else then '0' is returned.


However, for the D language I found only 'dscanner'. It has a 
report option, but seems to return always a '0'. I have to 
check the JSON style output to find out, if any issues are 
reported or not. This makes things more complicated than needed.


So, my simple question are:
 * What is the recommended way to do automated linting for D 
sources in CI pipelines or similiar?
 * Is there any other tool than dscanner to do serious linting 
for D language?


Carsten


There were many additions in this area in the recent time.

- Jenkins Next Generation Warnings Plugin now supports D-Scanner 
JSON output. Therefore you can instrument the Jenkins plugin to 
stop if there are errors.


- D-Scanner allows you (upcoming version) to output SonarQube 
generic issues json instead of the default json. You can import 
it into a bare SonarQube (no d plugin needed). And also SonarQube 
voter can stop your build depending on your findings.


- With next Dub version, d-scanner is integrated. Just call dub 
lint within your dub project folder. This also makes the CI use 
case much greater.


That said, we are just at the starting point of using d-scanner 
in CI. There might be here and there missing features. 
Contribution in form of suggestions or even pull requests are 
highly welcome.


Kind regards
Andre


Re: selective tests

2019-10-12 Thread Dennis via Digitalmars-d-learn
On Saturday, 12 October 2019 at 09:52:59 UTC, Jonathan M Davis 
wrote:
You could set up your build so that you had targets which only 
compiled specific directories so that the only unit tests that 
were run were the ones in those directories, but I don't think 
that it's possible to do anything like that with dub. 
Certainly, if it is, it would be a royal pain to set up.


I think you can do it with sub packages:

dub.sdl
```
name "bread-and-butter"
description "the best thing since slided bread"
sourceFiles ""
dependency "bread-and-butter:bread"  version="*"
dependency "bread-and-butter:butter" version="*"

subPackage {
name "bread"
sourceFiles "source/bread/*.d"

}

subPackage {
name "butter"
sourcePaths "source/butter"
dependency "bread-and-butter:bread" version="*"
}
```

Then you can run tests like:

```
dub test bread-and-butter
dub test bread-and-butter:bread
dub test bread-and-butter:butter
```

An annoying thing about sub packages though is that you may have 
to duplicate lots of settings.
(hint hint 
https://forum.dlang.org/thread/fppszpfvbnvioeiak...@forum.dlang.org)


Re: selective tests

2019-10-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, October 12, 2019 2:18:02 AM MDT Martin Brezeln via Digitalmars-
d-learn wrote:
> Is it possible to execute only certain modules or tests which are
> defined in certain directories?
>
> For example, in go one can run "go test ./XYZ" to execute ony
> tests in ./XYZ or "go test ./..." to execute all the tests in and
> under the current directory.
>
> Please don't get me wrong, i do not wish to start a discussion
> about doing things the "go way". I am asking if there is a way to
> achieve a similar result with dub (or maybe without dub?
> 樂)

The default test runner does not support running only some of the tests. It
simply runs all of the unittest blocks in the binary prior to running main,
and tests only get skipped when they're either not compiled in or when a
previous unittest block in that module failed.

You could set up your build so that you had targets which only compiled
specific directories so that the only unit tests that were run were the ones
in those directories, but I don't think that it's possible to do anything
like that with dub. Certainly, if it is, it would be a royal pain to set up.

Really, if you want to control which tests get run instead of simply always
running them all, then you'll need to use an alternate test runner which
supports that. There are a few test runners available on code.dlang.org, and
I expect that at least one of them supports that (probably multiple do).

- Jonathan M Davis






Play free with Gamesbx

2019-10-12 Thread games bxgames via Digitalmars-d-learn

hello reader
The days of technology and our lives gradually change with the 
pace of development, and we work from morning till night to never 
take a rest to catch up with life. It is not uncommon because we 
need to work to build a better life. It is so tiring that it 
keeps repeating every day making us uncomfortable and unhappy. 
But it can't be that we stop, so today I introduce you a quick 
web game to help you relax is GamesBX
This is a fast games category suitable for all players with many 
different game genres. in which the two main games io and Html5 
games are continuously updated every day. With the goal to help 
players entertain and relax, Gamesbx improves and updates the 
game types every day to bring to the players, the special thing 
here is when you play the game you do not need to waste time 
registering. or lose any fee and still be able to connect with 
other players in the world in group play mode. That is wonderful 
is not it. Apart from this aspect as we know it, online games 
have become a popular form of entertainment used by many people. 
Recent studies are done by some famous scientific and research 
organizations. have shown that playing video games can help 
improve the quality of life that increases brain stimulation, 
reflexes, and assertiveness.
Gamesbx will not change your real life, but it will definitely 
bring you the best entertainment and many more interesting things 
to improve your mood every day after stressful working hours.


Please come to gamesbx2.info to experience it, have a nice day 
and have lots of fun

-- -
GamesBX2 places entertainment and relaxation


selective tests

2019-10-12 Thread Martin Brezeln via Digitalmars-d-learn
Is it possible to execute only certain modules or tests which are 
defined in certain directories?


For example, in go one can run "go test ./XYZ" to execute ony 
tests in ./XYZ or "go test ./..." to execute all the tests in and 
under the current directory.


Please don't get me wrong, i do not wish to start a discussion 
about doing things the "go way". I am asking if there is a way to 
achieve a similar result with dub (or maybe without dub?

樂)