Re: git workflow for D

2017-12-03 Thread Patrick Schluter via Digitalmars-d-learn

On Monday, 4 December 2017 at 01:54:57 UTC, ketmar wrote:

Basile B. wrote:

On Sunday, 3 December 2017 at 22:22:47 UTC, Arun 
Chandrasekaran wrote:
Git CLI is arcane and esoteric. I've lost my commits before 
(yeah, my mistake).


Who hasn't ;)

me.

Happened to me last time because i tried a command supposed to 
remove untracked files in submodules...but used "reset" in a 
wrong way... ouch.


"git reflog". nothing commited is *ever* lost until you do "git 
gc".


This needs to be repeated: nothing in git is ever lost if it had 
been commited. You can lose untracked files, but commits do not 
disappear.
If you're unsure before an operation and have difficulties to use 
git reflog. Before doing the operation, do a simple git branch 
life-draft (or whatever you want). After the operation if it 
failed, you still have the commit your HEAD was on referenced by 
the life-draft branch.
branches and tags are just pointers in the directed graph a git 
repositery is. The interface only does not display the branches 
that have no entry pointer.


git sometimes does GC on its own, so you can turn it off

with:

git config --global gc.auto 0

don't forget to manually GC your repo then with "git gc", or it 
may grow quite huge.





Re: git workflow for D

2017-12-03 Thread ketmar via Digitalmars-d-learn

Basile B. wrote:


On Sunday, 3 December 2017 at 22:22:47 UTC, Arun Chandrasekaran wrote:
Git CLI is arcane and esoteric. I've lost my commits before (yeah, my 
mistake).


Who hasn't ;)

me.

Happened to me last time because i tried a command supposed to remove 
untracked files in submodules...but used "reset" in a wrong way... ouch.
"git reflog". nothing commited is *ever* lost until you do "git gc". git 
sometimes does GC on its own, so you can turn it off with:


git config --global gc.auto 0

don't forget to manually GC your repo then with "git gc", or it may grow 
quite huge.


Re: git workflow for D

2017-12-03 Thread Arun Chandrasekaran via Digitalmars-d-learn

On Sunday, 3 December 2017 at 23:39:49 UTC, Basile B. wrote:
On Sunday, 3 December 2017 at 22:22:47 UTC, Arun Chandrasekaran 
wrote:
Git CLI is arcane and esoteric. I've lost my commits before 
(yeah, my mistake).


Who hasn't ;)
Happened to me last time because i tried a command supposed to 
remove untracked files in submodules...but used "reset" in a 
wrong way... ouch.


If you still lose changes, you could try using Mercurial with 
hggit. It can be a bit slow, but not destructive as git itself. ;)


I really wish Mercurial won instead of git. Now that hg evolve 
and hg topic are stable, that actually alleviates the need for 
git. But the world talks git now. So everyone else is forced to 
talk in git :(


I guess, without StackOverflow and GitHub, no one would be using 
git.


Facebook uses Mercurial and their team is working on a Mercurial 
server in Rust. https://github.com/facebookexperimental/mononoke


I thought Facebook uses DLang as well. No one's motivated to 
write one in DLang?




Re: git workflow for D

2017-12-03 Thread Basile B. via Digitalmars-d-learn
On Sunday, 3 December 2017 at 22:22:47 UTC, Arun Chandrasekaran 
wrote:
Git CLI is arcane and esoteric. I've lost my commits before 
(yeah, my mistake).


Who hasn't ;)
Happened to me last time because i tried a command supposed to 
remove untracked files in submodules...but used "reset" in a 
wrong way... ouch.


Since then I always access git via mercurial. In comparison 
Mercurial is far better a VCS tool.


I use git gui (i find other GUIs slower even if nicer) but 
even...there are few commands to know:


- checkout /*select a branch or a commit in the history*/
- commit /*validate changes*/
- pull /*get upstream changes*/
- push /*send upstream changes*/
- rebase /*squash - fixup*/
- stash /*backup before pull in case of...*/

you can live with that.


Re: How to declare immutable struct outside of try catch and reference it later

2017-12-03 Thread Basile B. via Digitalmars-d-learn

On Sunday, 3 December 2017 at 22:33:40 UTC, kdevel wrote:

On Sunday, 3 December 2017 at 14:58:03 UTC, Basile B. wrote:

In this case i'd go for a typed pointer, e.g

---
immutable struct Configuration
{
this(string){/*load some file...*/}
int value;
}

Configuration* config;

void main()
{
try config = new Configuration("config.sdl");
catch(Exception){}
// config.value = 42; // ok, read only
}
---


When config is null, e.g. in case "load some file..." threw, 
you get a segfault. No error handling at all!


I don't follow you...the file thing happens in the __ctor. 
Exceptions are well handled. Maybe you've missed the try (w/o 
braces) ?


