Re: How to enable verbose logging during application run

2018-03-17 Thread Venkat via Digitalmars-d-learn

Thankyou.


Re: how to make private class member private

2018-03-17 Thread Amorphorious via Digitalmars-d-learn

On Saturday, 17 March 2018 at 23:54:22 UTC, psychoticRabbit wrote:

On Saturday, 17 March 2018 at 21:33:01 UTC, Adam D. Ruppe wrote:

On Saturday, 17 March 2018 at 21:22:44 UTC, arturg wrote:

maybe extend that to a list of types?


this is basically what C++ friend does and D was trying to 
avoid the complexity of


Really, the complexity of 'friend' comes from people abusing it.

In D, I would prefer no breaking change here. Leave private as 
it is.


Just a simple attribute that only applies within a class, and 
only to private members within that class.


@strictly private string firstName_;

Nothing outside of the class, not even the module, can access 
this now. It's all encapsulated.


It breaks nothing (AFAIK).
It's very clear what the intention is here.
It's an easy attribute to remember.
It restores the principle of class enscapsulation within a 
module, for when it's really needed.


Now D programmers would have the best of both worlds.



Why do you insist that you know how everything works and you are 
the harbinger of truth. The fact is, you don't know squat about 
what you are talking about and you just want to conform D to your 
naive ignorant understanding of programming so you don't get 
confused rather than learning and accepting D for what it does, 
which is do everything better than C/C++. You keep trying to make 
it in to C/C++, the the hell don't you just go use C/C++ then?


No one is going to listen to you. Your ignorance is pointed out 
by many that have used D far longer than you have and you think 
you can come in and point out all the things wrong without having 
any experience with it.


The fact is, the creator of the class is also the creator of the 
module.. and preventing him from having full access to the class 
is ignorant. He doesn't need to encapsulate himself. 
Encapsulation is ONLY meant to reduce dependencies. If the 
programmer, probably someone like you, can't trust himself to 
understand his own code then he shouldn't be coding.


If you don't like it, just write one class per module and don't 
have any free functions... it solves your problem and it doesn't 
use your shitty "solution". No one is forcing you to access your 
class outside the class but inside the module.


The fact is you are ignorant of what you speak about and that is 
99% of the problem. If you don't like how D does it, go use 
another language that does it the way you "think"(if you could 
call it that) is correct.


Many of the thing D does is learned from the mistakes of C/C++... 
and for you to pretend that your insignificant self who has never 
wrote a compiler much less read the specs has a clue about the 
ramifications of the changes is moronic.


Your only reason for not liking it is because you "don't like 
it"... how moronic.


"Mmm.. I don't think I like it.

I feel you should be able to make a member of a class, private, 
regardless of where the class is located. This seems to break the 
concept of class encapsulation.


No. I don't like it at all.
"

Yet you have no clue... You "learned"(brainwashed" that 
encapsulation means private members of classes cannot be accessed 
from C++ and because D provides a more complex rule that you 
can't seem to grasp(but which is very simple and no other human 
that has used D has had issues with) you say that D is wrong 
rather than that you or C++ is wrong.


The fact is, you are a moron. It's not because of this one issue 
but because of your mentality of which this is just an example. 
I'm sure you have the same thing with many issues in your life 
and you go strutting around like you own the place telling 
everyone what is wrong with how things are done when you yourself 
have no clue.


Want me to prove it to you?

You say:
"I feel you should be able to make a member of a class, private, 
regardless of where the class is located. This seems to break the 
concept of class encapsulation.

"

Yet, really, what you mean is that it breaks the concept of class 
that you learned in programming 101 that had to do with C++. You 
don't have a clue about logic and qualification. Maybe you are 
confused and you thought D was C++?



You know, if you go to Rome... ah never mind, you won't get it...






Re: how to make private class member private

2018-03-17 Thread psychoticRabbit via Digitalmars-d-learn

On Saturday, 17 March 2018 at 21:33:01 UTC, Adam D. Ruppe wrote:

On Saturday, 17 March 2018 at 21:22:44 UTC, arturg wrote:

maybe extend that to a list of types?


this is basically what C++ friend does and D was trying to 
avoid the complexity of


Really, the complexity of 'friend' comes from people abusing it.

In D, I would prefer no breaking change here. Leave private as it 
is.


Just a simple attribute that only applies within a class, and 
only to private members within that class.


@strictly private string firstName_;

Nothing outside of the class, not even the module, can access 
this now. It's all encapsulated.


