Skip to main content
deleted 1621 characters in body
Source Link
chakrit
  • 61.6k
  • 25
  • 138
  • 164

If you need more readibility, just rename it to 'Formats' or 'FormatWith'.

For quick copy-and-paste go here.


 

I'd like to clarify that I keep it as a simple "F" because there is least visual clutter whenDon't you wantfind it more natural to format string in-placetype "some string".F("param") instead of string.Format("some string", "param") ?

For a more readable name, as in the following exampletry one of these suggestion:

// withs just= "F"
Console.WriteLine("At"Hello ({0}, world {1}!".Fmt("Stack", "Overflow");
s color= is"Hello {20} world {1}!".FFormatBy(src.X, src.Y"Stack", color)"Overflow");
 
// withs longer= "FormatsWith"
Console.WriteLine("At"Hello ({0}, world {1}!".FormatWith("Stack", "Overflow");
s color= is"Hello {20} world {1}!".FormatsWithDisplay(src.X"Stack", src"Overflow");
s = "Hello {0} world {1}!".YWith("Stack", color)"Overflow");

I'd even go so far as to say that a simple "F" conveys meaning faster than "FormatsWith". The difference between the two statements above, other than 10 more characters to auto-complete... is that to read the statement, you'd have to "read" the word "FormatsWith" out loud in your head, you can't skip it quickly enough because it has 11 characters. While with a simple "F", it becomes a passive uninterrupting background noise and allow you to map src.X with {0}, src.Y with {1}.. right away. It feels more like a language feature than a method call. But that's just me.

My point was that what is the first thing you that comes into your mind when you see a curly brace with a number inside {0} and a corresponding parameter on the right?

I believe everyone with some .NET experience will associate it with string.Format first thing. And that is enough readability for me, readability matters more in the grander scheme of your code than just little easily-guessed helper methods.

And there is always the "Go to definition menu" that'll confirms, when you have a doubt, with a look at the one simple string.Format statement lying at the destination.

And when you use that as a pattern consistent throughout your code...

But I won't encourage it, if you feels like "Formats" or "Injects" or "FormatsWith" would suit you or your team better, then I'd like you to use that.

It's just an idea, you can implement it however you like. Verbosity is another subject to be arguing entirely, if you'd ask me.

p.s. how do I make this shorter?

If you need more readibility, just rename it to 'Formats' or 'FormatWith'.

For quick copy-and-paste go here.


 

I'd like to clarify that I keep it as a simple "F" because there is least visual clutter when you want to format string in-place, as in the following example:

// with just "F"
Console.WriteLine("At ({0}, {1}) color is {2}".F(src.X, src.Y, color));
 
// with longer "FormatsWith"
Console.WriteLine("At ({0}, {1}) color is {2}".FormatsWith(src.X, src.Y, color));

I'd even go so far as to say that a simple "F" conveys meaning faster than "FormatsWith". The difference between the two statements above, other than 10 more characters to auto-complete... is that to read the statement, you'd have to "read" the word "FormatsWith" out loud in your head, you can't skip it quickly enough because it has 11 characters. While with a simple "F", it becomes a passive uninterrupting background noise and allow you to map src.X with {0}, src.Y with {1}.. right away. It feels more like a language feature than a method call. But that's just me.

My point was that what is the first thing you that comes into your mind when you see a curly brace with a number inside {0} and a corresponding parameter on the right?

I believe everyone with some .NET experience will associate it with string.Format first thing. And that is enough readability for me, readability matters more in the grander scheme of your code than just little easily-guessed helper methods.

And there is always the "Go to definition menu" that'll confirms, when you have a doubt, with a look at the one simple string.Format statement lying at the destination.

And when you use that as a pattern consistent throughout your code...

But I won't encourage it, if you feels like "Formats" or "Injects" or "FormatsWith" would suit you or your team better, then I'd like you to use that.

It's just an idea, you can implement it however you like. Verbosity is another subject to be arguing entirely, if you'd ask me.

p.s. how do I make this shorter?

For quick copy-and-paste go here.

Don't you find it more natural to type "some string".F("param") instead of string.Format("some string", "param") ?

For a more readable name, try one of these suggestion:

s = "Hello {0} world {1}!".Fmt("Stack", "Overflow");
s = "Hello {0} world {1}!".FormatBy("Stack", "Overflow");
s = "Hello {0} world {1}!".FormatWith("Stack", "Overflow");
s = "Hello {0} world {1}!".Display("Stack", "Overflow");
s = "Hello {0} world {1}!".With("Stack", "Overflow");

..

Post Made Community Wiki by CommunityBot
added clarification due to number of comments
Source Link
chakrit
  • 61.6k
  • 25
  • 138
  • 164

string.Format shortcut:

public static class StringExtensions
{
    // Enable quick and more natural string.Format calls
    public static string F(this string s, params object[] args)
    {
        return string.Format(s, args);
    }
}

Example:

var s = "The co-ordinate is ({0}, {1})".F(point.X, point.Y);

If you need more readibility, just rename it to 'Formats' or 'FormatWith'.

For quick copy-and-paste go here.


I'd like to clarify that I keep it as a simple "F" because there is least visual clutter when you want to format string in-place, as in the following example:

// with just "F"
Console.WriteLine("At ({0}, {1}) color is {2}".F(src.X, src.Y, color));

// with longer "FormatsWith"
Console.WriteLine("At ({0}, {1}) color is {2}".FormatsWith(src.X, src.Y, color));

I'd even go so far as to say that a simple "F" conveys meaning faster than "FormatsWith". The difference between the two statements above, other than 10 more characters to auto-complete... is that to read the statement, you'd have to "read" the word "FormatsWith" out loud in your head, you can't skip it quickly enough because it has 11 characters. While with a simple "F", it becomes a passive uninterrupting background noise and allow you to map src.X with {0}, src.Y with {1}.. right away. It feels more like a language feature than a method call. But that's just me.

My point was that what is the first thing you that comes into your mind when you see a curly brace with a number inside {0} and a corresponding parameter on the right?

I believe everyone with some .NET experience will associate it with string.Format first thing. And that is enough readability for me, readability matters more in the grander scheme of your code than just little easily-guessed helper methods.

And there is always the "Go to definition menu" that'll confirms, when you have a doubt, with a look at the one simple string.Format statement lying at the destination.

And when you use that as a pattern consistent throughout your code...

But I won't encourage it, if you feels like "Formats" or "Injects" or "FormatsWith" would suit you or your team better, then I'd like you to use that.

It's just an idea, you can implement it however you like. Verbosity is another subject to be arguing entirely, if you'd ask me.

p.s. how do I make this shorter?

string.Format shortcut:

public static class StringExtensions
{
    // Enable quick and more natural string.Format calls
    public static string F(this string s, params object[] args)
    {
        return string.Format(s, args);
    }
}

Example:

var s = "The co-ordinate is ({0}, {1})".F(point.X, point.Y);

If you need more readibility, just rename it to 'Formats' or 'FormatWith'.

For quick copy-and-paste go here.

string.Format shortcut:

public static class StringExtensions
{
    // Enable quick and more natural string.Format calls
    public static string F(this string s, params object[] args)
    {
        return string.Format(s, args);
    }
}

Example:

var s = "The co-ordinate is ({0}, {1})".F(point.X, point.Y);

If you need more readibility, just rename it to 'Formats' or 'FormatWith'.

For quick copy-and-paste go here.


I'd like to clarify that I keep it as a simple "F" because there is least visual clutter when you want to format string in-place, as in the following example:

// with just "F"
Console.WriteLine("At ({0}, {1}) color is {2}".F(src.X, src.Y, color));

// with longer "FormatsWith"
Console.WriteLine("At ({0}, {1}) color is {2}".FormatsWith(src.X, src.Y, color));

I'd even go so far as to say that a simple "F" conveys meaning faster than "FormatsWith". The difference between the two statements above, other than 10 more characters to auto-complete... is that to read the statement, you'd have to "read" the word "FormatsWith" out loud in your head, you can't skip it quickly enough because it has 11 characters. While with a simple "F", it becomes a passive uninterrupting background noise and allow you to map src.X with {0}, src.Y with {1}.. right away. It feels more like a language feature than a method call. But that's just me.

My point was that what is the first thing you that comes into your mind when you see a curly brace with a number inside {0} and a corresponding parameter on the right?

I believe everyone with some .NET experience will associate it with string.Format first thing. And that is enough readability for me, readability matters more in the grander scheme of your code than just little easily-guessed helper methods.

And there is always the "Go to definition menu" that'll confirms, when you have a doubt, with a look at the one simple string.Format statement lying at the destination.

And when you use that as a pattern consistent throughout your code...

But I won't encourage it, if you feels like "Formats" or "Injects" or "FormatsWith" would suit you or your team better, then I'd like you to use that.

It's just an idea, you can implement it however you like. Verbosity is another subject to be arguing entirely, if you'd ask me.

p.s. how do I make this shorter?

added pastebin link
Source Link
chakrit
  • 61.6k
  • 25
  • 138
  • 164

string.Format shorthandshortcut:

public static class StringExtensions
{
    // Enable quick and more natural string.Format calls
    public static string F(this string s, params object[] args)
    {
        return string.Format(s, args);
    }
}

Example:

var s = "The co-ordinate is ({0}, {1})".F(point.X, point.Y);

If you need more readibility, just rename it to 'Format''Formats' or 'FormatWith'.

For quick copy-and-paste go here.

string.Format shorthand:

public static class StringExtensions
{
    // Enable quick and more natural string.Format calls
    public static string F(this string s, params object[] args)
    {
        return string.Format(s, args);
    }
}

Example:

var s = "The co-ordinate is ({0}, {1})".F(point.X, point.Y);

If you need more readibility, just rename it to 'Format' or 'FormatWith'.

string.Format shortcut:

public static class StringExtensions
{
    // Enable quick and more natural string.Format calls
    public static string F(this string s, params object[] args)
    {
        return string.Format(s, args);
    }
}

Example:

var s = "The co-ordinate is ({0}, {1})".F(point.X, point.Y);

If you need more readibility, just rename it to 'Formats' or 'FormatWith'.

For quick copy-and-paste go here.

deleted 9 characters in body
Source Link
chakrit
  • 61.6k
  • 25
  • 138
  • 164
Loading
added 73 characters in body
Source Link
chakrit
  • 61.6k
  • 25
  • 138
  • 164
Loading
added 1 characters in body
Source Link
chakrit
  • 61.6k
  • 25
  • 138
  • 164
Loading
Source Link
chakrit
  • 61.6k
  • 25
  • 138
  • 164
Loading