<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: C Tip: Safe String Manipulation</title>
	<link>http://gdmike.statbuff.com/2006/09/15/c-tip-safe-string-manipulation/</link>
	<description>News, opinions, articles, tips &#038; tricks on game development with an Indie twist.</description>
	<pubDate>Fri, 21 Nov 2008 18:38:28 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
		<item>
		<title>By: Programmer16</title>
		<link>http://gdmike.statbuff.com/2006/09/15/c-tip-safe-string-manipulation/#comment-874</link>
		<dc:creator>Programmer16</dc:creator>
		<pubDate>Mon, 18 Sep 2006 06:44:42 +0000</pubDate>
		<guid>http://gdmike.statbuff.com/2006/09/15/c-tip-safe-string-manipulation/#comment-874</guid>
		<description>The OO (sorry, I should actually say class-based design or something) wasn't the only reason, as I said it was part of the reason. Safety and cleaner code would be a couple other reasons (safety would have been a lot better choice than what I said.)

I misused the term OO because I was quite tired (as you can see I posted at 7am, I think that puts me at being up for about 36 hours since I didn't go to bed on time the day before either lol.) I do understand that object orientation isn't just about classes.

I actually just switched over to using C++ strings most of the time (unless C-strings are needed) a couple months ago.</description>
		<content:encoded><![CDATA[<p>The OO (sorry, I should actually say class-based design or something) wasn&#8217;t the only reason, as I said it was part of the reason. Safety and cleaner code would be a couple other reasons (safety would have been a lot better choice than what I said.)</p>
<p>I misused the term OO because I was quite tired (as you can see I posted at 7am, I think that puts me at being up for about 36 hours since I didn&#8217;t go to bed on time the day before either lol.) I do understand that object orientation isn&#8217;t just about classes.</p>
<p>I actually just switched over to using C++ strings most of the time (unless C-strings are needed) a couple months ago.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gdmike</title>
		<link>http://gdmike.statbuff.com/2006/09/15/c-tip-safe-string-manipulation/#comment-846</link>
		<dc:creator>gdmike</dc:creator>
		<pubDate>Sun, 17 Sep 2006 15:57:35 +0000</pubDate>
		<guid>http://gdmike.statbuff.com/2006/09/15/c-tip-safe-string-manipulation/#comment-846</guid>
		<description>That's why this is labeled as a C Tip and not a C++ Tip :) I've been a C user for some years now, so I'm just used to C strings. I think your reasoning about using std::string, because it's "OO", is flawed. 

The fact that std::string has an object oriented design does not by itself make it inherently better than C's string API. In fact, there are different pitfalls that you don't need to worry about with C strings (a side effect of the C++ language, not object orientation in general). The benefits come from the implementation details, not the fact that you can call methods on it with str.method syntax. 

Second, there's nothing that prevents you from using free functions in an OO design. Object orientation is not about classes - that's just an implementation detail. Object orientation is about objects, and such a design can be implemented in C easily enough. Languages like C++ just give you the tools to make the implementation easier.

I suggest you take a look at the &lt;a href="http://www.digitalmars.com/d/index.html" rel="nofollow" rel="nofollow"&gt;D programming language&lt;/a&gt;. D's strings are similar to those in C -- arrays of characters manipulated with free functions. The biggest difference is that D strings don't need to be null terminated, since arrays are actually structs under the hood that contain a data pointer and a length value. Another feature of D is that you can use the first argument to a function with . syntax (so that doSomething(myStr) is the same as myStr.doSomething()). How does that fit into your definition of OO?

I do agree with you on the general principle that std::string is a better option when using C++, but my reasoning is that it's safer than using raw C-strings.</description>
		<content:encoded><![CDATA[<p>That&#8217;s why this is labeled as a C Tip and not a C++ Tip <img src='http://gdmike.statbuff.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> I&#8217;ve been a C user for some years now, so I&#8217;m just used to C strings. I think your reasoning about using std::string, because it&#8217;s &#8220;OO&#8221;, is flawed. </p>
<p>The fact that std::string has an object oriented design does not by itself make it inherently better than C&#8217;s string API. In fact, there are different pitfalls that you don&#8217;t need to worry about with C strings (a side effect of the C++ language, not object orientation in general). The benefits come from the implementation details, not the fact that you can call methods on it with str.method syntax. </p>
<p>Second, there&#8217;s nothing that prevents you from using free functions in an OO design. Object orientation is not about classes - that&#8217;s just an implementation detail. Object orientation is about objects, and such a design can be implemented in C easily enough. Languages like C++ just give you the tools to make the implementation easier.</p>
<p>I suggest you take a look at the <a href="http://www.digitalmars.com/d/index.html" rel="nofollow" rel="nofollow">D programming language</a>. D&#8217;s strings are similar to those in C &#8212; arrays of characters manipulated with free functions. The biggest difference is that D strings don&#8217;t need to be null terminated, since arrays are actually structs under the hood that contain a data pointer and a length value. Another feature of D is that you can use the first argument to a function with . syntax (so that doSomething(myStr) is the same as myStr.doSomething()). How does that fit into your definition of OO?</p>
<p>I do agree with you on the general principle that std::string is a better option when using C++, but my reasoning is that it&#8217;s safer than using raw C-strings.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Programmer16</title>
		<link>http://gdmike.statbuff.com/2006/09/15/c-tip-safe-string-manipulation/#comment-833</link>
		<dc:creator>Programmer16</dc:creator>
		<pubDate>Sun, 17 Sep 2006 07:09:45 +0000</pubDate>
		<guid>http://gdmike.statbuff.com/2006/09/15/c-tip-safe-string-manipulation/#comment-833</guid>
		<description>I agree that char-pointer strings are not evil, but in my opinion there is no need to use them unless they're absolutely required. Part of the reason that I like C++ strings better than C-strings is that C++ strings are OO while C strings require functions for any of the nice features (appending and such.)

Anyway, I usually don't take anybody that says "X is evil" or "you shouldn't do X" seriously, since those terms are used by too many people who have no idea what they're talking about.</description>
		<content:encoded><![CDATA[<p>I agree that char-pointer strings are not evil, but in my opinion there is no need to use them unless they&#8217;re absolutely required. Part of the reason that I like C++ strings better than C-strings is that C++ strings are OO while C strings require functions for any of the nice features (appending and such.)</p>
<p>Anyway, I usually don&#8217;t take anybody that says &#8220;X is evil&#8221; or &#8220;you shouldn&#8217;t do X&#8221; seriously, since those terms are used by too many people who have no idea what they&#8217;re talking about.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
