digitalmars.D - Pipe-Syntax?
- Manfred Nowak (18/18) Dec 20 2011 Just looked at index.html of D and got stuck on
- Kagamin (1/1) Dec 20 2011 Just use perl.
- =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= (5/23) Dec 20 2011 You could have a look at the pipe template in std.functional. But in
- Dejan Lekic (11/11) Dec 21 2011 Perhaps I should think more about it, but right now I am 100% against it...
- Somedude (6/15) Dec 21 2011 I second this opinion. Multiplying different syntaxes just for the sake
- Manfred Nowak (13/18) Dec 21 2011 Very well put.
Just looked at index.html of D and got stuck on writeln("Hello World, Reloaded"); // auto type inference and built-in foreach foreach (argc, argv; args) { // Object Oriented Programming auto cl = new CmdLin(argc, argv); // Improved typesafe printf writeln(cl.argnum, cl.suffix, " arg: ", cl.argv); // Automatic or explicit memory management delete cl; } With the pipe-syntax of shells ( sh, bash, ...) this five lines could be written as: "Hello World, Piped" | writeln; args | CmdLin | {argnum, suffix, " arg: ", argv} | writeln; Comments? -manfred
Dec 20 2011
On 21-12-2011 05:51, Manfred Nowak wrote:Just looked at index.html of D and got stuck on writeln("Hello World, Reloaded"); // auto type inference and built-in foreach foreach (argc, argv; args) { // Object Oriented Programming auto cl = new CmdLin(argc, argv); // Improved typesafe printf writeln(cl.argnum, cl.suffix, " arg: ", cl.argv); // Automatic or explicit memory management delete cl; } With the pipe-syntax of shells ( sh, bash, ...) this five lines could be written as: "Hello World, Piped" | writeln; args | CmdLin | {argnum, suffix, " arg: ", argv} | writeln; Comments? -manfredYou could have a look at the pipe template in std.functional. But in general, I agree; a sort of piping operator would be very useful in - Alex
Dec 20 2011
Perhaps I should think more about it, but right now I am 100% against it, as it makes the code extremely unreadable to an imperative programmer. I will have to become a ~100% functional programmer to understand what all those overloaded operators do behind the scenes. To me | is a bitwise OR operator, end of story. When I see "|>" and similar in functional languages, I get a headache... My opinion - we should strive for a good ballance between imperative and declarative in D, not to include every possible feature a functional language might have. If you really, really want something like that, then the D way would be to use the "~" operator perhaps...
Dec 21 2011
Le 21/12/2011 13:54, Dejan Lekic a écrit :Perhaps I should think more about it, but right now I am 100% against it, as it makes the code extremely unreadable to an imperative programmer. .... My opinion - we should strive for a good ballance between imperative and declarative in D, not to include every possible feature a functional language might have.I second this opinion. Multiplying different syntaxes just for the sake of "simplifying" code here and there is a good way to make the code unreadable. Even in Python, you can write unreadable code by abusing from functional syntax. Eventually, Guido van Rossum discourages this kind of writing.
Dec 21 2011
Dejan Lekic wrote:extremely unreadable to an imperative programmer.I sort myself to the imperative programming league.not to include every possible feature a functional language might have.Very well put.If you really, really want something like that, then the D way would be to use the "~" operator perhaps...A "no" for both from me. Because it is a first thought only and `~' has the same "history" as `!' in D. As Alex points out, another D way seems to be to write something like: pipe!( echo!args, CmdLin, pipe!(argnum, suffix, " arg: ", argv), writeln ); But I do not see any sugar in this. -manfred
Dec 21 2011