Re: Why is stdio ... stdio?

2018-11-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, November 10, 2018 7:51:36 PM MST Adam D. Ruppe via Digitalmars-
d-learn wrote:
> On Saturday, 10 November 2018 at 23:29:12 UTC, Jonathan M Davis
>
> wrote:
> > The fact that they got added to ddoc just further degrades it
> > as a proper, macro-based markup language.
>
> The backticks were added to ddoc because they enabled something
> that was *virtually impossible* in ddoc before - proper character
> escaping. It actually originally had nothing to do with syntax
> sugar nor even with presentation - just the constant repetition
> of that myth has made it into a bit of reality.

It may be that a feature was needed to do better character escaping, but
backticks really don't fit in with ddoc as a whole, and they've only
encouraged folks to try and add further markdown features to ddoc, which
IMHO, is incredibly negative. On the whole, the worst features of ddoc are
the ones that act least like macros. They're the ones that are most
"magical" and the ones that generally have to be fought and worked around.
Adding more markdown features just makes things worse. As such, I very much
wish that we'd found a different way to fix the character escaping problem.

Regardless, none of that has anything to do with what we do with syntax
highlighting in the newsgroup's web interface.

> On the forum though, characters are already escaped properly, so
> there's no need here. Syntax highlighting for larger blocks is
> something I'm meh on - I don't really care either way if we
> wanted to do it.

I don't really care what the web interface tries to highlight, but I don't
want it doing anything that encourages people to start putting markdown in
their messages, because I don't use the web interface, I don't want to have
to see markdown in the middle of plain text messages any more than I want to
see html.

- Jonathan M Davis





Re: Why is stdio ... stdio?

2018-11-10 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 10 November 2018 at 23:29:12 UTC, Jonathan M Davis 
wrote:
The fact that they got added to ddoc just further degrades it 
as a proper, macro-based markup language.


The backticks were added to ddoc because they enabled something 
that was *virtually impossible* in ddoc before - proper character 
escaping. It actually originally had nothing to do with syntax 
sugar nor even with presentation - just the constant repetition 
of that myth has made it into a bit of reality.


On the forum though, characters are already escaped properly, so 
there's no need here. Syntax highlighting for larger blocks is 
something I'm meh on - I don't really care either way if we 
wanted to do it.


Re: dip1000: why can't the addressee come into existence later?

2018-11-10 Thread Neia Neutuladh via Digitalmars-d-learn
On Sat, 10 Nov 2018 16:25:40 +, Stanislav Blinov wrote:
> Yep, you just over-simplified the first case.

It is too simple to clearly illustrate why the code is invalid, but not so 
simple that the compiler accepts that code.

> Consider:
> 
> int* p;
> {
>  int i;
>  p = 
> }
> *p = 42;

In that example, the scope for i ends before the scope for p ends. It's 
not at all surprising that that code is wrong. In the other examples I 
gave, both i and p go out of scope at the same time.

But there's a total ordering for when variables' lifetimes end, which is 
the key (and non-obvious) difference between the two.


Re: How do I install a library?

2018-11-10 Thread greatsam4sure via Digitalmars-d-learn

On Saturday, 10 November 2018 at 20:04:21 UTC, aberba wrote:

On Thursday, 8 November 2018 at 23:51:39 UTC, bachmeier wrote:

On Thursday, 8 November 2018 at 23:43:38 UTC, Murilo wrote:

It finally worked, but I can't just compile it normally, I 
have to use dub run, I wish it were something simple that I 
just download into the folder and then use an import 
statement and then compile it like any other program. I wish 
it were as simple as using std.stdio for example.


Unfortunately your stuck with Dub if you want to use D. It's 
an awful experience compared to Python and other scripting 
languages, so I understand what you're saying, but most people 
around here think Dub is the way to go.



Stop bashing dub. Its completely fine for me. I don't get what 
OP mean by "simple" but:


dub init
add package name
dub run

... doesn't look "not simple" to me.


It will pay some of us if you explain more on how to us dub. To 
me dub is too difficult to us and is not user friendly. It is not 
every body who is interested in Dlang is in a country with strong 
internet connection. A tutorial on how to use dub will really 
help. I don't need a link as i have gone through them but did not 
help me. How i wish dlang tools will be as simple and user 
friendly as the language itself.


Re: Why is stdio ... stdio?

2018-11-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, November 10, 2018 6:53:14 AM MST Kagamin via Digitalmars-d-
learn wrote:
> On Friday, 9 November 2018 at 09:11:37 UTC, Jonathan M Davis
>
> wrote:
> > No, I didn't. I just used underscores, which has been used with
> > plain text for emphasis for decades. Supporting markdown, would
> > involve stuff like backticks for code highlighting

Backticks are not from ddoc. They're from markdown and only got added to
ddoc later. The fact that they got added to ddoc just further degrades it as
a proper, macro-based markup language. Regardless, if it isn't clear that
something is code, just put it on its own line, just like folks have been
doing in mailing lists and newsgroups for decades.

