Re: I want Sublime 3 D auto import !

2020-06-03 Thread Виталий Фадеев via Digitalmars-d-learn

On Thursday, 4 June 2020 at 04:48:22 UTC, bauss wrote:

On Wednesday, 3 June 2020 at 11:54:57 UTC, Виталий Фадеев wrote:

On Tuesday, 2 June 2020 at 20:08:09 UTC, bauss wrote:
What happens if you have the same symbol in multiple modules? 
Ex. two libraries that implement symbols with same name.


Is there a way to be selective?


I want it too! :)


Updated:
- implemented simple way to be selective !




Re: I want Sublime 3 D auto import !

2020-06-03 Thread bauss via Digitalmars-d-learn

On Wednesday, 3 June 2020 at 11:54:57 UTC, Виталий Фадеев wrote:

On Tuesday, 2 June 2020 at 20:08:09 UTC, bauss wrote:
What happens if you have the same symbol in multiple modules? 
Ex. two libraries that implement symbols with same name.




First module will inserted.


Is there a way to be selective?


I want it too! :)


And what about keyboard shortcut?


A specially for you !

Sublime 3 / Preferences / Key bindings:
[
{ "keys": ["alt+a"], "command": "dlang_auto_import" },
]


Thanks, that's great!


Re: writeln Function while reading a Text File is printing appending text "before text" and "after text" at the same position

2020-06-03 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 03, 2020 at 08:43:43PM +, BoQsc via Digitalmars-d-learn wrote:
> On Wednesday, 3 June 2020 at 20:05:52 UTC, ttk wrote:
[...]
> > That works, but consider using chomp() instead.
> > 
> > https://dlang.org/phobos/std_string.html#.chomp
> 
> Chomp sounds kind of funny hahaha.
> Who came up with these function names? Walter Bright?
> Anyways, Chomp's way looks way more simple. Thanks.

Chomp comes from Perl.


T

-- 
For every argument for something, there is always an equal and opposite 
argument against it.
Debates don't give answers, only wounded or inflated egos.


Re: writeln Function while reading a Text File is printing appending text "before text" and "after text" at the same position

2020-06-03 Thread BoQsc via Digitalmars-d-learn

On Wednesday, 3 June 2020 at 20:05:52 UTC, ttk wrote:

On Wednesday, 3 June 2020 at 19:53:03 UTC, BoQsc wrote:

Removing the last element of the string got it resolved.
Might not be the best way and adding additional check for 
carriage return before removing the element would be better, 
so this is only initial proof.



Improved example with the above comments resolved.


That works, but consider using chomp() instead.

https://dlang.org/phobos/std_string.html#.chomp


Chomp sounds kind of funny hahaha.
Who came up with these function names? Walter Bright?
Anyways, Chomp's way looks way more simple. Thanks.


import std.stdio;
import std.algorithm;
import std.string;
import std.uni : lineSep;