It breaks nothing (AFAIK).
It's very clear what the intention is here.
It's an easy attribute to remember.
It restores the principle of class enscapsulation within a 
module, for when it's really needed.


Now D programmers would have the best of both worlds.



Re: How to enable verbose logging during application run

2018-03-17 Thread rjframe via Digitalmars-d-learn
On Sat, 17 Mar 2018 22:37:36 +, Venkat wrote:

> Sorry posted the above message by accident.
> 
> I am running a vibed app using `dub` command. But it produces no logging
> what so ever when requests are made. The server returns http error codes
> but it doesn't log anything to the console. How do I make it show me a
> lot more detail than it is doing now ?
> 
> For example, in a Java webapp, one would change the logging level to
> debug if a logging library is configured.


vibe.core.log has a setLogLevel function.

http://vibed.org/api/vibe.core.log/setLogLevel
http://vibed.org/api/vibe.core.log/LogLevel


Also, the URLRouter class has a getAllRoutes method; if needed, writing 
that to the terminal can verify the routes are what you expect.


Re: How to enable verbose logging during application run

2018-03-17 Thread Venkat via Digitalmars-d-learn

Sorry posted the above message by accident.

I am running a vibed app using `dub` command. But it produces no 
logging what so ever when requests are made. The server returns 
http error codes but it doesn't log anything to the console. How 
do I make it show me a lot more detail than it is doing now ?


For example, in a Java webapp, one would change the logging level 
to debug if a logging library is configured.





How to enable verbose logging during application run

2018-03-17 Thread Venkat via Digitalmars-d-learn
I am running a vibed app using `dub` command. But it produces no 
logging what so ever when re


Re: how to make private class member private

2018-03-17 Thread Adam D. Ruppe via Digitalmars-d-learn

On Saturday, 17 March 2018 at 21:22:44 UTC, arturg wrote:

maybe extend that to a list of types?


this is basically what C++ friend does and D was trying to avoid 
the complexity of


Re: how to make private class member private

2018-03-17 Thread arturg via Digitalmars-d-learn

On Saturday, 17 March 2018 at 14:16:19 UTC, bauss wrote:
I don't like the name @deny, personally I would rather see the 
private attribute changed to something like:


private(true) // The member is oly visible to its parent.

private(false) // Same as just "private", visible to whole 
module.


Could be specialized to something like:

private(this) // Same as private(true)

private(module) // Same as private(false)



maybe extend that to a list of types?

private(typeof(this), Foo, Bar)

would mean only typeof(this), Foo and Bar from the same module 
have access.


Re: Can't add ubytes together to make a ubyte... bug or feature?

2018-03-17 Thread Ali Çehreli via Digitalmars-d-learn

On 03/17/2018 11:36 AM, Jonathan wrote:

`(a+b)&0xff` What is this syntax?!  Could you give a link to this in the 
D documentation?


Here is my description of bitwise AND:


http://ddili.org/ders/d.en/bit_operations.html#ix_bit_operations.&,%20bitwise%20and

The section titled "Masking" on the same page explains what &0xff part 
means.



I am not even sure how to look it up...


I hope my index section is useful in such cases. Just search for the & 
character there:


  http://ddili.org/ders/d.en/ix.html

Yes, there are many meanings of the & character but I think it's still 
useful. :)


Ali


Re: Can't add ubytes together to make a ubyte... bug or feature?

2018-03-17 Thread bauss via Digitalmars-d-learn
On Saturday, 17 March 2018 at 18:56:55 UTC, Dominikus Dittes 
Scherkl wrote:

On Saturday, 17 March 2018 at 18:36:35 UTC, Jonathan wrote:
On Tuesday, 19 January 2016 at 23:36:14 UTC, Adam D. Ruppe 
wrote:
On Tuesday, 19 January 2016 at 22:12:06 UTC, Soviet Friend 
wrote:
I don't care if my computer needs to do math on a 4 byte 
basis, I'm not writing assembly.


x86 actually doesn't need to do math that way, if you were 
writing assembly, it would just work. This is just an 
annoying rule brought over by C.



Can I prevent the initial implicit casts?


Nope, though you can help tell the compiler that you want it 
to fit there by doing stuff like


ubyte a = 200;
ubyte b = 100;
ubyte c = (a+b)&0xff;

or something like that, so the expression is specifically 
proven to fit in the byte with compile time facts.



`(a+b)&0xff` What is this syntax?!  Could you give a link to 
this in the D documentation?  I am not even sure how to look 
it up...

& is the normal binary and operation, same in C, C++, Java, ...
0xFF is a hexadecimal constant (255), which the compiler knows 
fit in an ubyte