- Jonathan M Davis





Re: How do I use null in a struct?

2018-11-10 Thread Sebastiaan Koppe via Digitalmars-d-learn

On Saturday, 10 November 2018 at 19:42:47 UTC, Václav Kozák wrote:
I'm making a Rest API with vibe.d and I have a struct User. 
Sometimes I need to return only a few of the fields. So for 
example: return User(1, null, "John", null, null, ...);
If I do this, an error occurs: cannot implicitly convert 
expression null of type typeof(null) to ...

Thanks.


You can use Optional like drug said, or you can use the @optional 
attribute [1].


@optional will leave the field in its .init state, whereas with 
Optional its easier to detect the null state.


[1] http://vibed.org/api/vibe.data.serialization/optional


Re: How do I use null in a struct?

2018-11-10 Thread drug via Digitalmars-d-learn

On 10.11.2018 22:42, Václav Kozák wrote:
I'm making a Rest API with vibe.d and I have a struct User. Sometimes I 
need to return only a few of the fields. So for example: return User(1, 
null, "John", null, null, ...);
If I do this, an error occurs: cannot implicitly convert expression null 
of type typeof(null) to ...

Thanks.
Probably you need Nullable? 
https://dlang.org/phobos/std_typecons.html#Nullable


Re: Why is stdio ... stdio?

2018-11-10 Thread Patrick Schluter via Digitalmars-d-learn

On Saturday, 10 November 2018 at 18:47:19 UTC, Chris Katko wrote:

On Saturday, 10 November 2018 at 13:53:14 UTC, Kagamin wrote:

[...]


There is another possibility. Have the website run (fallible) 
heuristics to detect a snippet of code and automatically 
generate it. That would leave the mailing list people 
completely unchanged.


[...]


Simply using markup convention used in stackoverflow and reddit 
of formatting as code when indented by 4 blanks would already be 
a good step forward. I do it now even on newsgroup like 
comp.lang.c, the only newsgroup I still use via thunderbird 
(yeah, for the D groups I prefer the web interface which is 
really that good, contrary to all other web based newsgroup 
reader I ever saw).





[...]




Re: How do I install a library?

2018-11-10 Thread aberba via Digitalmars-d-learn

On Thursday, 8 November 2018 at 23:51:39 UTC, bachmeier wrote:

On Thursday, 8 November 2018 at 23:43:38 UTC, Murilo wrote:

It finally worked, but I can't just compile it normally, I 
have to use dub run, I wish it were something simple that I 
just download into the folder and then use an import statement 
and then compile it like any other program. I wish it were as 
simple as using std.stdio for example.


Unfortunately your stuck with Dub if you want to use D. It's an 
awful experience compared to Python and other scripting 
languages, so I understand what you're saying, but most people 
around here think Dub is the way to go.



Stop bashing dub. Its completely fine for me. I don't get what OP 
mean by "simple" but:


dub init
add package name
dub run

... doesn't look "not simple" to me.


How do I use null in a struct?

2018-11-10 Thread Václav Kozák via Digitalmars-d-learn
I'm making a Rest API with vibe.d and I have a struct User. 
Sometimes I need to return only a few of the fields. So for 
example: return User(1, null, "John", null, null, ...);
If I do this, an error occurs: cannot implicitly convert 
expression null of type typeof(null) to ...

Thanks.


Re: Why is stdio ... stdio?

2018-11-10 Thread Chris Katko via Digitalmars-d-learn

On Saturday, 10 November 2018 at 13:53:14 UTC, Kagamin wrote:
On Friday, 9 November 2018 at 09:11:37 UTC, Jonathan M Davis 
wrote:
No, I didn't. I just used underscores, which has been used 
with plain text for emphasis for decades. Supporting markdown, 
would involve stuff like backticks for code highlighting


Backticks are from ddoc. What's the other way to indicate a 
code fragment?


markup for urls - stuff that doesn't actually provide 
information to someone who's reading plain text but just gets 
in the way


If the url is messy, it's already a mess. If it isn't, it's 
easier to leave url as is than bother to markup it.


whereas the underscores _do_ provide information to someone 
reading plain text.


I think what's really missing is code highlighting. Emphasis 
isn't very useful, in your example the verb "do" is already 
emphasis, so markup doesn't provide any additional information, 
just gets in the way.


There is another possibility. Have the website run (fallible) 
heuristics to detect a snippet of code and automatically generate 
it. That would leave the mailing list people completely unchanged.


However, HOW fallible becomes a huge issue. It may be so well 
implemented that nobody ever complains. Or, it could be so bad 
that it often breaks up the author's post in ways the author 
never planned--almost taking away the poster as the controller of 
what they present.


That's a bit of an extreme, and unlikely, but I feel that 
examining extremes can be helpful to define the potential domain 
of the problem.


We can also easily have a checkmark next to each post that 
disables highlighting for that post (as well as disable them in 
your account settings), and even a button people could press that 
says "this post is highlighted wrong." and the developer would 
get a log with the code.


