tag:blogger.com,1999:blog-8730195.post8779541425159652628..comments2024-03-27T03:04:27.251-07:00Comments on Coding Power Unleashed: CodeRush, when code smells...Roland Beenhakkerhttp://www.blogger.com/profile/05387682563668003098noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-8730195.post-55413722827781278062009-04-11T07:19:00.000-07:002009-04-11T07:19:00.000-07:00Hi James,> Actually, > s = "Cow says &q...Hi James,<BR/><BR/>> Actually, <BR/>> s = "Cow says " + Cow.Make<BR/>> + "Several times";<BR/><BR/>This example shows another characteristic of string concatenation: display bugs can be harder to spot in the code and may instead be caught at runtime, sometimes by customers after you ship. <BR/><BR/>The potential display bug in the code above isn't so obvious when string concatenation is used.<BR/><BR/>Consider what happens when Cow.Make returns "Moo". The message displayed becomes: "Cow says MooSeveral times".<BR/><BR/>But take a look at how that display bug is so much easier to spot in the code when you use String.Format:<BR/><BR/>string s = String.Format("Cow says {0}Several times", Cow.Make);Unknownhttps://www.blogger.com/profile/15236727746670308092noreply@blogger.comtag:blogger.com,1999:blog-8730195.post-4329094344281860752009-04-10T17:30:00.000-07:002009-04-10T17:30:00.000-07:00Actually, s = "Cow says " + Cow.Make + "Several...Actually, <BR/> s = "Cow says " + Cow.Make + "Several times";<BR/><BR/>would be faster than using String.Format(). The compiler would automatically translate it to <BR/> String.ConCat("Cow says ", Cow.Make, "Several times")<BR/><BR/>The one string vs two is irrelevant, as those those constant strings are built at compile time.<BR/><BR/>The other reason preferring String.Format are still valid.James Curranhttps://www.blogger.com/profile/03689643776077649326noreply@blogger.comtag:blogger.com,1999:blog-8730195.post-15339507806134564672009-04-08T22:42:00.000-07:002009-04-08T22:42:00.000-07:00I just this was also available for Delphi. I reall...I just this was also available for Delphi. I really miss Code Rush for Delphi. Not that I have ever used it but after trying a demo version some time back in VS2005 I personally feel that this Add-in should also be made for Delphi. It will make life of developers easier.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8730195.post-19959508933312913772009-04-08T14:36:00.000-07:002009-04-08T14:36:00.000-07:00Now _that_ is an excellent reason. Thanks for poin...Now _that_ is an excellent reason. Thanks for pointing it out!gabr42https://www.blogger.com/profile/06903558857617342477noreply@blogger.comtag:blogger.com,1999:blog-8730195.post-90762703904813843002009-04-08T12:28:00.000-07:002009-04-08T12:28:00.000-07:00Strings passed to String.Format are also easier to...Strings passed to String.Format are also easier to translate/localize than concatenated strings. For example, the string expression "The cow says " + Cow.Make + "." might need to be reorganized grammatically when translating to another language (e.g., Cow.Make + " is spoken by the cow."). Grammatical changes like this (which are common when localizing your application for other cultures) cannot happen when string concatenation determines the order of the sentence parts (at least not without changing th *code*), however they are easy to do when the string to be translated includes all the grammatical parts of the phrase (e.g., "The cow says {0}."). One additional benefit: having the entire phrase in one string provides more context to the translator, so the translations tend to be of a higher quality.Unknownhttps://www.blogger.com/profile/15236727746670308092noreply@blogger.comtag:blogger.com,1999:blog-8730195.post-82645013523276132702009-04-08T08:18:00.000-07:002009-04-08T08:18:00.000-07:00That's something I would believe only if you p...That's something I would believe only if you profile & time both versions.gabr42https://www.blogger.com/profile/06903558857617342477noreply@blogger.comtag:blogger.com,1999:blog-8730195.post-7091138703903888412009-04-08T08:09:00.000-07:002009-04-08T08:09:00.000-07:00In a slightly larger example...s = "Cow says " + C...In a slightly larger example...<BR/><BR/>s = "Cow says " + Cow.Make + "Several times";<BR/><BR/>...is better phrased as...<BR/><BR/>S = String.Format("Cow says {0} Several times",Cow.Make);<BR/><BR/>..for performance reasons.<BR/><BR/>There are fewer strings in the 2nd version (2 vs 3). Therefore it's less memory intensive (especially in large loop)Roryhttps://www.blogger.com/profile/01170543848308287619noreply@blogger.comtag:blogger.com,1999:blog-8730195.post-67442807988880433192009-04-08T06:31:00.000-07:002009-04-08T06:31:00.000-07:00Well it is considered better from the readability ...Well it is considered better from the readability perpective. (iow maintainability)<BR/>It drills down to the coding standard you r using. But this was just a simple example, why would a Cow say anything at all? ;-)Rolandnoreply@blogger.comtag:blogger.com,1999:blog-8730195.post-68798703756012893212009-04-08T06:21:00.000-07:002009-04-08T06:21:00.000-07:00Nice feature but still - why should System.Format ...Nice feature but still - why should System.Format be better than string concatenation???gabr42https://www.blogger.com/profile/06903558857617342477noreply@blogger.com