So what do you not understand about this syntax?


I guess he doesn't understand bitwise operations.

Also don't you mean bitwise and?


Re: Can't add ubytes together to make a ubyte... bug or feature?

2018-03-17 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn

On Saturday, 17 March 2018 at 18:36:35 UTC, Jonathan wrote:
On Tuesday, 19 January 2016 at 23:36:14 UTC, Adam D. Ruppe 
wrote:
On Tuesday, 19 January 2016 at 22:12:06 UTC, Soviet Friend 
wrote:
I don't care if my computer needs to do math on a 4 byte 
basis, I'm not writing assembly.


x86 actually doesn't need to do math that way, if you were 
writing assembly, it would just work. This is just an annoying 
rule brought over by C.



Can I prevent the initial implicit casts?


Nope, though you can help tell the compiler that you want it 
to fit there by doing stuff like


ubyte a = 200;
ubyte b = 100;
ubyte c = (a+b)&0xff;

or something like that, so the expression is specifically 
proven to fit in the byte with compile time facts.



`(a+b)&0xff` What is this syntax?!  Could you give a link to 
this in the D documentation?  I am not even sure how to look it 
up...

& is the normal binary and operation, same in C, C++, Java, ...
0xFF is a hexadecimal constant (255), which the compiler knows 
fit in an ubyte

So what do you not understand about this syntax?


Re: Can't add ubytes together to make a ubyte... bug or feature?

2018-03-17 Thread Jonathan via Digitalmars-d-learn

On Tuesday, 19 January 2016 at 23:36:14 UTC, Adam D. Ruppe wrote:
On Tuesday, 19 January 2016 at 22:12:06 UTC, Soviet Friend 
wrote:
I don't care if my computer needs to do math on a 4 byte 
basis, I'm not writing assembly.


x86 actually doesn't need to do math that way, if you were 
writing assembly, it would just work. This is just an annoying 
rule brought over by C.



Can I prevent the initial implicit casts?


Nope, though you can help tell the compiler that you want it to 
fit there by doing stuff like


ubyte a = 200;
ubyte b = 100;
ubyte c = (a+b)&0xff;

or something like that, so the expression is specifically 
proven to fit in the byte with compile time facts.



`(a+b)&0xff` What is this syntax?!  Could you give a link to this 
in the D documentation?  I am not even sure how to look it up...


Re: Convert output range to input range

2018-03-17 Thread John Chapman via Digitalmars-d-learn

On Saturday, 17 March 2018 at 17:16:40 UTC, David Nadlinger wrote:

On Friday, 16 March 2018 at 07:57:04 UTC, John Chapman wrote:
I need to write to a range created with outputRangeObject, 
then read from it. Is there a way to convert it to an input 
range?


Could you illustrate your problem a bit further?


I'm trying to replace the old std.streams in my app with ranges. 
I'm interfacing with a networking library to which I supply a 
callback that when invoked provides the requested data. I write 
that data to an output range, but later on I need to read that 
data from the range too - which of course you can't do.


So what I'm looking for is the range-based equivalent of a 
MemoryStream.




Re: how to make private class member private

2018-03-17 Thread bauss via Digitalmars-d-learn

On Saturday, 17 March 2018 at 15:02:21 UTC, psychoticRabbit wrote:

On Saturday, 17 March 2018 at 14:16:19 UTC, bauss wrote:


I don't like the name @deny .


how about:

@reallyis private string firstName_;

mmm..perhaps not... then how about...

@strictly private string firstName_;


Still introduces a new attribute. D already has a lot of 
attributes and it goes against how every other attribute for 
visibility works.


That's why my suggestion would work better, because the package 
attribute already works like that.


Re: Convert output range to input range

2018-03-17 Thread David Nadlinger via Digitalmars-d-learn

On Friday, 16 March 2018 at 07:57:04 UTC, John Chapman wrote:
I need to write to a range created with outputRangeObject, then 
read from it. Is there a way to convert it to an input range?


Could you illustrate your problem a bit further?

In the literal sense, converting from an output to an input range 
would require using coroutines (where .empty() blocks until the 
output range has supplied the next element).


However, I suspect what you want to do is to write results from 
the output range to a buffer (e.g. an Appender) first, and after 
that – or possibly every so often in chunks – process the results 
further?


 — David


Re: How to build static linked executable

2018-03-17 Thread Seb via Digitalmars-d-learn

On Saturday, 17 March 2018 at 14:44:42 UTC, zunkree wrote:

Hi,

Is there a way to build static linked executable with dub for 
vibe-d based app?