How many implementation "fixes" are needed depends on how 
fallible the detection code really is.


--

But, really, I don't personally see it being "that" bad for 
people to put code tags / code markers around code. It's not like 
they're going to be peppered everywhere. If you can ignore a 
comment in code, you can ignore two tags (start and end) in a 
single post.


It's an interesting argument to extend bold and italics... 
because people ARE already using them!


But I never suggested we should support "full markdown". There's 
no need to support an entire standard if your forum only needs 
part of it. It seems like a reasonable compromise favoring 
maximum utility, to support code tags, as well as tags people 
already use like italics and bold.


Automatic URL linking is a feature of 99% of forums and that 
would also have zero impact on the mailing list people.


There may be others. Even if the goal is "minimum changes for 
mailing list people" it can still be done.


Re: dip1000: why can't the addressee come into existence later?

2018-11-10 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 10 November 2018 at 06:56:29 UTC, Neia Neutuladh 
wrote:

The following code doesn't work with @safe -dip1000:

int* p;
int i;
p = 

i has a shorter lifetime than p, the compiler complains.

But this code does:

int i;
int* p;
p = 

The compiler does this even in the absence of scope guards and 
destructors because simple, obvious rules will be easier to 
understand and implement than nuanced ones, even if it makes 
you reorder declarations sometimes.


Is this right?


Yep, you just over-simplified the first case. Consider:

int* p;
{
int i;
p = 
}
*p = 42;

or even:

module thing;

int* global;

void foo() {
int i;
global = 
}

...much simpler to just go by the lifetime, instead of attempting 
to do a complex analysis. Because for the latter, it would then 
*need* to be deep to be of any use at all. Especially in a 
language that has static ifs:


// parameter is not scope, function is not pure, etc.
void nasty(int* p) { /* ... */ }

void main() {
int *p;
int i;
p = 
static if (someCondition) nasty(p);
}



Re: Reading into the output of a long running shellExecute

2018-11-10 Thread JN via Digitalmars-d-learn

On Saturday, 10 November 2018 at 15:05:38 UTC, helxi wrote:
Hi. I have not done any multi-threaded programming before. What 
I basically want is to read into the output of a long 
shellExecute function each second.


In details, I am calling shellExecute("pkexec dd 
if=/path/to/file of=/dev/sdx status=progress && sync");
It's a long running process and dd command prints how many 
bytes it has written in stdout continuously. I want to read and 
parse this output each second. How should I proceed?


shellExecute won't work, because it waits for the process to end 
before moving on.


I believe https://dlang.org/phobos/std_process.html#pipeProcess 
should do what you want. It returns a ProcessPipes object which 
has stdout, from which you should be able to read.


Re: dip1000: why can't the addressee come into existence later?

2018-11-10 Thread Neia Neutuladh via Digitalmars-d-learn
On Sat, 10 Nov 2018 11:47:24 +, Nicholas Wilson wrote:
> On Saturday, 10 November 2018 at 06:56:29 UTC, Neia Neutuladh wrote:
>> Is this right?
> 
> Are you sure you added @safe to the second example?
> https://run.dlang.io/is/2RbOwK fails to compile.

Maybe take another look at the post you're replying to? I was saying that, 
if the compiler allowed one thing that looked safe to me, it would either 
require nuance (check for scope guards, destructors, and the like before 
saying something is un-@safe) or allow other code that is obviously 
invalid.


Reading into the output of a long running shellExecute

2018-11-10 Thread helxi via Digitalmars-d-learn
Hi. I have not done any multi-threaded programming before. What I 
basically want is to read into the output of a long shellExecute 
function each second.


In details, I am calling shellExecute("pkexec dd if=/path/to/file 
of=/dev/sdx status=progress && sync");
It's a long running process and dd command prints how many bytes 
it has written in stdout continuously. I want to read and parse 
this output each second. How should I proceed?


Re: Why is stdio ... stdio?

2018-11-10 Thread Kagamin via Digitalmars-d-learn
On Friday, 9 November 2018 at 09:11:37 UTC, Jonathan M Davis 
wrote:
No, I didn't. I just used underscores, which has been used with 
plain text for emphasis for decades. Supporting markdown, would 
involve stuff like backticks for code highlighting


Backticks are from ddoc. What's the other way to indicate a code 
fragment?


markup for urls - stuff that doesn't actually provide 
information to someone who's reading plain text but just gets 
in the way


If the url is messy, it's already a mess. If it isn't, it's 
easier to leave url as is than bother to markup it.


whereas the underscores _do_ provide information to someone 
reading plain text.


I think what's really missing is code highlighting. Emphasis 
isn't very useful, in your example the verb "do" is already 
emphasis, so markup doesn't provide any additional information, 
just gets in the way.


Re: dip1000: why can't the addressee come into existence later?

2018-11-10 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 10 November 2018 at 06:56:29 UTC, Neia Neutuladh 
wrote:

Is this right?


Are you sure you added @safe to the second example?
https://run.dlang.io/is/2RbOwK fails to compile.