---
immutable struct Configuration {
this(string){/*parse_config...*/}
}

Configuration* config;

int main() {
try {
config = new Configuration("config.sdl");
// instead of "conf = parse_config("config.sdl");"
} catch(Exception e){
std.stdio.stderr.writeln("Error reading configuration 
file: ", e.msg);

return 1;
}
}
---




Re: Windows Share Path

2017-12-03 Thread rjframe via Digitalmars-d-learn
On Sun, 03 Dec 2017 16:42:46 +, vino wrote:

> Question:
> Is there a way to map network drive in windows using D code, similar to
> the windows command such as "net use" or "pushd" or powershell command
> New-PSDrive.?
> 
> From,
> Vino.B

There's WNetAddConnection2[1] and WNetAddConnection3[2] in the Windows API. 
The API header module is core.sys.windows.winnetwk[3].

I've not used either function, but based on the documentation, it looks 
straightforward.

--Ryan


[1]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa385413
(v=vs.85).aspx
[2]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa385418
(v=vs.85).aspx
[3]: https://github.com/dlang/druntime/
blob/2db828bd4f21807254b770b3ec304f14596a9805/src/core/sys/windows/
winnetwk.d


Re: How to declare immutable struct outside of try catch and reference it later

2017-12-03 Thread kdevel via Digitalmars-d-learn

On Sunday, 3 December 2017 at 14:58:03 UTC, Basile B. wrote:

In this case i'd go for a typed pointer, e.g

---
immutable struct Configuration
{
this(string){/*load some file...*/}
int value;
}

Configuration* config;

void main()
{
try config = new Configuration("config.sdl");
catch(Exception){}
// config.value = 42; // ok, read only
}
---


When config is null, e.g. in case "load some file..." threw, you 
get a segfault. No error handling at all!


Re: git workflow for D

2017-12-03 Thread Arun Chandrasekaran via Digitalmars-d-learn
Git CLI is arcane and esoteric. I've lost my commits before 
(yeah, my mistake). Since then I always access git via mercurial. 
In comparison Mercurial is far better a VCS tool.


Re: git workflow for D

2017-12-03 Thread Mengu via Digitalmars-d-learn

On Sunday, 3 December 2017 at 20:05:47 UTC, bitwise wrote:
I've finally started learning git, due to our team expanding 
beyond one person - awesome, right? Anyways, I've got things 
more or less figured out, which is nice, because being clueless 
about git is a big blocker for me trying to do any real work on 
dmd/phobos/druntime. As far as working on a single master 
branch works, I can commit, rebase, merge, squash, push, reset, 
etc, like the best of em. What I'm confused about is how all 
this stuff will interact when working on a forked repo and 
trying to maintain pull requests while everyone else's commits 
flood in.


How does one keep their fork up to date? For example, if I fork 
dmd, and wait a month, do I just fetch using dmd's master as a 
remote, and then rebase? Will that actually work, or is that 
impossible across separate forks/branches? What if I have 
committed and pushed to my remote fork and still want to merge 
in the latest changes from dlang's master branch?


you can fork it, set dmd/master as upstream and then git fetch 
upstream. you can then rebase.




And how does a pull request actually work? Is it a request to 
merge my entire branch, or just some specific files? and do I 
need a separate branch for each pull request, or is the pull 
request itself somehow isolated from my changes?


commits can be cherrypick-ed or you can request your entire 
branch to be merged. it doesn't always have to be the master 
branch. for example, if there's std.experimental.logger branch, 
you can ask for your branch to be merged with that. having a 
seperate branch for each feature is most of the time the way to 
go. makes it cleaner for yourself. later on you can delete those 
merged branches.




Anyways, I'd just be rambling if I kept asking questions. If 
anyone can offer any kind of advice, or an article that 
explains these things concisely and effectively, that would be 
helpful.


Thanks





Re: git workflow for D

2017-12-03 Thread Basile B. via Digitalmars-d-learn

On Sunday, 3 December 2017 at 20:05:47 UTC, bitwise wrote:
I've finally started learning git, due to our team expanding 
beyond one person - awesome, right? Anyways, I've got things 
more or less figured out, which is nice, because being clueless 
about git is a big blocker for me trying to do any real work on 
dmd/phobos/druntime. As far as working on a single master 
branch works, I can commit, rebase, merge, squash, push, reset, 
etc, like the best of em. What I'm confused about is how all 
this stuff will interact when working on a forked repo and 
trying to maintain pull requests while everyone else's commits 
flood in.


How does one keep their fork up to date?


Just push to your fork/master after pulling from the (shared) 
origin/master.


For example, if I fork dmd, and wait a month, do I just fetch 
using dmd's master as a remote, and then rebase? Will that 
actually work, or is that impossible across separate 
forks/branches? What if I have committed and pushed to my 
remote fork and still want to merge in the latest changes from 
dlang's master branch?


In a non personal project you NEVER commit to master. You make 
each single fucking change in a specific branch (sorry for the 
language, it's intentionally gross). the master branch is only 
updated when you pull from the origin.


And how does a pull request actually work? Is it a request to 
merge my entire branch,


Yes it's a merge. Optionally all the commits can be squashed.

or just some specific files? and do I need a separate branch 
for each pull request,


Yes, yes yes, again. ~master is sacrosanct.


or is the pull request itself somehow isolated from my changes?

Anyways, I'd just be rambling if I kept asking questions. If 
anyone can offer any kind of advice, or an article that 
explains these things concisely and effectively, that would be 
helpful.


Thanks


The only article i've ever read about git was when the first time 
i needed to squash (actually i rather do "fixup" 99% of the 
time...) so i have nothing else to add.


git workflow for D

2017-12-03 Thread bitwise via Digitalmars-d-learn
I've finally started learning git, due to our team expanding 
beyond one person - awesome, right? Anyways, I've got things more 
or less figured out, which is nice, because being clueless about 
git is a big blocker for me trying to do any real work on 
dmd/phobos/druntime. As far as working on a single master branch 
works, I can commit, rebase, merge, squash, push, reset, etc, 
like the best of em. What I'm confused about is how all this 
stuff will interact when working on a forked repo and trying to 
maintain pull requests while everyone else's commits flood in.


How does one keep their fork up to date? For example, if I fork 
dmd, and wait a month, do I just fetch using dmd's master as a 
remote, and then rebase? Will that actually work, or is that 
impossible across separate forks/branches? What if I have 
committed and pushed to my remote fork and still want to merge in 
the latest changes from dlang's master branch?


And how does a pull request actually work? Is it a request to 
merge my entire branch, or just some specific files? and do I 
need a separate branch for each pull request, or is the pull 
request itself somehow isolated from my changes?


Anyways, I'd just be rambling if I kept asking questions. If 
anyone can offer any kind of advice, or an article that explains 
these things concisely and effectively, that would be helpful.


Thanks



Re: Implicit nothrow with -betterC

2017-12-03 Thread Adam D. Ruppe via Digitalmars-d-learn

On Sunday, 3 December 2017 at 15:24:27 UTC, Manuel Maier wrote:
I've been experimenting with the -betterC switch and stumbled 
upon something that didn't quite make sense to me.


betterC doesn't change the language, it just doesn't compile in 
all the features automatically. So rules about nothrow etc. 
decorations are still in place, even if the feature isn't 
actually available at this time. The same code you build with 
-betterC can almost always be built without the switch too, and 
continue to work the same way.



According to the docs, exceptions "won't work":


That may be a temporary restriction. It is already possible to do 
exceptions with -betterC code if you link in the functions 
yourself (notably, betterC modules are permitted to be used in a 
regular druntime based application), and in the future, such may 
be done automatically on demand too.


Re: Windows Share Path

2017-12-03 Thread vino via Digitalmars-d-learn

On Sunday, 3 December 2017 at 01:27:40 UTC, codephantom wrote:

On Saturday, 2 December 2017 at 14:23:48 UTC, Vino wrote:

Hi,
  Even tried the Option "Run with Highest Privilege" but no 
luck. and also tried with option "Configure for : Windows 
Vista , Windows Server 2008"


From,
Vino.B


You haven't accidently ticked the 'Do not store password' 
option? That is a common mistake. (i.e. make sure it's *not* 
ticked, and reinsert credentials).


In my 'sysadmin' days, I *refused* to use the windows 
scheduler. I didn't want something that kept changing depending 
on which version of windows you were using. I wanted 
consistency.


From memory, i think I installed 'system scheduler' on all my 
MS servers.


https://www.splinterware.com/tour/scheduler.html


Hi All,

 Finally was able to resolve the issue, the issue was, the 
windows share was mapped using domain user so when the .bat 
program is scheduled via task manager with the option "Run 
whether the user is logged in or not" the .bat script run the 
task in session 0, where as the windows share was mapped in user 
session (domain user , session 23), so the the D program was not 
able to find the windows share path, so add the windows command 
"net use \\server\share" as the first line in the .bat and then 
added line calling the D program which resolved the issue.

Option : Do not store password was unchecked"

Solution:
D Program(TestDir.exe)
import std.stdio;
import std.file;
import std.path;


void main()
{
auto p = "N:BACKUP";
if (!p.isValidPath && !p.strip.isValidFilename || !p.exists ) { 
writeln("Invalid File Path (", p, ") or Path do not Exist"); }

else { writeln("File Exist":, p); }
}
  }

Bat Program(Run.bat)
@echo off
net use N: \\shareserver\sharename /Persistence: No
start /D D:\DScript /B /WAIT D:\DScript\TestDir.exe
exit

Question:
Is there a way to map network drive in windows using D code, 
similar to the windows command such as "net use" or "pushd" or 
powershell command New-PSDrive.?


From,
Vino.B


template specialization and Rebindable

2017-12-03 Thread vit via Digitalmars-d-learn
Why is template param T != B but T == Rebindable!(const(B)) when 
specialization is T : const(A)?


abstract class A{}
class B : A{}

string foo(T : const(A))(T x){
return T.stringof;
}

void main(){
import std.typecons : Rebindable;
import std.stdio : writeln;

Rebindable!(const B) b = new B;

auto bar = foo(b);
assert(bar == "Rebindable!(const(B))");

}


Re: Struct inside a class: How to get outer?

2017-12-03 Thread Jacob Carlborg via Digitalmars-d-learn

On 2017-12-03 10:57, Nick Sabalausky (Abscissa) wrote:

On 12/03/2017 03:46 AM, bauss wrote:

It wouldn't make much sense either, if a struct  was able to do it.



Why is that?


It would get an extra field, making the size of the struct larger and 
not compatible with a C struct. But I guess you wouldn't use a nested 
struct for that anyway.


--
/Jacob Carlborg


Implicit nothrow with -betterC

2017-12-03 Thread Manuel Maier via Digitalmars-d-learn
I've been experimenting with the -betterC switch and stumbled 
upon something that didn't quite make sense to me.


I've put together a small example [1] of Win32 code with a window 
callback that has to be nothrow as per the definition of WNDPROC 
somewhere in core.sys.windows. However, calling anything from 
within the window callback not marked as nothrow will result in a 
compile error. This behavior is expected for regular D code and 
there are many ways to fix the code so the compiler no longer 
emits the error. What bugs me is the following.


According to the docs, exceptions "won't work":

From https://dlang.org/spec/betterc.html#consequences
As no Druntime is available, many D features won't work. For 
example:

[...]
7. Exceptions
[...]


To me, this means it should be impossible to write -betterC code 
that throws exceptions. So shouldn't -betterC imply nothrow on 
all functions by default? Is this a compiler bug? If not, in what 
way is the explicit nothrow attribute still useful for -betterC?



[1] 
https://gist.github.com/Manuzor/81cc01d57543202d68eab5a84d944027


Re: How to declare immutable struct outside of try catch and reference it later

2017-12-03 Thread Basile B. via Digitalmars-d-learn

On Sunday, 3 December 2017 at 05:49:54 UTC, Fra Mecca wrote:

I have this code:
Configuration conf = void ;
try {
conf = parse_config("config.sdl");
} catch (Exception e) {
std.stdio.stderr.writeln("Error reading configuration 
file: ", e.msg);

exit(1);
}

// other code
function(value, conf);
// end

I get:
source/app.d(18,3): Error: cannot modify struct conf 
Configuration with immutable members


Is there a way to declare conf outside of the try catch block 
and use it later?

I thought void explicitly avoid inizialization.


In this case i'd go for a typed pointer, e.g

---
immutable struct Configuration
{
this(string){/*load some file...*/}
int value;
}

Configuration* config;

void main()
{
try config = new Configuration("config.sdl");
catch(Exception){}
// config.value = 42; // ok, read only
}
---


Re: How to declare immutable struct outside of try catch and reference it later

2017-12-03 Thread kdevel via Digitalmars-d-learn

On Sunday, 3 December 2017 at 14:16:42 UTC, kdevel wrote:

int main ()
{
   try {
  real_main ();
   }
   catch (Exception e) {
  std.stdio.stderr.writeln(e.msg);
  return 1;
   }
   return 0;
}
```


This is better:

int main ()
{
   try {
  return real_main ();
   }
   catch (Exception e) {
  std.stdio.stderr.writeln(e.msg);
  return 1;
   }
}


Re: How to declare immutable struct outside of try catch and reference it later

2017-12-03 Thread kdevel via Digitalmars-d-learn

On Sunday, 3 December 2017 at 05:49:54 UTC, Fra Mecca wrote:

I have this code:
Configuration conf = void ;
try {
conf = parse_config("config.sdl");
} catch (Exception e) {
std.stdio.stderr.writeln("Error reading configuration 
file: ", e.msg);

exit(1);
}


Since most programs have more than place where execution must be 
terminated, you end up dupliating that try-catch-code all over 
the program making it unreadable. When you try to avoid calling 
exit this problem will not arise. You can simply write


```
   auto conf = parse_config("config.sdl");
```

The exception unwinds the stack and terminates the program. If a 
stacktrace on the command line does not suffice I would wrap the 
main-code in a try-catch block. Your function parse_config should 
support this coding style by putting a whole sentence into the 
Exception instead of the mere filename, then the try-catch 
wrapper in main may look like this:


```
int main ()
{
   try {
  real_main ();
   }
   catch (Exception e) {
  std.stdio.stderr.writeln(e.msg);
  return 1;
   }
   return 0;
}
```



Re: Struct inside a class: How to get outer?

2017-12-03 Thread Nick Sabalausky (Abscissa) via Digitalmars-d-learn

On 12/03/2017 03:46 AM, bauss wrote:

On Sunday, 3 December 2017 at 07:38:47 UTC, Jonathan M Davis wrote:
As I understand it, there is no outer for nested structs, only nested 
classes. So, you'll either have to use a nested class or explicitly 
pass a reference to the outer class to the nested struct.



It wouldn't make much sense either, if a struct  was able to do it.



Why is that?


Re: Struct inside a class: How to get outer?

2017-12-03 Thread bauss via Digitalmars-d-learn
On Sunday, 3 December 2017 at 07:38:47 UTC, Jonathan M Davis 
wrote:
On Sunday, December 03, 2017 01:05:00 Nick Sabalausky  via 
Digitalmars-d- learn wrote:

Is this even possible? My attempts:

class Outer {
  struct Inner {
  void foo() {
  // Error: no property 'outer' for type 'Inner'
  Outer o = this.outer;

  // Error: cannot implicitly convert expression
  // this of type Inner to testNested.Outer
  Outer o = this;
  }
  }
}


As I understand it, there is no outer for nested structs, only 
nested classes. So, you'll either have to use a nested class or 
explicitly pass a reference to the outer class to the nested 
struct.


- Jonathan M Davis


It wouldn't make much sense either, if a struct  was able to do 
it.