Regards,
zunkree


Yes, use -static

Here's how we build the DTour: 
https://github.com/dlang-tour/core/blob/master/dub.sdl


Re: How to build static linked executable

2018-03-17 Thread Seb via Digitalmars-d-learn

On Saturday, 17 March 2018 at 15:42:06 UTC, Seb wrote:

On Saturday, 17 March 2018 at 14:44:42 UTC, zunkree wrote:

Hi,

Is there a way to build static linked executable with dub for 
vibe-d based app?


Regards,
zunkree


Yes, use -static

Here's how we build the DTour: 
https://github.com/dlang-tour/core/blob/master/dub.sdl


I forgot to mention that -static is an LDC-only flag, but you 
wouldn't want to use DMD for an optimized application anyhow.


Re: how to make private class member private

2018-03-17 Thread psychoticRabbit via Digitalmars-d-learn

On Saturday, 17 March 2018 at 14:16:19 UTC, bauss wrote:


I don't like the name @deny .


how about:

@reallyis private string firstName_;

mmm..perhaps not... then how about...

@strictly private string firstName_;




How to build static linked executable

2018-03-17 Thread zunkree via Digitalmars-d-learn

Hi,

Is there a way to build static linked executable with dub for 
vibe-d based app?


Regards,
zunkree


Re: how to make private class member private

2018-03-17 Thread bauss via Digitalmars-d-learn

On Saturday, 17 March 2018 at 11:08:27 UTC, psychoticRabbit wrote:
On Saturday, 17 March 2018 at 09:18:13 UTC, Nick Treleaven 
wrote:
It's a language design decision as to whether a particular 
feature is worth supporting. I would like this feature too 
though. I'm not sure how much compiler complexity would be 
added by having another visibility modifier.




D could add an new attribute to class members:  @deny

A @deny attribute can come before a classes private member, to 
indicate that the private member is to remain private, even 
within the module.


Cause sure, it nice to be among friends, but you don't want 
your friends knowing every thought that is going through your 
mind! Sometimes, somethings, just need to remain private.


@deny private string _userName;

now... _userName is no longer accessible at the module level, 
and class encapsulation is restored.


If had I any clue about compilers, I'd think this through more 
;-)


I don't like the name @deny, personally I would rather see the 
private attribute changed to something like:


private(true) // The member is oly visible to its parent.

private(false) // Same as just "private", visible to whole module.

Could be specialized to something like:

private(this) // Same as private(true)

private(module) // Same as private(false)

That way it can be introduced without breaking changes and looks 
cleaner since it wouldn't be yet another attribute.


Really it's just an extension to the already existing attribute.

This feature should be relatively easy to implement since it's 
similar to the "package" attribute, which also takes a value as 
the module name.


Re: how to make private class member private

2018-03-17 Thread psychoticRabbit via Digitalmars-d-learn

On Saturday, 17 March 2018 at 09:18:13 UTC, Nick Treleaven wrote:
It's a language design decision as to whether a particular 
feature is worth supporting. I would like this feature too 
though. I'm not sure how much compiler complexity would be 
added by having another visibility modifier.




D could add an new attribute to class members:  @deny

A @deny attribute can come before a classes private member, to 
indicate that the private member is to remain private, even 
within the module.


Cause sure, it nice to be among friends, but you don't want your 
friends knowing every thought that is going through your mind! 
Sometimes, somethings, just need to remain private.


@deny private string _userName;

now... _userName is no longer accessible at the module level, and 
class encapsulation is restored.


If had I any clue about compilers, I'd think this through more ;-)



Logging Function Parameters

2018-03-17 Thread dom via Digitalmars-d-learn

Hi,

I am looking for a method to log the current function name + 
parameters.
Getting the name of the current function is simply possible with 
__PRETTY_FUNCTION__
Is there some possibility to generically access the parameters of 
a function such that they can be iterated and printed out?


currently i have something like this:
log.info(__PRETTY_FUNCTION__,  " ", parameter1, " ", parameter2);

i would like to get to something like that:
log.info(__PRETTY_FUNCTION__,  " ", parameters.join(", "));




Re: how to make private class member private

2018-03-17 Thread Nick Treleaven via Digitalmars-d-learn
On Tuesday, 13 March 2018 at 13:59:00 UTC, Steven Schveighoffer 
wrote:
If you limit to class members, then you have to do something 
like C++ friends, which are unnecessarily verbose.


Not if you also have a module-level visibility modifier, which 
could have been `module`.


IMO, the module-level encapsulation is the right choice. It 
helps with a lot of key features:


1. IFTI factory methods


Aren't these mainly because constructors can't use IFTI, unlike 
C++17, and because nullary struct constructors are banned?



2. unittests


Documented unittests should not be allowed to use private 
symbols, I just filed this:

https://issues.dlang.org/show_bug.cgi?id=18623


Re: how to make private class member private

2018-03-17 Thread Nick Treleaven via Digitalmars-d-learn

On Tuesday, 13 March 2018 at 05:11:48 UTC, psychoticRabbit wrote:
If you have access to the module source, you have access to 
the source of types inside it. Making the module the lowest 
level of encapsulation makes sense from that perspective.


There are two problems I see:

1st - D has broken the concept of class encapsulation, simply 
for convenience at the module level. Not good in my opinion.


It's a language design decision as to whether a particular 
feature is worth supporting. I would like this feature too 
though. I'm not sure how much compiler complexity would be added 
by having another visibility modifier.


I'm surprised how many people here ignore the advantage of being 
able to modify your class/struct fields without the chance of 
breaking template code that might not even be instantiated by a 
unit test. (And no, the answer to this isn't fix your tests, 
because if that's your attitude, why bother with static typing, 
just use duck typing, the unit tests will catch any bugs). In 
theory this and other generic unit test issues could be 
comprehensively solved by having a Rust-like traits feature.


2nd - C++/C#/Java programmers will come to D, use the same 
syntax, but get very different semantics. Not good in my 
opinion. (i.e. I only realised private was not private, by 
accident).


D has made many good design decisions. I do not see this as one 
of them.


+1, D should have used a different keyword, such as `module`. It 
is a classic source of confusion for programmers familiar with 
many statically typed languages, and it comes up regularly here. 
It is a syntax issue, semantically the feature is better than 
just having true private.


Re: Convert output range to input range

2018-03-17 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, March 17, 2018 06:58:04 Dukc via Digitalmars-d-learn wrote:
> On Friday, 16 March 2018 at 08:07:09 UTC, Jonathan M Davis wrote:
> > For instance, std.array.Appender is an output range, and you
> > get a dynamic array out of it, which would be an input range.
> > So, if you have control over what output range you're dealing
> > with, the simplest would be to just use Appender.
>
> I think it's worth warning that appending on an array may
> invalidate all copies of it. Meaning that you should not append
> on an array while you're iterating over it, unless iterating by
> the original copy of the array. Note that foreach loop copies the
> range by default. Pass refRange(*array) to foreach instead.

Appending to a dynamic array doesn't invalidate anything. It just results in
a new buffer being allocated and the dynamic array being changed to point to
it instead of the dynamic array does not have enough capacity to append in
place. Any other dynamic arrays which were slices of the previous buffer
still refer to it and are perfectly valid.

Yes, if you want to treat a dynamic array as a reference type, it's not
going to work to simply pass around a dynamic array, because dynamic arrays
are pseudo-reference types and not reference types, and if you want a
reference type, you're going to have to wrap the dynamic array in another
type, but the fact that they're pseudo-reference types does not mean that
anything is invalidated when appending.

Now, doing something like iterating over a dynamic array with a foreach loop
and then appending to it in that same loop means that you're really
operating on two dynamic arrays, because the loop is slices the dynamic
array and is thus iterating over another dynamic array which (at least
initially) refers to the same memory, and the appending that you're doing
won't affect it. So, you do have to be careful about appending while
iterating if you really want to be appending to the same dynamic array that
you're iterating over, but everything involved will be valid regardless. It
just may not have the behavior you want, because the dynamic array has been
sliced.

In any case, based on the OP's question, it was my assumption that they
intended to fully write to the output range and then operate on the results
as on input range, which then has none of the problems associated with
trying to put while you pop. If they want to put while they're popping, then
things get far more complicated, and a dynamic array is probably not the
best solution whether Appender is used or not.

- Jonathan M Davis



Re: Convert output range to input range

2018-03-17 Thread Dukc via Digitalmars-d-learn

On Friday, 16 March 2018 at 08:07:09 UTC, Jonathan M Davis wrote:
For instance, std.array.Appender is an output range, and you 
get a dynamic array out of it, which would be an input range. 
So, if you have control over what output range you're dealing 
with, the simplest would be to just use Appender.


I think it's worth warning that appending on an array may 
invalidate all copies of it. Meaning that you should not append 
on an array while you're iterating over it, unless iterating by 
the original copy of the array. Note that foreach loop copies the 
range by default. Pass refRange(*array) to foreach instead.