int lineNumber;
void main(){

File exampleFile = File("exampleText.txt");
lineNumber = 0;
foreach(line; exampleFile.byLine){

if (line == " Sphinx of black quartz, judge my vow.\u000D"){
			writeln(lineNumber, ". hahahahahahaha", chomp(line, "\r"), " 
nononono");


} else {
writeln( lineNumber, ". ", line);
}

lineNumber++;
}
}


Re: writeln Function while reading a Text File is printing appending text "before text" and "after text" at the same position

2020-06-03 Thread ttk via Digitalmars-d-learn

On Wednesday, 3 June 2020 at 19:53:03 UTC, BoQsc wrote:

Removing the last element of the string got it resolved.
Might not be the best way and adding additional check for 
carriage return before removing the element would be better, 
so this is only initial proof.



Improved example with the above comments resolved.


That works, but consider using chomp() instead.

https://dlang.org/phobos/std_string.html#.chomp




Re: writeln Function while reading a Text File is printing appending text "before text" and "after text" at the same position

2020-06-03 Thread BoQsc via Digitalmars-d-learn

Removing the last element of the string got it resolved.
Might not be the best way and adding additional check for 
carriage return before removing the element would be better, so 
this is only initial proof.



Improved example with the above comments resolved.

testingGround.d

import std.stdio;
import std.algorithm;



int lineNumber;
void main(){

File exampleFile = File("exampleText.txt");
lineNumber = 0;
foreach(line; exampleFile.byLine){

if (line == " Sphinx of black quartz, judge my vow.\u000D"){
if (line[line.length -1] == '\u000D'){
line = line.remove(line.length - 1);
}
writeln(lineNumber, ". hahahahahahaha", line, " 
nononono");

} else {
writeln( lineNumber, ". ", line[line.length -1]);
}

lineNumber++;
}
}


Re: writeln Function while reading a Text File is printing appending text "before text" and "after text" at the same position

2020-06-03 Thread BoQsc via Digitalmars-d-learn

On Wednesday, 3 June 2020 at 18:49:38 UTC, ttk wrote:

On Wednesday, 3 June 2020 at 18:23:51 UTC, BoQsc wrote:
Here you can see ". hahahahahahaha" and "nononono" and even 
lineNumber is being merged into the same position. Why is this 
happening and can this be simply resolved?


Your string in "line" has a carriage return character at the 
end, which moves the cursor to the beginning of the display row.


If you remove this trailing carriage return character (0x0D) it 
will display correctly.


With the carriage return character in place, everything written 
to your terminal after the carriage return starts at the 
beginning of the row.


It seems to be correct.
Removing the last element of the string got it resolved.
Might not be the best way and adding additional check for 
carriage return before removing the element would be better, so 
this is only initial proof.


Command Prompt Output
C:\Users\vaida\Desktop\Associative Array Sorting> rdmd 
associativeArraySorting.d

0.  The quick brown fox jumps over the lazy dog
1. hahahahahahaha Sphinx of black quartz, judge my vow.nononono
2. # How vexingly quick daft zebras jump!
3. # The five boxing wizards jump quickly
4. # Maecenas consectetur risus a lacus sodales iaculis.
5. # Morbi sed tortor sollicitudin, pharetra massa egestas, 
congue massa.

6. # Sed sit amet nisi at ligula ultrices posuere quis nec est.
7. # Mauris vel purus viverra, pellentesque elit id, consequat 
felis.



testingGround.d

import std.stdio;
import std.algorithm;



int lineNumber;
void main(){

File exampleFile = File("exampleText.txt");
lineNumber = 0;
foreach(line; exampleFile.byLine){

if (line == " Sphinx of black quartz, judge my vow.\u000D"){
			writeln(lineNumber, ". hahahahahahaha", 
line.remove(line.length - 1), " nononono");


} else {
writeln( lineNumber, ". ", line);
}

lineNumber++;
}
}


Re: writeln Function while reading a Text File is printing appending text "before text" and "after text" at the same position

2020-06-03 Thread Steven Schveighoffer via Digitalmars-d-learn

On 6/3/20 2:23 PM, BoQsc wrote:

C:\Users\vaida\Desktop\Associative Array Sorting> rdmd testingGround.d
0.  The quick brown fox jumps over the lazy dog
nonononoahahahaha Sphinx of black quartz, judge my vow.
2. # How vexingly quick daft zebras jump!
3. # The five boxing wizards jump quickly
4. # Maecenas consectetur risus a lacus sodales iaculis.
5. # Morbi sed tortor sollicitudin, pharetra massa egestas, congue massa.
6. # Sed sit amet nisi at ligula ultrices posuere quis nec est.
7. # Mauris vel purus viverra, pellentesque elit id, consequat felis.


Here you can see ". hahahahahahaha" and "nononono" and even lineNumber 
is being merged into the same position. Why is this happening and can 
this be simply resolved?



testingGround.d

import std.stdio;
import std.algorithm;

int lineNumber;
void main(){

File exampleFile = File("exampleText.txt");
lineNumber = 0;
foreach(line; exampleFile.byLine){

    if (line == " Sphinx of black quartz, judge my vow.\u000D"){
    writeln(lineNumber, ". hahahahahahaha", line, "nononono");

    } else {
    writeln( lineNumber, ". ", line);
    }

    lineNumber++;
}
}


exampleText.txt

 The quick brown fox jumps over the lazy dog
 Sphinx of black quartz, judge my vow.
# How vexingly quick daft zebras jump!
# The five boxing wizards jump quickly
# Maecenas consectetur risus a lacus sodales iaculis.
# Morbi sed tortor sollicitudin, pharetra massa egestas, congue massa.
# Sed sit amet nisi at ligula ultrices posuere quis nec est.
# Mauris vel purus viverra, pellentesque elit id, consequat felis.


\u000D is a carriage return, which means that the terminal moves the 
insertion point to the front of the line, and writes "nononono" over the 
original text there. (BTW, you can just do \r instead)


How do you fix it? I don't know what your requirements are. I don't know 
what you are expecting.


-Steve


Re: writeln Function while reading a Text File is printing appending text "before text" and "after text" at the same position

2020-06-03 Thread ttk via Digitalmars-d-learn

On Wednesday, 3 June 2020 at 18:23:51 UTC, BoQsc wrote:
Here you can see ". hahahahahahaha" and "nononono" and even 
lineNumber is being merged into the same position. Why is this 
happening and can this be simply resolved?


Your string in "line" has a carriage return character at the end, 
which moves the cursor to the beginning of the display row.


If you remove this trailing carriage return character (0x0D) it 
will display correctly.


With the carriage return character in place, everything written 
to your terminal after the carriage return starts at the 
beginning of the row.




writeln Function while reading a Text File is printing appending text "before text" and "after text" at the same position

2020-06-03 Thread BoQsc via Digitalmars-d-learn
C:\Users\vaida\Desktop\Associative Array Sorting> rdmd 
testingGround.d

0.  The quick brown fox jumps over the lazy dog
nonononoahahahaha Sphinx of black quartz, judge my vow.
2. # How vexingly quick daft zebras jump!
3. # The five boxing wizards jump quickly
4. # Maecenas consectetur risus a lacus sodales iaculis.
5. # Morbi sed tortor sollicitudin, pharetra massa egestas, 
congue massa.

6. # Sed sit amet nisi at ligula ultrices posuere quis nec est.
7. # Mauris vel purus viverra, pellentesque elit id, consequat 
felis.


Here you can see ". hahahahahahaha" and "nononono" and even 
lineNumber is being merged into the same position. Why is this 
happening and can this be simply resolved?



testingGround.d

import std.stdio;
import std.algorithm;

int lineNumber;
void main(){

File exampleFile = File("exampleText.txt");
lineNumber = 0;
foreach(line; exampleFile.byLine){

if (line == " Sphinx of black quartz, judge my vow.\u000D"){
writeln(lineNumber, ". hahahahahahaha", line, 
"nononono");

} else {
writeln( lineNumber, ". ", line);
}

lineNumber++;
}
}


exampleText.txt

 The quick brown fox jumps over the lazy dog
 Sphinx of black quartz, judge my vow.
# How vexingly quick daft zebras jump!
# The five boxing wizards jump quickly
# Maecenas consectetur risus a lacus sodales iaculis.
# Morbi sed tortor sollicitudin, pharetra massa egestas, congue 
massa.

# Sed sit amet nisi at ligula ultrices posuere quis nec est.
# Mauris vel purus viverra, pellentesque elit id, consequat 
felis.


Re: Is there a list of things which are slow to compile?

2020-06-03 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 03, 2020 at 09:36:52AM +, drathier via Digitalmars-d-learn 
wrote:
> I'm wondering if there's a place that lists things which are
> slower/faster to compile? DMD is pretty famed for compiling quickly,
> but I'm not seeing particularly high speed at all, and I want to fix
> that.

The two usual culprits are:
- Recursive/chained templates
- Excessive CTFE

Note that while the current CTFE engine is slow, it's still reasonably
fast for short computations. Just don't write nested loops or loops with
a huge number of iterations inside your CTFE code, and you should be
fine. And on that note, even running std.format with all of its
complexity inside CTFE is reasonably fast, as long as you don't do it
too often; so generally you won't see a problem here unless you have
loop with too many iterations or too deeply-nested loops running in
CTFE.

Templates are generally reasonably OK, until you use too many recursive
templates. Or if you chain too many of them together, like if you have
excessively long UFCS chains with Phobos algorithms. Short chains are
generally OK, but once they start getting long they will generate large
symbols and large numbers of instantiations. Large symbols used to be a
big problem, but ever since Rainer's fix they have generally been a lot
tamer. But still, it's something to avoid unless you can't help it.

Recursive templates are generally bad because they tend to produce a
super-linear number of instantiations, which consume lots of compiler
memory and also slow things down. Use too many of them, and things will
quickly slow to a crawl.

Worst is if you combine both deeply-nested templates and CTFE, like
std.regex does. Similarly, std.format (which includes writefln & co)
tends to add 1-2 seconds to compile time.

Another is if you have an excessively long function body, IIRC there are
some O(n^2) algorithms in the compiler w.r.t. the length of the function
body. But I don't expect normal code to reach the point where this
begins to matter; generally you won't run into this unless your code is
*really* poorly written (like the entire application inside main()), or
you're using excessive code generation (like the mixin of a huge
procedurally generated string).

Identifier lengths are generally no problem unless you're talking about
100KB-long identifiers, which used to be a problem until Rainer
implemented backreferences in the mangling. But I don't expect normal
code to generate symbols of this order of magnitude unless you're using
excessively-long UFCS chains with nested templates. Identifier length
generally doesn't even register on the radar unless they're ridiculously
long, like tens or hundreds of KB long -- not something a human would
type. What humans would consider a long identifier, like Java-style
names that span 50 characters, are mere round-off error and probably
don't even make a measurable difference. The problem really only begins
to surface when you have 10,000 characters in your identifier or larger.

Comments are not even a blip on the radar: lexing is the fastest part of
the compilation process.  Similarly, aliases are extremely cheap, it's
not even on the radar. Delegates have only a runtime cost; they are
similarly unnoticeably cheap during compilation.  As are Variants,
unless you're running Variants inside CTFE (which I don't think even
works).


