Continue Discussion 31 replies
July 2006

codinghorror

In case you were wondering what Brad is doing these days, Brad has moved up and on from the .NET CLR team. He’s currently the group program manager for the UI Framework and Services team. His team owns ASP.NET, Atlas, and Windows Forms.

Super, super nice guy. And one of the best MS blogs out there too:

http://blogs.msdn.com/BradA/

July 2006

John_Lam

I used to like String.Format before I discovered Ruby. The {n} thing is OK until n becomes a reasonably large number (5+/-2). Then it becomes a lot harder to read.

String.Format(“My name is {0} {1} and I’m a {2}”, firstName, lastName, citizenship)

vs.

“My name is #{first_name} #{last_name} and I’m a #{citizenship}”

July 2006

Alyosha8

My favorite STL class? string. :slight_smile:

Second most favorite? vector.

July 2006

foobar

“My name is #{first_name} #{last_name} and I’m a #{citizenship}”

ColdFusion has something really similar:

“My name is #first_name# #last_name# and I’m a #citizenship#”

That and grouping were about the only two things I sorta miss about using CF.

July 2006

Morgan

More posters:
http://msdn.microsoft.com/vstudio/previous/2003/posters/
I have these on my walls at work, and at home.

Don’t think they have 2005 yet :frowning:

July 2006

Martin

They don’t have .NET 2.0 posters because they added so many classes that, just like Java, they cannot make it fit…

:wink:

July 2006

AndrewS

Java and .NET String are both a big step up from C and even from C++'s std::string, but are still fairly primitive tools compared to the string capabilities of dynamic “scripting” languages like Perl, Python, and Ruby. So its important to keep things in perspective.

July 2006

KevinS

String concatenation is still useful over string.format because it is an order of magnitude faster! string.format may be easier to read, but the performance difference can really show in a tight loop. Try it!

July 2006

Nick_Hodges

String is cool and all, but it’s /sealed/. Argh!

July 2006

Haacked

Jeff, you’d love what Resharper does for strings.

If you have code like this:

string s = "This " + verb + " freaking " + adjective + " I want to " + verb;

It puts a little smart tag next to it and lets you convert it to a format string. Good for cleaning up ugly string concats.

July 2006

codinghorror

C strings (bstr, tstring, wstring, const char*, wchar*, etc.) are so durn ugly

True; I don’t think string is a native datatype in C or C++. Hard to imagine for modern languages.

My love for strings is so deep and so wide that it extends to all things string-related. I’m a huge StringBuilder fan, too.

I’m thinking of naming my first born child StringBuilder.

July 2006

Shawn_Oster

To John Lam… you have the same type of inline syntax in PHP, and I’m sure a few dozen other languages. Ruby is great but that feature is far from unique.

Oh, and I think a sealed Strings class is great. There is nothing more annoying than having to maintain someone else’s code and seeing a class that you think you know how works but you don’t, because it’s a funky inherited type of a base system class and they’ve overridden half of it. Blench.

July 2006

Scott

Aye, I have to agree strings are wonderful, but concur with Nick. Its Sealed! This is OO days, we want to inherit and extend that functionality, not be told we can’t. Sealed, in this instance, is taking a big step backwards in my opinion. :slight_smile:

July 2006

Ben_Moxon

From all I’ve heard String.Concat does perform a bit better than String.Format and a lot better than “a”+“b”+“c” for patching together long strings. Obviously String.Format has it’s own advantages in many cases but if you just want to tie a bunch of strings together concat is a good option.

July 2006

engtech

How is String.Format any different than printf/sprintf that has been around for ever?

July 2006

codinghorror

It’s not any different, it just supports a zillion more output formats. Unfortunately, it doesn’t support named value key/pair substitution as shown in Ruby and PHP via previous commenters…

July 2006

Scott

Hi Shawn, I do disagree a little.

Not all of us are from the C/C++ world. I personally use Delphi.net, and I personally think OO inheritance is a great option/tool.

Just because some people love operator overloading doesn’t mean you should remove the ability to inherit from that base class. Personally we can extend a class (yes I use different names for my new classes, but I know what you are talking about) to provide more then just the base class offerings.

