www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Better string mixins

reply Michelle Long <HappyDance321 gmail.com> writes:
The problem with mixing in code is that one has to manually build 
code strings like:

static foreach(k; X)
    mixin("int Var"~k~" = "~k~";);

which is error prone, ugly, time consuming, and harder to read.

Instead, I propose a simple extension:

static foreach(k; X)
    mixin("int Var k =  k;");


Here the   simple, or whatever symbol would be best, takes the 
variable and inserts it from the outer scope as a string, 
converting it to a string if necessary.

It can only be used on such CT variables so errors should not 
exist.

If necessary, maybe

static foreach(k; X)
     mixin("int Var k =  k;");

or

static foreach(k; X)
    mixin( "int Var k =  k;");

could be used.


This avoids having to do shit like

mixin("foo("~x~", "~y~", "~z~");");

so one has

mixin("foo( x, y, z);");

which translates almost directly in to standard code(one can 
simply strip the  's).
Dec 27 2018
next sibling parent reply Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Friday, 28 December 2018 at 05:55:30 UTC, Michelle Long wrote:
 The problem with mixing in code is that one has to manually 
 build code strings like:

 [...]
mixin accepts multiple arguments, see the bottom of https://dlang.org/spec/statement.html#mixin-statement
Dec 28 2018
parent reply SashaGreat <s g.com> writes:
On Friday, 28 December 2018 at 09:12:45 UTC, Nicholas Wilson 
wrote:
 On Friday, 28 December 2018 at 05:55:30 UTC, Michelle Long 
 wrote:
 The problem with mixing in code is that one has to manually 
 build code strings like:

 [...]
mixin accepts multiple arguments, see the bottom of https://dlang.org/spec/statement.html#mixin-statement
It would be nice if it were like C#: mixin("x = {0}", x); More arguments: mixin("x = {0}; y = {1}", x, y); S.
Dec 28 2018
parent reply rikki cattermole <rikki cattermole.co.nz> writes:
On 29/12/2018 1:29 AM, SashaGreat wrote:
 
 It would be nice if it were like C#:
 
 mixin("x = {0}", x);
 
 More arguments:
 
 mixin("x = {0}; y = {1}", x, y);
 
 S.
No need. import std.stdio; import std.format; void main() { int x; mixin("x = %d;".format(8)); writeln(x); } Its hard to argue for syntax sugar when there is reasonable library code. Going to need to make a clear case argument for why this isn't acceptable. Otherwise a DIP for it would be rejected.
Dec 28 2018
parent reply SashaGreat <s g.com> writes:
On Friday, 28 December 2018 at 12:34:27 UTC, rikki cattermole 
wrote:
 No need.

 import std.stdio;
 import std.format;

 void main() {
     int x;
     mixin("x = %d;".format(8));
     writeln(x);
 }
Yes, but for the second case it would be ugly... mixin("x = {0}; y = {1}", x, y); S.
Dec 28 2018
next sibling parent reply SashaGreat <s g.com> writes:
On Friday, 28 December 2018 at 12:43:28 UTC, SashaGreat wrote:
 On Friday, 28 December 2018 at 12:34:27 UTC, rikki cattermole 
 wrote:
 No need.

 import std.stdio;
 import std.format;

 void main() {
     int x;
     mixin("x = %d;".format(8));
     writeln(x);
 }
Yes, but for the second case it would be ugly... mixin("x = {0}; y = {1}", x, y); S.
By the way, thinking more about it, in C# (My main language), in could easily create a extension for this like: public static Format(string this, object[] args){ // Loop through all the {x} replacing with arg[x] } Then "x = {0}".Format(1); "x = {0}; y = {0}".Format(10, 20); Is this possible with D? S. }
Dec 28 2018
parent JN <666total wp.pl> writes:
On Friday, 28 December 2018 at 12:51:33 UTC, SashaGreat wrote:
 By the way, thinking more about it, in C# (My main language), 
 in could easily create a extension for this like:

 public static Format(string this, object[] args){
     // Loop through all the {x} replacing with arg[x]
 }

 Then

 "x = {0}".Format(1);

 "x = {0}; y = {0}".Format(10, 20);

 Is this possible with D?

 S.
In D, UFCS does what C# extension methods do. If you have a function foo that takes a string argument first, you can either call it as foo(s, somethingsomething) or s.foo(somethingsomething).
Dec 28 2018
prev sibling parent reply rikki cattermole <rikki cattermole.co.nz> writes:
On 29/12/2018 1:43 AM, SashaGreat wrote:
 On Friday, 28 December 2018 at 12:34:27 UTC, rikki cattermole wrote:
 No need.

 import std.stdio;
 import std.format;

 void main() {
     int x;
     mixin("x = %d;".format(8));
     writeln(x);
 }
Yes, but for the second case it would be ugly... mixin("x = {0}; y = {1}", x, y); S.
mixin("x = %d; y = %d;".format(8, 4)); Looks ok to me, given that the original code was ugly as well (it can be improved as a multi-line string).
Dec 28 2018
next sibling parent drug <drug2004 bk.ru> writes:
On 28.12.2018 15:51, rikki cattermole wrote:
 On 29/12/2018 1:43 AM, SashaGreat wrote:
 On Friday, 28 December 2018 at 12:34:27 UTC, rikki cattermole wrote:
 No need.

 import std.stdio;
 import std.format;

 void main() {
     int x;
     mixin("x = %d;".format(8));
     writeln(x);
 }
Yes, but for the second case it would be ugly... mixin("x = {0}; y = {1}", x, y); S.
mixin("x = %d; y = %d;".format(8, 4)); Looks ok to me, given that the original code was ugly as well (it can be improved as a multi-line string).
In practice your mixin string is more complex and format doesn't work so nicely. Sometimes you need to use one argument in several places in mixin string also. But for the case above it works nice sure.
Dec 28 2018
prev sibling parent Adam D. Ruppe <destructionator gmail.com> writes:
On Friday, 28 December 2018 at 12:51:47 UTC, rikki cattermole 
wrote:
 On 29/12/2018 1:43 AM, SashaGreat wrote:
 mixin("x = {0}; y = {1}", x, y);
mixin("x = %d; y = %d;".format(8, 4));
For a more direct translation, you would use positional parameters. mixin("x = %1$s; y = %2$s".format(x, y)); You can write your own function to pretty easily convert between the two string formats if you want. (Or, if going that far, you can just write your own function that avoids `format` and just converts the args and inserts at position.) Though these positional things are different than the interpolation request.
Dec 28 2018
prev sibling next sibling parent Andre Pany <andre s-e-a-p.de> writes:
On Friday, 28 December 2018 at 05:55:30 UTC, Michelle Long wrote:
 The problem with mixing in code is that one has to manually 
 build code strings like:

 static foreach(k; X)
    mixin("int Var"~k~" = "~k~";);

 which is error prone, ugly, time consuming, and harder to read.

 Instead, I propose a simple extension:

 static foreach(k; X)
    mixin("int Var k =  k;");


 Here the   simple, or whatever symbol would be best, takes the 
 variable and inserts it from the outer scope as a string, 
 converting it to a string if necessary.

 It can only be used on such CT variables so errors should not 
 exist.

 If necessary, maybe

 static foreach(k; X)
     mixin("int Var k =  k;");

 or

 static foreach(k; X)
    mixin( "int Var k =  k;");

 could be used.


 This avoids having to do shit like

 mixin("foo("~x~", "~y~", "~z~");");

 so one has

 mixin("foo( x, y, z);");

 which translates almost directly in to standard code(one can 
 simply strip the  's).
As far as I understand you propose a string interpolation syntax for string mixins only. There is currently a DIP for adding general string interpolation to the language. Also there is a library solution available for string interpolation. With string interpolation your use case will become quite readable and less error prone. When the DIP is in a good shape there might be a chance it is added to the language. I just found a post of Walter where he express his open mind for this topic. Kind regards Andre
Dec 28 2018
prev sibling next sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 12/27/2018 9:55 PM, Michelle Long wrote:
 This avoids having to do shit like
Please don't use such words on the forums. We expect professional demeanor.
Dec 28 2018
next sibling parent reply John Colvin <john.loughran.colvin gmail.com> writes:
On Friday, 28 December 2018 at 12:09:30 UTC, Walter Bright wrote:
 On 12/27/2018 9:55 PM, Michelle Long wrote:
 This avoids having to do shit like
Please don't use such words on the forums. We expect professional demeanor.
I'm sure you're bored of hearing this, but workplaces aren't very uniform in expected demeanor across different countries, industries, companies and jobs. Playing on stereotypes: what might be normal behaviour for a sysadmin at an Australian games company would likely be horrifically bad behaviour for a user-facing tech support role in a German accounting software company. Maybe I'm wrong, but I think programmers swearing regularly is pretty normal at work in a lot of places. Maybe there is another description of what you intend that would be more universal. (To be clear, I think I understand what you mean by "professional demeanor", but I've been here a while and inferred from observation what you do and don't put up with, plus I guess a bit based on similarities between UK and USA culture)
Dec 28 2018
next sibling parent reply Jonathan Marler <johnnymarler gmail.com> writes:
On Friday, 28 December 2018 at 14:13:04 UTC, John Colvin wrote:
 On Friday, 28 December 2018 at 12:09:30 UTC, Walter Bright 
 wrote:
 On 12/27/2018 9:55 PM, Michelle Long wrote:
 This avoids having to do shit like
Please don't use such words on the forums. We expect professional demeanor.
I'm sure you're bored of hearing this, but workplaces aren't very uniform in expected demeanor across different countries, industries, companies and jobs. Playing on stereotypes: what might be normal behaviour for a sysadmin at an Australian games company would likely be horrifically bad behaviour for a user-facing tech support role in a German accounting software company. Maybe I'm wrong, but I think programmers swearing regularly is pretty normal at work in a lot of places. Maybe there is another description of what you intend that would be more universal. (To be clear, I think I understand what you mean by "professional demeanor", but I've been here a while and inferred from observation what you do and don't put up with, plus I guess a bit based on similarities between UK and USA culture)
This is just a guess but I think Walter is more sensitive to swearing because of his religious beliefs. I saw a video a while back that made me think he's Mormon. I was raised Mormon and they look down very much on swearing. Nowadays I just find it fun to use for emphasis and humor but I'm careful to only use it around people I know well and I know are comfortable with it. When I was Mormon I probably looked down on people who used it, so even though I don't think there's anything wrong with swearing, I know other people will judge you for it. With so many religious people in the world it's safe to assume someone's going to be offended by that language so it's best to avoid it if you want to Foster a well meaning and diverse community. Anyway, just thought I'd share my thoughts, could all be wrong but maybe it provides another helpful perspective.
Dec 28 2018
parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 12/28/2018 6:46 PM, Jonathan Marler wrote:
 This is just a guess but I think Walter is more sensitive to swearing because
of 
 his religious beliefs.
No. It's about professional demeanor. It's neither hard to understand nor hard to do.
Dec 29 2018
parent reply Jonathan Marler <johnnymarler gmail.com> writes:
On Saturday, 29 December 2018 at 11:37:01 UTC, Walter Bright 
wrote:
 On 12/28/2018 6:46 PM, Jonathan Marler wrote:
 This is just a guess but I think Walter is more sensitive to 
 swearing because of his religious beliefs.
No. It's about professional demeanor. It's neither hard to understand nor hard to do.
Yeah, even though many people enjoy swearing, alot of people are offended by it, so it doesn't make sense for professionals to use it as a bit of humor or emphasis isn't worth the risk of offending people. Based on your response Walter it sounds like you think you were mischaracterized. Just to clarify, I didn't mean to say that you're reason for wanting professionalism is because of your religious beliefs. Professionalism is self justifiable without religion. I was just seeing arguments about whether swearing could be considered professional in some situations (which it could be) but it's not going to be that way on these forums. Based on your beliefs, I think swearing would violate your definition of professional. If I was right about your background then that's not going to change so I was letting people know that debating this would be a waste of time. Plus, I think a public forum is too large of a group to ever think that everyone on it would ever be ok with swearing...the group is just to large and diverse.
Dec 29 2018
parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 12/29/2018 9:26 AM, Jonathan Marler wrote:
 Plus, I think a public forum 
 is too large of a group to ever think that everyone on it would ever be ok
with 
 swearing...the group is just to large and diverse.
People in business are not interested in investing their time and money in a product where the people involved behave like children. They won't be offended, they'll just close the window and move on. They're not going to risk their time and money with such. I don't care what people do in their office. But this is the D Foundation's office, and people here will comport themselves professionally, or will be asked to shape up or ship out.
Dec 29 2018
next sibling parent bachmeier <no spam.net> writes:
On Saturday, 29 December 2018 at 21:57:12 UTC, Walter Bright 
wrote:

 People in business are not interested in investing their time 
 and money in a product where the people involved behave like 
 children. They won't be offended, they'll just close the window 
 and move on. They're not going to risk their time and money 
 with such.

 I don't care what people do in their office. But this is the D 
 Foundation's office, and people here will comport themselves 
 professionally, or will be asked to shape up or ship out.
Same goes for academics. I would never tell a student to post here. There's just no way I'd want to attach my reputation to what is considered okay by programmers in a random office somewhere.
Dec 29 2018
prev sibling parent reply Rubn <where is.this> writes:
On Saturday, 29 December 2018 at 21:57:12 UTC, Walter Bright 
wrote:
 People in business are not interested in investing their time 
 and money in a product where the people involved behave like 
 children.
Okay, but I'm not involved nor are a lot of individuals here, I have zero affiliation with the D foundation. Kind of difficult to tell how is and isn't, seems like it's partially a secret. The forums also don't have that kind of functionality. If I could guess or know someone's email I could probably impersonate them.
 They won't be offended, they'll just close the window and move 
 on. They're not going to risk their time and money with such.

 I don't care what people do in their office. But this is the D 
 Foundation's office, and people here will comport themselves 
 professionally, or will be asked to shape up or ship out.
Every office I've been to doesn't let anyone from the street walk around willy nilly. Yah you have bigger problems if you consider this an office.
Dec 29 2018
parent Mike Parker <aldacron gmail.com> writes:
On Sunday, 30 December 2018 at 02:01:47 UTC, Rubn wrote:


 Every office I've been to doesn't let anyone from the street 
 walk around willy nilly. Yah you have bigger problems if you 
 consider this an office.
Then let's call it the D Community's office, as that's what Walter was getting at. Everything that happens here reflects on the community at large. When people wander in from reddit or elsewhere and see a bunch of flamewars, temper tantrums, and such, they won't acscribe it only to the participants, but to the D Community. We'll turn off those who are serious and fuel those who like to talk smack outside. These forums have been around for many years now in various forms and have generally been decent because the people who participate agree to keep it that way. I count myself among those who would like to see that continue.
Dec 29 2018
prev sibling next sibling parent bauss <jj_1337 live.dk> writes:
On Friday, 28 December 2018 at 14:13:04 UTC, John Colvin wrote:
 On Friday, 28 December 2018 at 12:09:30 UTC, Walter Bright 
 wrote:
 On 12/27/2018 9:55 PM, Michelle Long wrote:
 This avoids having to do shit like
Please don't use such words on the forums. We expect professional demeanor.
I'm sure you're bored of hearing this, but workplaces aren't very uniform in expected demeanor across different countries, industries, companies and jobs. Playing on stereotypes: what might be normal behaviour for a sysadmin at an Australian games company would likely be horrifically bad behaviour for a user-facing tech support role in a German accounting software company. Maybe I'm wrong, but I think programmers swearing regularly is pretty normal at work in a lot of places. Maybe there is another description of what you intend that would be more universal. (To be clear, I think I understand what you mean by "professional demeanor", but I've been here a while and inferred from observation what you do and don't put up with, plus I guess a bit based on similarities between UK and USA culture)
I kinda agree with this. At my company we curse a lot and not because we aren't professional, that's just our culture. We're more like friends/family than just colleagues. I do agree with Walter too that you should refrain from using such phrases if possible.
Dec 29 2018
prev sibling next sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 12/28/2018 6:13 AM, John Colvin wrote:
 Maybe there is another description of what you intend that would be more
universal.
https://www.amazon.com/Emily-Posts-Etiquette-19th-Manners/dp/0062439251 It's not that hard.
Dec 29 2018
parent Rubn <where is.this> writes:
On Saturday, 29 December 2018 at 11:33:54 UTC, Walter Bright 
wrote:
 On 12/28/2018 6:13 AM, John Colvin wrote:
 Maybe there is another description of what you intend that 
 would be more universal.
https://www.amazon.com/Emily-Posts-Etiquette-19th-Manners/dp/0062439251 It's not that hard.
"From social networking to social graces, Emily Post is the definitive source on etiquette for generations of __Americans__." Guess that doesn't include me.
Dec 29 2018
prev sibling parent reply Ethan <gooberman gmail.com> writes:
On Friday, 28 December 2018 at 14:13:04 UTC, John Colvin wrote:
 I'm sure you're bored of hearing this, but workplaces aren't 
 very uniform in expected demeanor across different countries, 
 industries, companies and jobs. Playing on stereotypes: what 
 might be normal behaviour for a sysadmin at an Australian games 
 company would likely be horrifically bad behaviour for a 
 user-facing tech support role in a German accounting software 
 company.
Can confirm that I've used the phrase "next level shit" at my GDC presentation. Certainly what's considered professional in my industry (an entertainment industry) doesn't fly with classic white-collar IT. (TIL that it's now classified gold-collar. Whatevs.) Swears are fine where I'm from. Using swears to demean or insult someone doesn't matter, you're still being demeaning and insulting ie a dick. Don't be a dick. Of course, I don't mind keeping it white-collar when I post here. I swear a lot in person, use blue-ish humour to get a point across. But on a forum, I have the luxury of time to think about how to say something in a clean manner.
Dec 29 2018
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 12/29/18 9:20 AM, Ethan wrote:
 On Friday, 28 December 2018 at 14:13:04 UTC, John Colvin wrote:
 I'm sure you're bored of hearing this, but workplaces aren't very 
 uniform in expected demeanor across different countries, industries, 
 companies and jobs. Playing on stereotypes: what might be normal 
 behaviour for a sysadmin at an Australian games company would likely 
 be horrifically bad behaviour for a user-facing tech support role in a 
 German accounting software company.
Can confirm that I've used the phrase "next level shit" at my GDC presentation. Certainly what's considered professional in my industry (an entertainment industry) doesn't fly with classic white-collar IT. (TIL that it's now classified gold-collar. Whatevs.) Swears are fine where I'm from. Using swears to demean or insult someone doesn't matter, you're still being demeaning and insulting ie a dick. Don't be a dick. Of course, I don't mind keeping it white-collar when I post here. I swear a lot in person, use blue-ish humour to get a point across. But on a forum, I have the luxury of time to think about how to say something in a clean manner.
Thanks. That's exactly the spirit. (FWIW that talk was a riot and I wouldn't ask you to change it at all.) We're trying to stay light on formal rules and rely on common sense among adults in a professional organization. The "but my organization does allow that" retort does not impose on the Foundation the least common denominator of all posters' respective organizations, and should not be used in an attempt to game the system. Just like Ethan, I'm convinced people understand and appreciate the variations across workplaces and what the middle road would be. Happy New Year! Andrei
Dec 30 2018
prev sibling next sibling parent reply Neia Neutuladh <neia ikeran.org> writes:
On Fri, 28 Dec 2018 04:09:30 -0800, Walter Bright wrote:
 On 12/27/2018 9:55 PM, Michelle Long wrote:
 This avoids having to do shit like
Please don't use such words on the forums. We expect professional demeanor.
Based on enforcement, I'd say it's a rule against swearing specifically. At my job, I can say it's fucked up that swagger-codegen for Java produces broken JAX-RS code by default, but if I responded to a coworker missing something in documentation by sending them a link to the Wikipedia page for confirmation bias, that wouldn't be acceptable. On the newsgroups, though, the opposite is true.
Dec 28 2018
next sibling parent reply Paul Backus <snarwin gmail.com> writes:
On Friday, 28 December 2018 at 17:47:41 UTC, Neia Neutuladh wrote:
 On Fri, 28 Dec 2018 04:09:30 -0800, Walter Bright wrote:
 On 12/27/2018 9:55 PM, Michelle Long wrote:
 This avoids having to do shit like
Please don't use such words on the forums. We expect professional demeanor.
Based on enforcement, I'd say it's a rule against swearing specifically. At my job, I can say it's fucked up that swagger-codegen for Java produces broken JAX-RS code by default, but if I responded to a coworker missing something in documentation by sending them a link to the Wikipedia page for confirmation bias, that wouldn't be acceptable. On the newsgroups, though, the opposite is true.
"No swearing" is a bright-line rule [1] that's easy to understand and to enforce. "No passive-aggressive Wikipedia links", on the other hand, requires a certain amount of subjective judgment, and as a result has more potential to lead to misunderstandings. When you have a relatively small group of people who all know each other, misunderstandings aren't too difficult to resolve, but when you have a large group of people, many of whom are complete strangers to one another, it can become quite difficult. So it makes sense that a public newsgroup, which is more like the second kind of group, would favor simple, clear rules, at the expense of nuance. [1] https://www.law.cornell.edu/wex/bright-line_rule
Dec 28 2018
parent reply Neia Neutuladh <neia ikeran.org> writes:
On Fri, 28 Dec 2018 18:39:40 +0000, Paul Backus wrote:
 "No swearing" is a bright-line rule [1] that's easy to understand and to
 enforce.
Yes. My primary complaint is that the rule is called "be professional" and is enforced as "don't swear".
 When you have a relatively small group of people who all know each
 other, misunderstandings aren't too difficult to resolve, but when you
 have a large group of people, many of whom are complete strangers to one
 another, it can become quite difficult.
Yes, maintaining a community is quite difficult.
Dec 28 2018
parent Walter Bright <newshound2 digitalmars.com> writes:
On 12/28/2018 12:00 PM, Neia Neutuladh wrote:
 Yes. My primary complaint is that the rule is called "be professional" and
 is enforced as "don't swear".
No, it is not. There have been many posts removed for unprofessional behavior that did not involve swearing.
Dec 29 2018
prev sibling next sibling parent rikki cattermole <rikki cattermole.co.nz> writes:
On 29/12/2018 6:47 AM, Neia Neutuladh wrote:
 On Fri, 28 Dec 2018 04:09:30 -0800, Walter Bright wrote:
 On 12/27/2018 9:55 PM, Michelle Long wrote:
 This avoids having to do shit like
Please don't use such words on the forums. We expect professional demeanor.
Based on enforcement, I'd say it's a rule against swearing specifically. At my job, I can say it's fucked up that swagger-codegen for Java produces broken JAX-RS code by default, but if I responded to a coworker missing something in documentation by sending them a link to the Wikipedia page for confirmation bias, that wouldn't be acceptable. On the newsgroups, though, the opposite is true.
Its not specific to swearing. Your usage of the word "fucked" here is ok for example. You're not using it as an adjective. Just stating a context for which it has been used in. We do badly at it, but a large point of the purpose of that rule is to stop aggressive tones and hateful discussion. With insults going back in forth. For this reason it works rather well. Either way, this is getting rather off-topic.
Dec 28 2018
prev sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 12/28/2018 9:47 AM, Neia Neutuladh wrote:
 I'd say it's a rule against swearing specifically.
No, it is not. Neither is it about religion nor my being offended. If anyone has difficulty understanding how to behave in a professional manner, I suggest: https://www.amazon.com/Emily-Posts-Etiquette-19th-Manners/dp/0062439251 If you like, think of it as the D forum style guide. After all, we have a style guide for code submissions.
Dec 29 2018
parent reply bauss <jj_1337 live.dk> writes:
On Saturday, 29 December 2018 at 11:56:03 UTC, Walter Bright 
wrote:
 On 12/28/2018 9:47 AM, Neia Neutuladh wrote:
 I'd say it's a rule against swearing specifically.
No, it is not. Neither is it about religion nor my being offended. If anyone has difficulty understanding how to behave in a professional manner, I suggest: https://www.amazon.com/Emily-Posts-Etiquette-19th-Manners/dp/0062439251 If you like, think of it as the D forum style guide. After all, we have a style guide for code submissions.
I don't think anyone would be willing to read a book to post on a forum.
Dec 29 2018
parent Walter Bright <newshound2 digitalmars.com> writes:
On 12/29/2018 4:05 AM, bauss wrote:
 I don't think anyone would be willing to read a book to post on a forum.
Some books everyone should read. That one will pay off in far more circumstances than this forum. Consider it an investment, like reading Martin's "Clean Code" book. https://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882
Dec 29 2018
prev sibling parent reply Rubn <where is.this> writes:
On Friday, 28 December 2018 at 12:09:30 UTC, Walter Bright wrote:
 On 12/27/2018 9:55 PM, Michelle Long wrote:
 This avoids having to do shit like
Please don't use such words on the forums. We expect professional demeanor.
I always find it amusing when people are offended because a particular word is used. Not even in the context it was used, merely that the word was used. I can easily and effortlessly say something much less professional without the use of such curse words. Someone interjected about my use of curse words in public, I insulted them in another language, and they were none the wiser. It's just a word, the person that gives it meaning is you. If you want to interpret the word in a way it wasn't used then that's on you. I find it funny radio and tv all have to bleep out these words when I can literally go on youtube and effortlessly find a video where they say "fuck" every 5 seconds without so much as a "i am totally this age and it is not made up so I can view the video" button. Oh how times change. tabarnak eh, monsieur Walter
Dec 28 2018
next sibling parent reply Neia Neutuladh <neia ikeran.org> writes:
On Sat, 29 Dec 2018 04:17:07 +0000, Michelle Long wrote:
 Basically it means black... but we can't use it because it's "offensive"
 because some psychopaths used it. People are morons. Most of the time
 they have no direct connection to the word but just perpetuate the
 problem.
Vocabulary is used, on occasion, to indicate allegiance. This is arbitrary, but so are flags, uniforms, armbands, and gestures, which are also used to indicate allegiance. In this case, the word is used to indicate allegiance to an ideal of racism.
Dec 28 2018
parent rikki cattermole <rikki cattermole.co.nz> writes:
That's enough.
Lets get back to the topic at hand, string mixin's improvements.
Dec 29 2018
prev sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 12/28/2018 12:41 PM, Rubn wrote:
 I always find it amusing when people are offended
It's not about being offended. I'm not offended. Would you pick up your date for the prom wearing track shorts? I wouldn't, either. On the D forums, I expect all to behave in a professional manner. That includes the dlang github repository.
Dec 29 2018
parent Rubn <where is.this> writes:
On Saturday, 29 December 2018 at 11:44:16 UTC, Walter Bright 
wrote:
 On 12/28/2018 12:41 PM, Rubn wrote:
 I always find it amusing when people are offended
It's not about being offended. I'm not offended.
Then what is the problem ?
 Would you pick up your date for the prom wearing track shorts? 
 I wouldn't, either. On the D forums, I expect all to behave in 
 a professional manner.
Who says you can't wear track shorts to prom? Who deemed that isn't acceptable? If you want to succumb to peer pressure, you can do so. But don't put pressure onto other individuals to follow your social norms.
 That includes the dlang github repository.
So if someone created a pull request and they included a swear word in the comment of the pull request, you would close it? I mean I know it would sit in the pull request queue until it becomes outdated someone needs to close it then creates a new one and reimplements it. But just hypothetically speaking, if you had the authority and were in charge of maintaining pull requests.
Dec 29 2018
prev sibling parent reply Dgame <r.schuett.1987 gmail.com> writes:
Hi, I've played around with string interpolation and wanted to 
ask if this is somewhat helpful?

https://run.dlang.io/is/6AokiH
Jan 02
parent reply Bastiaan Veelo <Bastiaan Veelo.net> writes:
On Wednesday, 2 January 2019 at 18:59:53 UTC, Dgame wrote:
 Hi, I've played around with string interpolation and wanted to 
 ask if this is somewhat helpful?

 https://run.dlang.io/is/6AokiH
You are aware of `writefln`?
    writeln(fmt!("a = $a, b = $b, c = $c", a, b, c));
    writefln("a = %s, b = %s, c = %s", a, b, c);
These lines produce the same output.
Jan 02
next sibling parent reply Jordan Wilson <wilsonjord gmail.com> writes:
On Wednesday, 2 January 2019 at 21:06:19 UTC, Bastiaan Veelo 
wrote:
 On Wednesday, 2 January 2019 at 18:59:53 UTC, Dgame wrote:
 Hi, I've played around with string interpolation and wanted to 
 ask if this is somewhat helpful?

 https://run.dlang.io/is/6AokiH
You are aware of `writefln`?
    writeln(fmt!("a = $a, b = $b, c = $c", a, b, c));
    writefln("a = %s, b = %s, c = %s", a, b, c);
These lines produce the same output.
This also produces the same output: writeln(fmt!("a = $a, b = $b, c = $c", c, a, b)); From what I can see, fmt removes the positional relationship between the vars and the format specifiers, but you still have to supply the actual variables themselves as arguments, which is a redundancy that string interpolation in some other languages don't appear to have. Jordan
Jan 02
parent Dgame <r.schuett.1987 gmail.com> writes:
On Wednesday, 2 January 2019 at 21:52:06 UTC, Jordan Wilson wrote:
 On Wednesday, 2 January 2019 at 21:06:19 UTC, Bastiaan Veelo 
 wrote:
 On Wednesday, 2 January 2019 at 18:59:53 UTC, Dgame wrote:
 Hi, I've played around with string interpolation and wanted 
 to ask if this is somewhat helpful?

 https://run.dlang.io/is/6AokiH
You are aware of `writefln`?
    writeln(fmt!("a = $a, b = $b, c = $c", a, b, c));
    writefln("a = %s, b = %s, c = %s", a, b, c);
These lines produce the same output.
This also produces the same output: writeln(fmt!("a = $a, b = $b, c = $c", c, a, b)); From what I can see, fmt removes the positional relationship between the vars and the format specifiers, but you still have to supply the actual variables themselves as arguments, which is a redundancy that string interpolation in some other languages don't appear to have. Jordan
That is correct, I might have been a bit hasty in sharing my little experiment.
Jan 02
prev sibling parent reply Dgame <r.schuett.1987 gmail.com> writes:
On Wednesday, 2 January 2019 at 21:06:19 UTC, Bastiaan Veelo 
wrote:
 On Wednesday, 2 January 2019 at 18:59:53 UTC, Dgame wrote:
 Hi, I've played around with string interpolation and wanted to 
 ask if this is somewhat helpful?

 https://run.dlang.io/is/6AokiH
You are aware of `writefln`?
    writeln(fmt!("a = $a, b = $b, c = $c", a, b, c));
    writefln("a = %s, b = %s, c = %s", a, b, c);
These lines produce the same output.
Yes I do. But consider this: int c = 3; int z = c * c; writefln("%s * %s = %s", c, c, z); vs writeln(fmt!("$c * $c = $z", c, z)); Just one c is applied. But I've disovered one slightly error here, the interpolation variables should be enclosed with { to prevent mistakenly replacement. Also, currently no further "magic" as ${c * 2} can't be interpreted as someone might wish, it is somewhat static, but I've thought it might be interesting.
Jan 02
parent Steven Schveighoffer <schveiguy gmail.com> writes:
On 1/2/19 4:54 PM, Dgame wrote:
 On Wednesday, 2 January 2019 at 21:06:19 UTC, Bastiaan Veelo wrote:
 On Wednesday, 2 January 2019 at 18:59:53 UTC, Dgame wrote:
 Hi, I've played around with string interpolation and wanted to ask if 
 this is somewhat helpful?

 https://run.dlang.io/is/6AokiH
You are aware of `writefln`?
    writeln(fmt!("a = $a, b = $b, c = $c", a, b, c));
    writefln("a = %s, b = %s, c = %s", a, b, c);
These lines produce the same output.
Yes I do. But consider this: int c = 3; int z = c * c; writefln("%s * %s = %s", c, c, z); vs writeln(fmt!("$c * $c = $z", c, z)); Just one c is applied. But I've disovered one slightly error here, the interpolation variables should be enclosed with { to prevent mistakenly replacement. Also, currently no further "magic" as ${c * 2} can't be interpreted as someone might wish, it is somewhat static, but I've thought it might be interesting.
It's better, but still is not DRY enough. I still have to repeat the variable name. In terms of string interpolation, the point is to put the reference right at the usage, not to repeat it elsewhere. And as you alluded to, it's very key for string interpolation to allow arbitrary expressions. -Steve
Jan 02