T

-- 
Why waste time reinventing the wheel, when you could be reinventing the engine? 
-- Damian Conway


Re: Fastest way to check using if identifier has already been defined, using static if or similar?

2020-06-03 Thread Stefan Koch via Digitalmars-d-learn

On Wednesday, 3 June 2020 at 09:39:34 UTC, Basile B. wrote:

On Wednesday, 3 June 2020 at 09:03:22 UTC, drathier wrote:

[...]


You can use this template:

  enum Exists(alias T) = is(typeof(T));

I don't know if there's a faster way bu this technic is used, 
notatbly in phobos, to workaroud issues of double declaration 
in `static foreach`


Please don't promote templates like this as long as they are not 
really zero-cost.

They don't add much to compile time granted.
But Barnacles.



Re: Fastest way to check using if identifier has already been defined, using static if or similar?

2020-06-03 Thread Paul Backus via Digitalmars-d-learn

On Wednesday, 3 June 2020 at 13:24:17 UTC, Basile B. wrote:
This is because the template parameter must be resolved to a 
valid symbol or type.

This version other version bypass the problem:

---
enum Exists(string s) = is(typeof(mixin(s)));

void main()
{
static if (!Exists!"foo")
int foo;
foo = 42;
}
---


Fails if the symbol in question is the name of a type.