There are plenty of times I’ve wanted to extend from a class in .NET and been denied the means, because it’s sealed. Personally I think sealed has its place, but it seems a little overused currently on some classes in the framework. :slight_smile:

July 2006

Erik_Lane

I want to second Haack on how ReSharper 2.0 cleans up string concatenation. It may new favorite feature and lets me know how much I was using " + "…

July 2006

Masklinn

Shawn Oster said
To John Lam… you have the same type of inline syntax in PHP, and I’m sure a few dozen other languages. Ruby is great but that feature is far from unique.

PHP has an inline syntax, but it’s quirky and error prone, Ruby’s inline syntax (some other languages have that kind of syntax indeed) is cleaner and mostly error-free.

July 2006

Steve

Strings.

Well, I guess I am the killjoy bastard, I frankly don’t know why people so much enjoy String.
When you have to deal with UI ok, use strings.
In a previous job, one rewarded architect choose to use xml/soap/kinf of communication. the main reason put forward, was human readable. Woo, an guess what it was communication over an SSL layer. So i wonder to which kind of human these kind of communication are dedicated.

So People understand string, give them string; computers understand binary give them binary.

Some people try to talk with dogs, and pets. it doesn’t work but they still do it and find it fun and cool. I was hoping IT world was a bit more reasonnable…

Peace,

July 2006

Nij

I have found C# String.Format to be incredibly useful, but a major bugbear for me is bad error reporting if I make a mistake in the format. Things go distinctly awry if your code is off the UI thread, IIRC.
But of course - you may just attribute that to bad programming!

July 2006

JustinS

String.Format…woooonderful stuff, I agree. What’s even better is being able to specify your formats in the web.config for greater maintainability.

IE:

Name: {0} {1}

can easily be changed to:

Name: {1}, {0}

…if you put the format string in the x.config. I’m a huge fan of stuff like this.

July 2006

Qwerty

Python even has an operator for string formatting:

brian = (“Bring”, “out”, “yer dead!”)
european_swallow = “%s %s %s” % brian
african_swallow = " ".join(brian)

July 2006

Qwerty

arthur = "Bring out %(possesive)s %(state)s!"
brian = { state: “dead”, possessive: “yer” }
european_swallow = arthur % brian

July 2008

Giel

If there’s one thing I don’t like about the whole class of formatting strings in C is that you loose all forms of type safety while using it. Yes a compiler like GCC (too my knowledge the only one atually) still performs type checking and gives you warnings (which I always turn into errors) when you have type mismatches… But still, I like an approach like Boost.Format’s much better (i.e. you don’t loose the type safety of the language).

July 2008

Tom

Some people try to talk with dogs, and pets. It doesn’t work but they still do it and find it fun and cool. I was hoping the IT world was a bit more reasonable…
SIT! SIIIIT… STAY… Now, Output! Good code.
Aw no, the damn thing just recursed all over the stack.

July 2008

James

@Giel: he’s not talking about printf (which does have type-safety issues), he’s talking about .NET Strings. All .NET objects derive from Object, and Object implements a .ToString() method, which means that all types can be converted to a string. Which, as I’m sure Jeff would agree, is beautiful.

September 2008

Jeff

Argh, this sort of thing drives me crazy. There’s a Sniglet called asterexasper (if I recall correctly), that is defined like this: When a sentence has an asterisk in it but the corresponding footnote doesn’t exist.

This article contains an asterexasper in this sentence: Regular expressions, for example, are themselves strings, as is SQL.*

So what WAS the footnote suppose to be, huh?

January 2009

DouglasM

That asterexasper bugged me too, so I invented my own footnote. :slight_smile:

*Well, the concrete syntax is anyway. Of course you could argue that the language itself is defined by its abstract syntax, and is more of a tree than a string.

January 2009

DouglasM

That asterexasper bugged me too, so I invented my own footnote. :slight_smile:

*Well, the concrete syntax is anyway. Of course you could argue that the language itself is defined by its abstract syntax, and is more of a tree than a string.

February 2010

JonG

The .NET (and Java) string classes look so good because C strings (bstr, tstring, wstring, const char*, wchar*, etc.) are so durn ugly.