struct Foo {}
enum Exists(string s) = is(typeof(mixin(s)));
static assert(Exists!"Foo"); // false

What you actually want is something like this:

enum Exists(string s) = __traits(compiles, { mixin("alias _ = 
", s, ";"); });


Re: Fastest way to check using if identifier has already been defined, using static if or similar?

2020-06-03 Thread Basile B. via Digitalmars-d-learn

On Wednesday, 3 June 2020 at 10:24:44 UTC, Simen Kjærås wrote:

On Wednesday, 3 June 2020 at 09:39:34 UTC, Basile B. wrote:

You can use this template:

  enum Exists(alias T) = is(typeof(T));

I don't know if there's a faster way bu this technic is used, 
notatbly in phobos, to workaroud issues of double declaration 
in `static foreach`


enum Exists(alias T) = is(typeof(T));
static assert(!Exists!bar); // undefined identifier bar

--
  Simen


This is because the template parameter must be resolved to a 
valid symbol or type.

This version other version bypass the problem:

---
enum Exists(string s) = is(typeof(mixin(s)));

void main()
{
static if (!Exists!"foo")
int foo;
foo = 42;
}
---


Re: How to make the compile time red color warning ?

2020-06-03 Thread Виталий Фадеев via Digitalmars-d-learn

On Wednesday, 3 June 2020 at 11:56:26 UTC, MrSmith wrote:

On Wednesday, 3 June 2020 at 11:48:27 UTC, Виталий Фадеев wrote:

Use case:
I have class for Windows OS.
I not implement class for Linux.
I want message about it. When code compiled under Linux.


You could use `static assert(false, "Message");` to make it an 
error.


That is true!
I happy!



Re: How to make the compile time red color warning ?

2020-06-03 Thread MrSmith via Digitalmars-d-learn

On Wednesday, 3 June 2020 at 11:48:27 UTC, Виталий Фадеев wrote:

Use case:
I have class for Windows OS.
I not implement class for Linux.
I want message about it. When code compiled under Linux.


You could use `static assert(false, "Message");` to make it an 
error.





Re: I want Sublime 3 D auto import !

2020-06-03 Thread Виталий Фадеев via Digitalmars-d-learn

On Tuesday, 2 June 2020 at 20:08:09 UTC, bauss wrote:
What happens if you have the same symbol in multiple modules? 
Ex. two libraries that implement symbols with same name.




First module will inserted.


Is there a way to be selective?


I want it too! :)


And what about keyboard shortcut?


A specially for you !

Sublime 3 / Preferences / Key bindings:
[
{ "keys": ["alt+a"], "command": "dlang_auto_import" },
]


How to make the compile time red color warning ?

2020-06-03 Thread Виталий Фадеев via Digitalmars-d-learn

Use case:
I have class for Windows OS.
I not implement class for Linux.
I want message about it. When code compiled under Linux.


Example:


version ( Windows )
{
public import ui.sys.windows.event.keyboardevent;
}
else
{
pragma( msg, "Unsupported OS" );
}


How to make red color message ?
pragma( msg, "Unsupported OS" );



Or may be call compiller warning_message() function ? Such exists 
?


Thanks.



Re: I want Sublime 3 D auto import !

2020-06-03 Thread aberba via Digitalmars-d-learn

On Monday, 1 June 2020 at 17:28:16 UTC, Johannes Loher wrote:

On Monday, 1 June 2020 at 16:18:44 UTC, Виталий Фадеев wrote:

[...]


Demanding stuff usually doesn't work in this community. The 
usual answer is something like this: If you care about this, 
implement it yourself or pay somebody to do it.


Depends on how you interpret it.


Re: Making alias of a struct field needs "this".

2020-06-03 Thread realhet via Digitalmars-d-learn

On Wednesday, 3 June 2020 at 10:11:59 UTC, realhet wrote:
On Tuesday, 2 June 2020 at 20:38:40 UTC, Steven Schveighoffer 
wrote:

On 6/2/20 10:51 AM, realhet wrote:

On Tuesday, 2 June 2020 at 13:10:55 UTC, Paul Backus wrote:

On Tuesday, 2 June 2020 at 09:28:01 UTC, realhet wrote:


mixin("int[", 2, "]") a = mixin([5]) ~ 6;

That's insane :D


Re: Fastest way to check using if identifier has already been defined, using static if or similar?

2020-06-03 Thread Simen Kjærås via Digitalmars-d-learn

On Wednesday, 3 June 2020 at 09:39:34 UTC, Basile B. wrote:

You can use this template:

  enum Exists(alias T) = is(typeof(T));

I don't know if there's a faster way bu this technic is used, 
notatbly in phobos, to workaroud issues of double declaration 
in `static foreach`


enum Exists(alias T) = is(typeof(T));
static assert(!Exists!bar); // undefined identifier bar

--
  Simen


Re: Making alias of a struct field needs "this".

2020-06-03 Thread realhet via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 20:38:40 UTC, Steven Schveighoffer 
wrote:

On 6/2/20 10:51 AM, realhet wrote:

On Tuesday, 2 June 2020 at 13:10:55 UTC, Paul Backus wrote:

On Tuesday, 2 June 2020 at 09:28:01 UTC, realhet wrote:


A month ago I discovered that mixinDeclarations can be used for 
types too:


mixin("int[", 2, "]") a = [5, 6];




Re: Is there a list of things which are slow to compile?

2020-06-03 Thread drathier via Digitalmars-d-learn

On Wednesday, 3 June 2020 at 09:36:52 UTC, drathier wrote:
Currently at ~1ksloc/s of d input without optimizing anything, 
which corresponds to 350ksloc/s if measuring by `-vcg-ast` 
output instead of d source input, while using the same time 
measurement from before, so the flag doesn't cost time.


Sorry, that should read `44ksloc/s`, not `350ksloc/s`.


Re: Fastest way to check using if identifier has already been defined, using static if or similar?

2020-06-03 Thread Basile B. via Digitalmars-d-learn

On Wednesday, 3 June 2020 at 09:03:22 UTC, drathier wrote:
I'm generating some code. Some of the generated types need to 
be overridden, so I define them manually at the top of the 
generated file. Then I need to guard against redefining the 
identifier (type/value/function) later on, in the generated 
code.


I'm currently using `static if (!__traits(compiles, thingy)) {` 
to avoid redefining things twice.


Of course the proper fix is to not generate code for the 
identifiers which are already manually defined, and not 
generate any `static if`s at all, but until then, is there a 
faster way than `static if (__traits(compiles, ...` to check if 
a type/value/function has already been defined?


You can use this template:

  enum Exists(alias T) = is(typeof(T));

I don't know if there's a faster way bu this technic is used, 
notatbly in phobos, to workaroud issues of double declaration in 
`static foreach`


Is there a list of things which are slow to compile?

2020-06-03 Thread drathier via Digitalmars-d-learn
I'm wondering if there's a place that lists things which are 
slower/faster to compile? DMD is pretty famed for compiling 
quickly, but I'm not seeing particularly high speed at all, and I 
want to fix that.


Currently at ~1ksloc/s of d input without optimizing anything, 
which corresponds to 350ksloc/s if measuring by `-vcg-ast` output 
instead of d source input, while using the same time measurement 
from before, so the flag doesn't cost time.


Here's my learnings so far:
- CTFE is obviously unboundedly slow, since it runs arbitrary code
- Template expansion is presumably O(n) in the size of the 
generated code, and the `-vcg-ast` flag helps a bit to see how 
much it's expanding. I'm not convinced it's the reason my code 
compiles slowly, though.

- no idea how expensive static if's on traits are
- std.regex compiles really slowly
- CTFE always runs on all top-level value definitions (even if 
they contain things which cannot be executed at compile-time, and 
I hate this so so much)


What other things are there?
- identifier lengths?
- comments?
- aliases?
- delegates?
- Variants?


Re: What's the best way to find out which exceptions may be thrown ?

2020-06-03 Thread wjoe via Digitalmars-d-learn

On Wednesday, 3 June 2020 at 07:19:45 UTC, Luis wrote:

On Wednesday, 27 May 2020 at 10:30:36 UTC, wjoe wrote:


Could you please elaborate why checked exceptions are more 
annoying?





Have like 3 functions : A calls B, B calls C .
[...]

I work daily with Java, and it's pretty annoying. That the IDE 
helps you auto putting the throws or suggesting a try/catch, 
helps. But we ended making some generic exceptions 
RuntimeExceptions to avoiding the noise and problems that could 
give checked exceptions.


I was thinking about IDE assistance, too, but after reading the 
interview with Anders Hejlsberg mentioning the ballooning problem 
- I can see how checked exceptions can get out of control.


Re: What's the best way to find out which exceptions may be thrown ?

2020-06-03 Thread wjoe via Digitalmars-d-learn

On Tuesday, 2 June 2020 at 13:58:13 UTC, Bienlein wrote:

On Wednesday, 27 May 2020 at 11:40:00 UTC, Mike Parker wrote:

On Wednesday, 27 May 2020 at 10:30:36 UTC, wjoe wrote:

[...]


For me, it's because they require all functions that touch 
them to either try/catch or include an exception specification 
in its declaration. In my Java days, I ended up just doing 
what so many others do and adding `throws Exception` or 
`catch(Exception)` to avoid having to handle multiple 
exception types. Most of the time, I didn't care what specific 
sort of exception was thrown.


Because of the problems with checked exceptions they were 
deliberately left out in C#. Here is an interview with Anders 
Hejlsberg, the creator of C# at MS, where he explains the 
reasons for this decision: 
https://www.artima.com/intv/handcuffs.html


That was a good read. Thank you.


Fastest way to check using if identifier has already been defined, using static if or similar?

2020-06-03 Thread drathier via Digitalmars-d-learn
I'm generating some code. Some of the generated types need to be 
overridden, so I define them manually at the top of the generated 
file. Then I need to guard against redefining the identifier 
(type/value/function) later on, in the generated code.


I'm currently using `static if (!__traits(compiles, thingy)) {` 
to avoid redefining things twice.


Of course the proper fix is to not generate code for the 
identifiers which are already manually defined, and not generate 
any `static if`s at all, but until then, is there a faster way 
than `static if (__traits(compiles, ...` to check if a 
type/value/function has already been defined?


Re: What's the best way to find out which exceptions may be thrown ?

2020-06-03 Thread Luis via Digitalmars-d-learn

On Wednesday, 27 May 2020 at 10:30:36 UTC, wjoe wrote:


Could you please elaborate why checked exceptions are more 
annoying?





Have like 3 functions : A calls B, B calls C .

Imagine that now you need to throw a checked exception on C, that 
before wasn't necessary.
You need to add the annoying "throws X" to A and B. And A and B 
could be on another module or on a different project. Perhaps, 
the guy that wrote B, was previsor, and putted "throws Exception" 
(or another generic Exception derived class) on B to avoid 
problems, but now you have loss the information about the 
specific Exception that C throws. So again, the compiler can't 
know what kind of exception could be throwed by A beyond of a 
generic "Exception" (or another generic exception class). Another 
workaround, could be wrapping the C throwed exception by a 
generic exception on B.


I work daily with Java, and it's pretty annoying. That the IDE 
helps you auto putting the throws or suggesting a try/catch, 
helps. But we ended making some generic exceptions 
RuntimeExceptions to avoiding the noise and problems that could 
give checked exceptions.





Re: What's the best way to find out which exceptions may be thrown ?

2020-06-03 Thread FeepingCreature via Digitalmars-d-learn

On Tuesday, 2 June 2020 at 13:58:13 UTC, Bienlein wrote:
Because of the problems with checked exceptions they were 
deliberately left out in C#. Here is an interview with Anders 
Hejlsberg, the creator of C# at MS, where he explains the 
reasons for this decision: 
https://www.artima.com/intv/handcuffs.html


This wouldn't seem to apply if checked exceptions were inferred 
by default, right? And the issues with Java generics don't apply 
to D, because our metaprogramming infers attributes anyways.