<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5993074704535120230</id><updated>2012-01-19T11:08:37.309-08:00</updated><category term='C#'/><category term='dev'/><category term='BadCode'/><category term='lazy'/><category term='PetPeev'/><category term='jQuery'/><category term='arithmetic performance testing haskell python common lisp newlisp mono C#'/><category term='JavaScript'/><category term='python'/><category term='least effort'/><category term='unix operating system design'/><category term='MVC2'/><title type='text'>Random bits of foo</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>35</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-3632748921901115057</id><published>2012-01-19T11:08:00.000-08:00</published><updated>2012-01-19T11:08:37.327-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='unix operating system design'/><title type='text'>Failings of the Unix Commodity</title><content type='html'>&lt;div&gt;Imagine if you will a city with an array of transportation systems. &amp;nbsp;The most popular transportation system is a personal helicopter. &amp;nbsp;A home can have dozens of automated helicopters, each built to go fly to a single place and back. &amp;nbsp;Very little knowledge is needed to operate these helicopters and traveling with them is rather convenient: You don't have to wait for traffic lights or wind around with a road. &amp;nbsp;You just hop in, the helicopter takes the absolutely most direct route to your destination, and you hop out.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;People have grown quite accustomed to having large garages in this city where they keep little armadas of these specialized aircraft; one for going to the supermarket, one for going to the mall, one for going to work, one for going to school, one for going to night clubs, one to cruise around town, and so on. &amp;nbsp;Hop in, push the "Start" button and you're on your way!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In order to keep selling these helicopters to consumers, manufacturers have been adding luxurious features. &amp;nbsp;It began with cup holders and grew into hot tubs, projector screens, and all other sorts of amenities to make the flight more pleasant. &amp;nbsp;While these luxuries do add weight that slows the helicopters down, people don't really notice because of all the fun they're having.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Because these helicopters blindly take the most direct routes to their destinations, crashes are not unheard of. &amp;nbsp;Some manufacturers try to avoid crashes between two of their own helicopters but that doesn't really do much for the overall aviation safety.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Earlier-on in their history, these helicopters were infamous for their propensity to have mid-air collisions, landing mishaps, and the like. &amp;nbsp;In spite of all the damage this incoherent method of transportation has caused, you can't argue with the billions of dollars the flying hot tubs have raked in.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;While it is true that these helicopters can only travel to certain places, this is largely mitigated by the fact that people are willing to make many varieties of helicopters. &amp;nbsp;Most helicopter riders only really care to go to the most popular shopping centers and movie theaters anyway so they're quite content with the selection.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The other major mode of transportation is the local subway system. &amp;nbsp;This series of subterranean tracks is dark, damp and noisy. &amp;nbsp;It's inconvenient -- requiring you to know a schedule and how trains connect in order to really get anywhere. &amp;nbsp;It usually involves a lot of indirection as you connect to various stations and hop between different lines to get to your destination.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Those who prefer the subway system are proud of how low their expenses are and how few people actually get hurt by their transit system. &amp;nbsp;They have experts dedicated to maintaining and fine-tuning the whole transit system to make sure that every train arrives on time with as few surprises as possible.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Subway workers and users get along well. &amp;nbsp;They have a thriving subculture in their subway. &amp;nbsp;They all know each other and were always eager to exchange ideas about anything but especially about how they could make their subway better.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Many of the riders are also share-holders in the subway. &amp;nbsp;They take the money they save from having such an inexpensive transit system and invest it into expanding and refining it. &amp;nbsp;As a result, there is no part of the city that is more than a mile from the nearest subway station. &amp;nbsp;While walking to the subway station is a little bit of work, it is manageable and subway drivers tend to be fit and capable of the trek.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;With a subway pass (that costs less than a tenth of the insurance premiums that most pay for their helicopters) and a good understanding of the subway system, subway passengers can get anywhere they'd like to go. &amp;nbsp;They see parts of the city that may be beneath the notice of helicopter riders because nobody makes aircraft that fly there. &amp;nbsp;These subway riders are totally content to trade some convenience for this kind of freedom; there are no prescribed ways or places to travel. &amp;nbsp;There is only a system that helps you get anywhere.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Helicopter riders feel like fish out of water when they enter the subway. &amp;nbsp;They enter the train and start looking for the massaging recliner seats but they find only stiff benches. &amp;nbsp;They get confused by the unspoken need to pay attention and know whether or not a stop is at the destination. &amp;nbsp;They are absolutely horrified about the idea of having to walk anywhere -- thinking that when the vehicle stops, the journey should be totally over. &amp;nbsp;When buried in a tunnel, they feel incapable of knowing where they are or what direction they want to be going. &amp;nbsp;In fact, they feel annoyed that they have to even know anything about direction.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;When I was still in diapers, there were two kinds of computers around: The home desktop and the mainframe. &amp;nbsp;Home desktops were like a garage full of the Helicopters above: Emphasizing personal convenience and mass-marketability at the cost of stability and long-term maintainability. &amp;nbsp;Mainframes were like the Subway described above: &amp;nbsp;Sacrificing personal convenience and ease-of-use in exchange for having a robust, reliable, versatile system that can service the needs of many people at once.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I know I'm going to get crap if I don't mention Linux so...&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;As the years went by in this city, helicopter manufacturers got adventurous. &amp;nbsp;They tried to emulate admirable traits of the subway system; sometimes consciously, sometimes not. &amp;nbsp;They started making helicopters that could fly to multiple destinations. &amp;nbsp;They started making hybrid airplane-helicopter craft that could take you greater distances than just a helicopter could. &amp;nbsp;They introduced parachutes to keep helicopters from crashing into the ground in a massive conflagration of doom, and they started teaching riders to jump out of one helicopter and into another in a highly dangerous attempt at getting people places faster without having to buy more helicopters.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Meanwhile, others who admired the solid engineering of the subway system tried to emulate its strengths. &amp;nbsp;A group of volunteers paved an expansive road system on the ground that roughly resembled the subway tunnels beneath them. &amp;nbsp;Other volunteers built custom cars to drive on this road that had some of the conveniences you find in personal helicopters. &amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;These automobile drivers included crazy hippies that believed that asphalt was implicitly morally superior to flying as well as some entrepreneurs who hoped there would be a rising car market like there had been a helicopter market. &amp;nbsp;Some still just liked the penguin logo that was painted onto the cars.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;While driver neglect could cause crashes on these roads and they were still more common than in the subway, the consequences of these crashes weren't quite as catastrophic as the airborne equivalents and so it was generally believed to be better.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This is a story that many are familiar with. &amp;nbsp;But there's actually a lot more to it than that. &amp;nbsp;Years before the automobile was introduced, there emerged another subway imitation in town. &amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Some entrepreneurial souls looked at the great efficiency and usefulness of the subway and decided to try making rail travel a tradable commodity. &amp;nbsp;They prefabricated railways that could be flown in and dropped on top of a neighborhood for an instant railway transit system. &amp;nbsp;This process was naturally expensive so only the wealthiest districts could afford such a thing.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The enormous template of rail tried hard to look like the layout of the subway system. &amp;nbsp;But building such a system in such a different circumstance is hard. &amp;nbsp;When transporting this massive pretzel of track, it would often bend and warp under its own weight and had to be reshaped to fit the terrain. &amp;nbsp;After the track was finally set in place, it usually didn't resemble the subway it was intended to emulate.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Three major companies rose as providers of trolley networks. &amp;nbsp;Each had their own ideas as to what a track system should look like and how the trolley cars should behave. &amp;nbsp;Each track would be just similar enough that a passenger could make a few safe assumptions about the schedules and directions of certain lines. &amp;nbsp;And each would have its own "gotchas" that made expertise in one neighborhood's track not fully transferable to another.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The lack of standardization between all trolley systems made it incredibly difficult for some to navigate -- even those who had grown accustomed to the subway system were not quite at home on this surface railway. &amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Because the companies that made these tracks were more interested in manufacturing efficiency than in usage efficiency, trolleys were eventually written off as a cute anachronism rather than a real transit system. &amp;nbsp;The purported savings of using such a system simply weren't there. &amp;nbsp;What's more, because these trolleys purported themselves to be the same as the subway system, whatever bad reputation they'd accrued was shared with the subways.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Those who had sunk the great amounts of money into buying trolley systems were stuck with them and tried to make do with what they had but no new buyers were lining up.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Trolley companies eventually got to the point where they made all their money selling repair and maintenance services to people who'd previously purchased trolley systems from them.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Some tired to add propeller blades to their trolley cars; thinking this could attract some helicopter-style revenue. &amp;nbsp;Other companies tried making their cars bigger or faster to see if that would attract neighborhoods to their wares. &amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In spite of all their efforts, the trolley companies weren't getting the kind of money they wanted. &amp;nbsp;Their attempts at mutating with market demands only made whatever rail templates they did sell even less cohesive than before.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;One trolley manufacturer decided to shift efforts toward building accessories for helicopters. &amp;nbsp;Another transformed its trolleys into industrial freight trains. &amp;nbsp;The last fumbled around for a while until the penguin cars showed up. &amp;nbsp;They eagerly jumped on the bandwagon and have been trying to transform their own track into paved roads since. &amp;nbsp;As soon as they saw the cars weren't just a fad, they started pulling parts out of their disheveled trolley cars and plugging them into the automobiles, hoping more than anything that they could turn it into a solid business plan.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This last company still has lingering segments of track with disheveled cars sputtering about it. &amp;nbsp;This slow energy hog of a transit system is a glorious testament of the hubris of the trolley industry which presumed they could prefabricate the emergent brilliance of a peer-reviewed, actively used, actively maintained transit system.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Some took this lesson from the trolley industry as evidence that rail travel was all together flawed or that the mistakes of the trolley were the mistakes of the subway as well. &amp;nbsp;Some even believed that the pitfalls of the trolley model were a problem with all non-aeronautic travel --- making it easy to dismiss the cars and their pavement when those started cropping up.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Today, the trolley is one of the more clumsy, unreliable forms of transportation there is. &amp;nbsp;Even the messy helicopter industry has managed to fumble their way into some best practices that mitigate their system's shortcomings. &amp;nbsp;As helicopters grow to more closely resemble the subway system beneath them, they brag about how novel and illustrious their inventions are and they mock the rails that they see beneath them.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Their mockery is not entirely unfounded. &amp;nbsp;If your only exposure to computing systems were the home desktop and the commercial Unix system, it makes perfect sense why you would prefer your squadron of helicopters.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-3632748921901115057?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/3632748921901115057/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=3632748921901115057' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/3632748921901115057'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/3632748921901115057'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2012/01/failings-of-unix-commodity.html' title='Failings of the Unix Commodity'/><author><name>Ishpeck</name><uri>http://www.blogger.com/profile/06825418921052334722</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_wFJ-jTIuZtg/S0GF0bOAY7I/AAAAAAAAAAo/-UYbuaROSlY/S220/planetfire.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-5224818847329470346</id><published>2012-01-18T08:34:00.000-08:00</published><updated>2012-01-18T08:34:30.725-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JavaScript'/><category scheme='http://www.blogger.com/atom/ns#' term='lazy'/><category scheme='http://www.blogger.com/atom/ns#' term='jQuery'/><title type='text'>jQuery how I love you.</title><content type='html'>So I had a problem today where I needed to be able to tell if a JavaScript object was empty. &amp;nbsp;I spent 10 minuets &amp;nbsp;Googleing&amp;nbsp;for a consice soluction then I went to jQuery util page on a whim and the answer was there.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://api.jquery.com/jQuery.isEmptyObject/"&gt;http://api.jquery.com/jQuery.isEmptyObject/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;With just one call the library will tell me if it has data. &amp;nbsp;Thanks to the people that build such cool tools for me to use.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-5224818847329470346?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/5224818847329470346/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=5224818847329470346' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/5224818847329470346'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/5224818847329470346'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2012/01/jquery-how-i-love-you.html' title='jQuery how I love you.'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-1940463802926738940</id><published>2012-01-13T12:51:00.000-08:00</published><updated>2012-01-13T14:24:58.408-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='arithmetic performance testing haskell python common lisp newlisp mono C#'/><title type='text'>Benchmarking arithmetic</title><content type='html'>Got curious so I decided to see how quickly and accurately some arithmetic gets done in various environments.  Results below.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;[ishpeck@slcatedjamu ~]$ time dc -e "16384d^p"&lt;br /&gt;113837518811535904250072068341232590877598871955010488951192642300792\&lt;br /&gt;621302625312821980719831387362324936714246794526258573039676337010858\&lt;br /&gt;828763430793585922853616976807646165532533059489556150449708988141578\&lt;br /&gt;442943112023447213983043116092849446398990980402342632274314814328953\&lt;br /&gt;404819192156219054837263740293206244418473178404516135133213244063518\&lt;br /&gt;784562296023799090475839668510215390134010117698262576769574042814029\&lt;br /&gt;529033278052184274508131740701273566100706819850632337113494857562098\&lt;br /&gt;320151217292158833266370707127916108421901433177514694034750917722728&lt;br /&gt;... &lt;snip&gt;....&lt;br /&gt;218238270074739736264157780272832032578594361150434678340392480113080\&lt;br /&gt;089703735801591153586235927851796939292373259062814173277075113674401\&lt;br /&gt;829043044144045490928371875112748010711233174142910835089303346849145\&lt;br /&gt;895484745236306027347877637526426501080516036812222087305078640639225\&lt;br /&gt;541848209795509140539016236258676383295890570846220185368800472374864\&lt;br /&gt;023572119859359115185919085597104610288583655001397080304511835993974\&lt;br /&gt;191673243089264458895016889710034575213135566915400700972672256581021\&lt;br /&gt;999134594756634350940758242683390117111624193719460587302044176159214\&lt;br /&gt;609746781781933047509937334480699072619539011846151062186574802048674\&lt;br /&gt;92382202923258637344388123757033376532121188827136&lt;br /&gt;&lt;br /&gt;real    0m1.167s&lt;br /&gt;user    0m0.283s&lt;br /&gt;sys     0m0.003s&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;dc surprised me with its slowness until I realized it was throwing those backslashes in there.  That can eat up some time.  &lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;[ishpeck@slcatedjamu ~]$ time python -c "print 16384 ** 16384"&lt;br /&gt;1138375188115359042500720683412325908775988719550104889511926423007926213026253128219807198313873623249367142467945262585730396763370108588287634307935859228536169768076461655325330594895561504497089881415784429431120234472139830431160928494463989909804023426322743148143289534048191921562190548372637402932062444184731784045161351332132440635187845622960237990904758396685102153901340101176982625767695740428140295290332780521842745081317407012735661007068198506323371134948575620983201512172921588332663707071279161084219014331775146940347509177227281385333933210897869224188603686168680892745382927717262582865116798735382574696365796311299351046728260094290719606736072012259117111400667629363151930588541659099143747134721613089069740776235687657534765557725361993289329394049820885278902800491606809630123223601804037635379024208423418856532333180705506732367579643586252181430162147604245508970283612154605179099342622822975114534462339240221466716903857275803280366341678962977346051289393798425922859136969165217554566247811263669128403448140287396494805411846462566580026934215636853835525602451004242548897751439534340759663617153864418706583169642432738589331305934295186834298433853228606541975022545265261045793253180106547809428350799194427853647105017781506127477182293624210259930919849611849204841346064260162960557828534199134070897721151924&lt;br /&gt;... &lt;snip&gt;...&lt;br /&gt;703704366990068353216089737426366069381491347684599380093222610835917961800770781409200926729603012036399122612354223297965849193568220166221823827007473973626415778027283203257859436115043467834039248011308008970373580159115358623592785179693929237325906281417327707511367440182904304414404549092837187511274801071123317414291083508930334684914589548474523630602734787763752642650108051603681222208730507864063922554184820979550914053901623625867638329589057084622018536880047237486402357211985935911518591908559710461028858365500139708030451183599397419167324308926445889501688971003457521313556691540070097267225658102199913459475663435094075824268339011711162419371946058730204417615921460974678178193304750993733448069907261953901184615106218657480204867492382202923258637344388123757033376532121188827136&lt;br /&gt;&lt;br /&gt;real    0m0.789s&lt;br /&gt;user    0m0.203s&lt;br /&gt;sys     0m0.010s&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Intrepid old Python has some nice optimization to help eek out those fractions of a second.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;[ishpeck@slcatedjamu ~]$ time clisp -x "(expt 16384 16384)"&lt;br /&gt;  i i i i i i i       ooooo    o        ooooooo   ooooo   ooooo&lt;br /&gt;  I I I I I I I      8     8   8           8     8     o  8    8&lt;br /&gt;  I  \ `+' /  I      8         8           8     8        8    8&lt;br /&gt;   \  `-+-'  /       8         8           8      ooooo   8oooo&lt;br /&gt;    `-__|__-'        8         8           8           8  8&lt;br /&gt;        |            8     o   8           8     o     8  8&lt;br /&gt;  ------+------       ooooo    8oooooo  ooo8ooo   ooooo   8&lt;br /&gt;&lt;br /&gt;Welcome to GNU CLISP 2.49 (2010-07-07) &lt;http://clisp.cons.org/&gt;&lt;br /&gt;&lt;br /&gt;Copyright (c) Bruno Haible, Michael Stoll 1992, 1993&lt;br /&gt;Copyright (c) Bruno Haible, Marcus Daniels 1994-1997&lt;br /&gt;Copyright (c) Bruno Haible, Pierpaolo Bernardi, Sam Steingold 1998&lt;br /&gt;Copyright (c) Bruno Haible, Sam Steingold 1999-2000&lt;br /&gt;Copyright (c) Sam Steingold, Bruno Haible 2001-2010&lt;br /&gt;&lt;br /&gt;Type :h and hit Enter for context help.&lt;br /&gt;&lt;br /&gt;1138375188115359042500720683412325908775988719550104889511926423007926213026253128219807198313873623249367142467945262585730396763370108588287634307935859228536169768076461655325330594895561504497089881415784429431120234472139830431160928494463989909804023426322743148143289534048191921562190548372637402932062444184731784045161351332132440635187845622960237990904758396685102153901340101176982625767&lt;br /&gt;... &lt;snip&gt;...&lt;br /&gt;7414291083508930334684914589548474523630602734787763752642650108051603681222208730507864063922554184820979550914053901623625867638329589057084622018536880047237486402357211985935911518591908559710461028858365500139708030451183599397419167324308926445889501688971003457521313556691540070097267225658102199913459475663435094075824268339011711162419371946058730204417615921460974678178193304750993733448069907261953901184615106218657480204867492382202923258637344388123757033376532121188827136&lt;br /&gt;Bye.&lt;br /&gt;&lt;br /&gt;real    0m1.262s&lt;br /&gt;user    0m0.393s&lt;br /&gt;sys     0m0.007s&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;It surprised me how much slower Common was here.  Doesn't help that it clutters the display with all that junk, either.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;[ishpeck@slcatedjamu random_scripts]$ time csharp -e "Console.WriteLine(Math.Pow(16384, 16384));"&lt;br /&gt;Infinity&lt;br /&gt;&lt;br /&gt;real    0m0.282s&lt;br /&gt;user    0m0.257s&lt;br /&gt;sys     0m0.033s&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;I don't know what I did wrong here... I mean, besides trusting a statically typed language to know what to do with so huge a number.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;[ishpeck@slcatedjamu ~]$ time newlisp -e "(pow 16384 16384)"&lt;br /&gt;inf&lt;br /&gt;&lt;br /&gt;real    0m0.003s&lt;br /&gt;user    0m0.000s&lt;br /&gt;sys     0m0.000s&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;LAWL!  Infinity!&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;[ishpeck@slcatedjamu ~]$ time echo "16384 ^ 16384" | ghci&lt;br /&gt;GHCi, version 7.0.3: http://www.haskell.org/ghc/  :? for help&lt;br /&gt;Loading package ghc-prim ... linking ... done.&lt;br /&gt;Loading package integer-gmp ... linking ... done.&lt;br /&gt;Loading package base ... linking ... done.&lt;br /&gt;Loading package ffi-1.0 ... linking ... done.&lt;br /&gt;Prelude&gt; 11383751881153590425007206834123259087759887195501048895119264230079262130262531282198071983138736232493671424679452625857303967633701085882876343079358592285361697680764616553253305948955615044970898814157844294311202344721398304311609284944639899098040234263227431481432895340481919215621905483726374029320624441847317840451613513321324406351878456229602379909047583966851021539013401011769826257676957404281402952903327805218427450813174070127356610070681985063233711349485756209832015121729215883326637070712791610842190143317751469403475091772272813853339332108978692241886036861686808927453829277172625828651167987353825746963657963112993510467282600942907196067360720122591171114006676293631519305885416590991437471347216130890697407762356876575347655577253619932893293940498208852789028004916068096301232236018040376353790242084234188565323331807055067323675796435862521814301621476042455089702836121546051790993426228229751145344623392402214667169038572758032803663416789629773460512893937984259228591369691652175545662478112636691284034481402873964948054118464625665800269342156368538355256024510042425488977514395343407596636171538644187065831696424327385893313059342951868342984338532286065419750225452652610457932531801065478094283507991944278536471050177815&lt;br /&gt;...&lt;snip&gt;...&lt;br /&gt;1800770781409200926729603012036399122612354223297965849193568220166221823827007473973626415778027283203257859436115043467834039248011308008970373580159115358623592785179693929237325906281417327707511367440182904304414404549092837187511274801071123317414291083508930334684914589548474523630602734787763752642650108051603681222208730507864063922554184820979550914053901623625867638329589057084622018536880047237486402357211985935911518591908559710461028858365500139708030451183599397419167324308926445889501688971003457521313556691540070097267225658102199913459475663435094075824268339011711162419371946058730204417615921460974678178193304750993733448069907261953901184615106218657480204867492382202923258637344388123757033376532121188827136&lt;br /&gt;Prelude&gt; Leaving GHCi.&lt;br /&gt;&lt;br /&gt;real    0m1.060s&lt;br /&gt;user    0m0.250s&lt;br /&gt;sys     0m0.173s&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;And for more LOL's!&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;[ishpeck@slcatedjamu ~]$ time lynx -dump http://www.wolframalpha.com/input/?i=16384%5E16384&lt;br /&gt;   #[1]Wolfram|Alpha&lt;br /&gt;&lt;br /&gt;     * [2]Home&lt;br /&gt;     * [3]Examples&lt;br /&gt;     * [4]Products&lt;br /&gt;     * [5]Blog&lt;br /&gt;     * [6]About&lt;br /&gt;&lt;br /&gt;     *&lt;br /&gt;          + [7]Wolfram Research&lt;br /&gt;          +&lt;br /&gt;          + [8]Wolfram Mathematica&lt;br /&gt;          + [9]Wolfram Demonstrations&lt;br /&gt;          + [10]Wolfram MathWorld&lt;br /&gt;          + [11]Wolfram Science&lt;br /&gt;          + [12]WolframTones&lt;br /&gt;          +&lt;br /&gt;          + [13]More &lt;br /&gt;&lt;br /&gt;   Experimental Feature&lt;br /&gt;&lt;br /&gt;   You have the Wolfram CDF Player installed and can now enable&lt;br /&gt;   Wolfram|Alpha Interactive to:&lt;br /&gt;     * Interact with your results using sliders and controls&lt;br /&gt;     * Rotate and zoom 3D graphics and visualizations&lt;br /&gt;     * Manipulate results directly in your browser&lt;br /&gt;&lt;br /&gt;   [14]Learn more  [15]Remind me later&lt;br /&gt;&lt;br /&gt;Experimental Feature&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   Thanks for helping us test Wolfram|Alpha with CDF!&lt;br /&gt;   Try these interactive examples:&lt;br /&gt;     * Interactively manipulate parameters&lt;br /&gt;       ____________________ Submit&lt;br /&gt;     * Rotate 3D graphics&lt;br /&gt;       ____________________ Submit&lt;br /&gt;     * Read plot values&lt;br /&gt;       ____________________ Submit&lt;br /&gt;     * Animate dynamic processes&lt;br /&gt;       ____________________ Submit&lt;br /&gt;     * Instantly build interactive interfaces&lt;br /&gt;       ____________________ Submit&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Experimental Feature&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   Thanks for helping us test Wolfram|Alpha with CDF!&lt;br /&gt;   Please tell us what you think:[16]Take a survey &lt;br /&gt;&lt;br /&gt;Experimental Feature&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    [17]Learn more [18]Take a survey &lt;br /&gt;&lt;br /&gt;   [19]Wolfram|Alpha Computational Knowledge EngineEnter what you want to&lt;br /&gt;   calculate or know about:&lt;br /&gt;&lt;br /&gt;   ____________________&lt;br /&gt;&lt;br /&gt;   Submit&lt;br /&gt;&lt;br /&gt;   [20]Examples[21]Random&lt;br /&gt;&lt;br /&gt;   To see full output on this page you need to enable JavaScript in your&lt;br /&gt;   browser. [22]More info &lt;br /&gt;   Computing&lt;br /&gt;   Computing...&lt;br /&gt;     __________________________________________________________________&lt;br /&gt;&lt;br /&gt;Input:&lt;br /&gt;&lt;br /&gt;   16384^16384&lt;br /&gt;   [23]Save as image [24]Copyable plaintext [25]Mathematica form &lt;br /&gt;     __________________________________________________________________&lt;br /&gt;     __________________________________________________________________&lt;br /&gt;&lt;br /&gt;Decimal approximation:&lt;br /&gt;&lt;br /&gt;     * [26]More digits&lt;br /&gt;&lt;br /&gt;   [27]1.13837518811535904250072068341232590877598871955010...  10^69049&lt;br /&gt;     __________________________________________________________________&lt;br /&gt;     __________________________________________________________________&lt;br /&gt;&lt;br /&gt;Power of 10 representation:&lt;br /&gt;&lt;br /&gt;   10^(10^4.839157747319649)&lt;br /&gt;     __________________________________________________________________&lt;br /&gt;     __________________________________________________________________&lt;br /&gt;&lt;br /&gt;Number length:&lt;br /&gt;&lt;br /&gt;   69050 decimal digits&lt;br /&gt;     __________________________________________________________________&lt;br /&gt;     __________________________________________________________________&lt;br /&gt;&lt;br /&gt;Last few digits:&lt;br /&gt;&lt;br /&gt;   ...1188827136&lt;br /&gt;     __________________________________________________________________&lt;br /&gt;&lt;br /&gt;   [28]Computed by Wolfram MathematicaDownload as: PDFLive Mathematica&lt;br /&gt;&lt;br /&gt;... &lt;snipped out the ocean of "reference" links&gt;...&lt;br /&gt;&lt;br /&gt;real    0m1.025s&lt;br /&gt;user    0m0.017s&lt;br /&gt;sys     0m0.010s&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Of course, this is all very far from scientific but it was amusing to try.  I've noticed that clisp tends to out-perform Python on smaller numbers (I assume because Python's cache is helpind it out when there's a lot of repitition).  Nobody who actually _tried_ to compute the desired value botched anything up (the way Python is wont to in some arithmetic situations).&lt;br /&gt;&lt;br /&gt;I know Haskell tended to be much faster if you subtracted start-up time (which this test does not).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-1940463802926738940?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/1940463802926738940/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=1940463802926738940' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/1940463802926738940'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/1940463802926738940'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2012/01/benchmarking-arithmetic.html' title='Benchmarking arithmetic'/><author><name>Ishpeck</name><uri>http://www.blogger.com/profile/06825418921052334722</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_wFJ-jTIuZtg/S0GF0bOAY7I/AAAAAAAAAAo/-UYbuaROSlY/S220/planetfire.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-9200461519347376048</id><published>2011-12-07T13:19:00.001-08:00</published><updated>2011-12-07T13:21:16.958-08:00</updated><title type='text'>Wrote my first jquery plugin it strips out html for an input field</title><content type='html'>&lt;pre style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #222222; font-size: 12px; line-height: 20px; margin-bottom: 15px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; vertical-align: baseline;"&gt;&lt;pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 15px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;I needed a way to remove up html from my input from the users.  This is my first attempt at it.&lt;/pre&gt;&lt;pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 15px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;(&lt;span style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;function&lt;/span&gt;&amp;nbsp;($)&amp;nbsp;{&lt;br /&gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$.fn.safeVal&amp;nbsp;=&amp;nbsp;&lt;span style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;function&lt;/span&gt;&amp;nbsp;()&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;var&lt;/span&gt;&amp;nbsp;value&amp;nbsp;=&amp;nbsp;$(&lt;span style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;this&lt;/span&gt;).val();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;var&lt;/span&gt;&amp;nbsp;ret&amp;nbsp;=&amp;nbsp;$(&lt;span style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;'&amp;lt;div&amp;gt;'&lt;/span&gt;).html(value).text();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;return&lt;/span&gt;&amp;nbsp;ret;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;};&lt;br /&gt;})(jQuery);&lt;/pre&gt;&lt;div&gt;&lt;/div&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-9200461519347376048?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/9200461519347376048/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=9200461519347376048' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/9200461519347376048'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/9200461519347376048'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2011/12/wrote-my-first-jquery-plugin-it-strips.html' title='Wrote my first jquery plugin it strips out html for an input field'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-7894164703205609713</id><published>2011-08-04T13:34:00.000-07:00</published><updated>2011-08-04T13:34:56.782-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='dev'/><category scheme='http://www.blogger.com/atom/ns#' term='lazy'/><category scheme='http://www.blogger.com/atom/ns#' term='PetPeev'/><title type='text'>My Rules for Development</title><content type='html'>&lt;ol&gt;&lt;li&gt;If you think you need a region you really need a new class.&lt;/li&gt;&lt;li&gt;If you are using a for loop in c# there is something wrong with your code.&lt;/li&gt;&lt;li&gt;If you are using a foreach fix you code so you don't need it.&lt;/li&gt;&lt;li&gt;If you think you want to use exceptions to control flow stop now and go to your room and think about what damage you may do.&lt;/li&gt;&lt;li&gt;If you don't write a unit test it's not done.&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-7894164703205609713?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/7894164703205609713/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=7894164703205609713' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/7894164703205609713'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/7894164703205609713'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2011/08/my-rules-for-development.html' title='My Rules for Development'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-4263859934704997406</id><published>2011-05-18T13:27:00.000-07:00</published><updated>2011-05-18T13:27:02.323-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='lazy'/><category scheme='http://www.blogger.com/atom/ns#' term='least effort'/><category scheme='http://www.blogger.com/atom/ns#' term='PetPeev'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Some Fun With Linq.</title><content type='html'>A friend of mine was asking me how I search through&amp;nbsp;dictionary&amp;nbsp;that contain lists of objects with Linq. After I chatted with him for a bit. I realized I don't do that. &amp;nbsp;I have one huge list that I parse out with linq. &amp;nbsp;It makes my life easier. &amp;nbsp;Here is a code example of what I would use.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: white; color: black; font-family: Consolas; font-size: 13;"&gt;&lt;span style="color: blue;"&gt;        public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;class&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;section&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;string&lt;/span&gt;&amp;nbsp;Group&amp;nbsp;{&amp;nbsp;&lt;span style="color: blue;"&gt;get&lt;/span&gt;;&amp;nbsp;&lt;span style="color: blue;"&gt;set&lt;/span&gt;;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;string&lt;/span&gt;&amp;nbsp;Order&amp;nbsp;{&amp;nbsp;&lt;span style="color: blue;"&gt;get&lt;/span&gt;;&amp;nbsp;&lt;span style="color: blue;"&gt;set&lt;/span&gt;;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;string&lt;/span&gt;&amp;nbsp;Section&amp;nbsp;{&amp;nbsp;&lt;span style="color: blue;"&gt;get&lt;/span&gt;;&amp;nbsp;&lt;span style="color: blue;"&gt;set&lt;/span&gt;;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;string&lt;/span&gt;&amp;nbsp;Title&amp;nbsp;{&amp;nbsp;&lt;span style="color: blue;"&gt;get&lt;/span&gt;;&amp;nbsp;&lt;span style="color: blue;"&gt;set&lt;/span&gt;;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;static&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;void&lt;/span&gt;&amp;nbsp;Main(&lt;span style="color: blue;"&gt;string&lt;/span&gt;[]&amp;nbsp;args)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;var&lt;/span&gt;&amp;nbsp;sec&amp;nbsp;=&amp;nbsp;&lt;span style="color: blue;"&gt;new&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;section&lt;/span&gt;&amp;gt;();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sec.Add(&lt;span style="color: blue;"&gt;new&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;section&lt;/span&gt;&amp;nbsp;{&amp;nbsp;Group&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"1"&lt;/span&gt;,&amp;nbsp;Order&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"1"&lt;/span&gt;,&amp;nbsp;Section&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"1.1"&lt;/span&gt;,&amp;nbsp;Title&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"one&amp;nbsp;one"&lt;/span&gt;&amp;nbsp;});&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sec.Add(&lt;span style="color: blue;"&gt;new&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;section&lt;/span&gt;&amp;nbsp;{&amp;nbsp;Group&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"1"&lt;/span&gt;,&amp;nbsp;Order&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"3"&lt;/span&gt;,&amp;nbsp;Section&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"1.3"&lt;/span&gt;,&amp;nbsp;Title&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"one&amp;nbsp;three"&lt;/span&gt;&amp;nbsp;});&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sec.Add(&lt;span style="color: blue;"&gt;new&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;section&lt;/span&gt;&amp;nbsp;{&amp;nbsp;Group&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"1"&lt;/span&gt;,&amp;nbsp;Order&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"2"&lt;/span&gt;,&amp;nbsp;Section&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"1.2"&lt;/span&gt;,&amp;nbsp;Title&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"one&amp;nbsp;two"&lt;/span&gt;&amp;nbsp;});&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sec.Add(&lt;span style="color: blue;"&gt;new&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;section&lt;/span&gt;&amp;nbsp;{&amp;nbsp;Group&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"2"&lt;/span&gt;,&amp;nbsp;Order&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"1"&lt;/span&gt;,&amp;nbsp;Section&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"2.1"&lt;/span&gt;,&amp;nbsp;Title&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"two&amp;nbsp;one"&lt;/span&gt;&amp;nbsp;});&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sec.Add(&lt;span style="color: blue;"&gt;new&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;section&lt;/span&gt;&amp;nbsp;{&amp;nbsp;Group&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"2"&lt;/span&gt;,&amp;nbsp;Order&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"2"&lt;/span&gt;,&amp;nbsp;Section&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"2.2"&lt;/span&gt;,&amp;nbsp;Title&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"two&amp;nbsp;two"&lt;/span&gt;&amp;nbsp;});&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sec.Add(&lt;span style="color: blue;"&gt;new&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;section&lt;/span&gt;&amp;nbsp;{&amp;nbsp;Group&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"3"&lt;/span&gt;,&amp;nbsp;Order&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"1"&lt;/span&gt;,&amp;nbsp;Section&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"3.1"&lt;/span&gt;,&amp;nbsp;Title&amp;nbsp;=&amp;nbsp;&lt;span style="color: #a31515;"&gt;"three&amp;nbsp;one"&lt;/span&gt;&amp;nbsp;});&lt;br /&gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: green;"&gt;//creates&amp;nbsp;a&amp;nbsp;diction&amp;nbsp;with&amp;nbsp;all&amp;nbsp;the&amp;nbsp;sections&amp;nbsp;in&amp;nbsp;order&amp;nbsp;grouped&amp;nbsp;by&amp;nbsp;group.&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;var&lt;/span&gt;&amp;nbsp;jmp&amp;nbsp;=&amp;nbsp;sec.OrderBy(j&amp;nbsp;=&amp;gt;&amp;nbsp;j.Order).GroupBy(c&amp;nbsp;=&amp;gt;&amp;nbsp;c.Group).ToDictionary(c&amp;nbsp;=&amp;gt;&amp;nbsp;c.Key,&amp;nbsp;d&amp;nbsp;=&amp;gt;&amp;nbsp;d.ToList());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: green;"&gt;//gets&amp;nbsp;one&amp;nbsp;section&amp;nbsp;form&amp;nbsp;a&amp;nbsp;section&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;var&lt;/span&gt;&amp;nbsp;wantedSection&amp;nbsp;=&amp;nbsp;sec.FirstOrDefault(c&amp;nbsp;=&amp;gt;&amp;nbsp;c.Section&amp;nbsp;==&amp;nbsp;&lt;span style="color: #a31515;"&gt;"2.2"&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&lt;span style="color: green;"&gt;//return&amp;nbsp;null&amp;nbsp;if&amp;nbsp;no&amp;nbsp;iteem&amp;nbsp;found&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: green;"&gt;//gets&amp;nbsp;one&amp;nbsp;section&amp;nbsp;in&amp;nbsp;the&amp;nbsp;order&amp;nbsp;you&amp;nbsp;set&amp;nbsp;in&amp;nbsp;order&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;var&lt;/span&gt;&amp;nbsp;sectionOne&amp;nbsp;=&amp;nbsp;sec.Where(c&amp;nbsp;=&amp;gt;&amp;nbsp;c.Group&amp;nbsp;==&amp;nbsp;&lt;span style="color: #a31515;"&gt;"1"&lt;/span&gt;).OrderBy(c&amp;nbsp;=&amp;gt;&amp;nbsp;c.Order).ToList();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-4263859934704997406?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/4263859934704997406/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=4263859934704997406' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/4263859934704997406'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/4263859934704997406'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2011/05/some-fun-with-linq.html' title='Some Fun With Linq.'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-3680562893235538490</id><published>2011-05-04T14:39:00.000-07:00</published><updated>2011-05-04T14:39:33.163-07:00</updated><title type='text'>I found this to be a very interesting watch</title><content type='html'>How much of the world is filtered out for you.&amp;nbsp;&lt;a href="http://www.ted.com/talks/eli_pariser_beware_online_filter_bubbles.html"&gt;http://www.ted.com/talks/eli_pariser_beware_online_filter_bubbles.html&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-3680562893235538490?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/3680562893235538490/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=3680562893235538490' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/3680562893235538490'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/3680562893235538490'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2011/05/i-found-this-to-be-very-interesting.html' title='I found this to be a very interesting watch'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-863132311190021354</id><published>2011-04-22T13:28:00.000-07:00</published><updated>2011-04-22T13:47:39.311-07:00</updated><title type='text'>Test Code that Doesn't</title><content type='html'>Consider the following code taken from an automated testing suite:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;   def group(self, group, options="", authUser=None, cmdOptions=""):&lt;br /&gt;       if options != "":&lt;br /&gt;           options = "-" + options&lt;br /&gt;          &lt;br /&gt;       output, rCode = self._run(cmdOptions, "list {} group {}".format(options, group), authUser, returnOutput=True)&lt;br /&gt;       if rCode != 0 and output != None:&lt;br /&gt;           lines = output.splitlines()&lt;br /&gt;           if len(lines) &amp;gt; 1:&lt;br /&gt;               for line in lines:&lt;br /&gt;                   if line.find("[debug]") == -1:&lt;br /&gt;                       group =  self._parseGroup(line)&lt;br /&gt;           else:&lt;br /&gt;               group = self._parseGroup(output)&lt;br /&gt;             &lt;br /&gt;       return group, rCode &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;What's especially interesting about this piece of code is that if the program being called succeeds and returns multiple lines, only the very last one is considered the actual output.  If the program being called by _run fails, the return value is the text of what you asked for!&lt;br /&gt;&lt;br /&gt;Though this is part of an automated testing suite, no real checks take place.  The only thing it bothers to do is ignore debugging output.  But that's handy!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-863132311190021354?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/863132311190021354/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=863132311190021354' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/863132311190021354'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/863132311190021354'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2011/04/test-code-that-doesnt.html' title='Test Code that Doesn&apos;t'/><author><name>Ishpeck</name><uri>http://www.blogger.com/profile/06825418921052334722</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_wFJ-jTIuZtg/S0GF0bOAY7I/AAAAAAAAAAo/-UYbuaROSlY/S220/planetfire.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-4730578471862979726</id><published>2011-03-25T10:16:00.000-07:00</published><updated>2011-03-25T10:16:48.866-07:00</updated><title type='text'>Chat between frinds</title><content type='html'>It's often the case where I learn more about programming from a conversation over google talk then I do form reading a book. &amp;nbsp;This is a copy of one such conversation between two of my friends. &amp;nbsp;I thought the content was good enough to actually post for others to read.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;Feels nice to perfect a 468-line data model using LINQ extremely liberally&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;how does LINQ relate to a data model?&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;Probably the wrong word&lt;br /&gt;&lt;br /&gt;There are a number of properties of my data model that I'm exposing that are little but fundamental interpretations of the data&lt;br /&gt;&lt;br /&gt;That's where the LINQ resides&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;data operations then&lt;br /&gt;technically speaking your data model should be POCO's&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;What's that?&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;Plain Old CLR Objects&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;Why?&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;ask yourself this question, what is a Data Model, simple answer, a unified representation of the data in a system&lt;br /&gt;not a unified representatino of the logic in the system&lt;br /&gt;by using POCO's you make your system firstly portable and simply definable&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;Well&lt;br /&gt;I'm defining a system in which the rules can be changed dynamically by simply modifying some .csv or .xml files&lt;br /&gt;For example, there is a number that defines how many slots you can put in your ship before the size in increased a level.&lt;br /&gt;This size number is fundamental to the data itself, but emerges based on the rules&lt;br /&gt;So, although it includes logic, I've included it in my data model&lt;br /&gt;Defense and Speed are based on size and, again, fundamental&lt;br /&gt;They also emerge from some logic&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;This is where i tell you, your system will never scale    you've just written a very small idea&lt;br /&gt;so if for example you want to do server side scaling of your game&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;Are you suggesting I should separate them into two different layers?&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;it won't happen and would be a nightmare&lt;br /&gt;lol i'm suggesting you learn about software architecture&lt;br /&gt;you can program, but the where and why needs to be taught&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;I try -_-&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;lol you suceed&lt;br /&gt;dude&lt;br /&gt;this is something i learned only 18 months ago at best&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;So would the problem be that so much computation is done server-side?&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;the problem is, if you try to do server side calculations you can simply push data easily in a POCO from client to server&lt;br /&gt;your having to push the entire logic base with it and deploy the same logic on client and server&lt;br /&gt;OR&lt;br /&gt;do stateful server side objects which don't scale either&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;Well&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;meaning when you create an instance of an object it stays alive on the server, rather that data moving through a system&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;This particular data and rule set would be computed and immutable when the actual "game" part begins, I'll tell you that&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;having dicipline does NOT make up for architectural mistakes&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;hah&lt;br /&gt;Fair enough&lt;br /&gt;I'ma quote that, actually.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;See your trying to apply a simple OOD which in truth is fundamentally flawed&lt;br /&gt;by that, when you create an Object Oriented System, to be properly constructed it must implement this http://en.wikipedia.org/wiki/Solid_(object-oriented_design)&lt;br /&gt;Its the only way of making an OO system scale and be properly designed&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;I never did understand where the line is drawn with SRP&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;more is better&lt;br /&gt;meaning, if you have to break up logic into multiple logic blocks because it violates the single responsibility, then do so&lt;br /&gt;so take this for example&lt;br /&gt;you have a Repository object that handles CRUD (create, retrieve, update, delete) operations&lt;br /&gt;now a repository pattern does not a happy llama make but its an easy way to explain this&lt;br /&gt;Technically speaking the object can follow SRP if it does CRUD operations&lt;br /&gt;but that can lead to a ton of operations right?&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;yeah&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;insert, update, delete, and data queries&lt;br /&gt;so one could say that doing insert, update, delete, and select by id is one responsibility because its doing autonomous operations on an entity in the model&lt;br /&gt;and any queries should be seperated out to a secondary or multiple objects in order to satisfy SRP&lt;br /&gt;both are valid interpretations&lt;br /&gt;however breaking it down further gives greater scope to the SRP making it more real&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;hrm&lt;br /&gt;But certainly wouldn't create one object to generate the Defense, another to generate Speed&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;why not&lt;br /&gt;they're components aren't they?&lt;br /&gt;or is it making too many objects?&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;public int Speed&lt;br /&gt;        {&lt;br /&gt;            get&lt;br /&gt;            {&lt;br /&gt;                return (int)Math.Ceiling(this.AllSlots&lt;br /&gt;                    .Where(i =&amp;gt; i.SlotType == SlotType.Engine&lt;br /&gt;                        || i.SlotType == SlotType.Universal)&lt;br /&gt;                    .Where(i =&amp;gt; i.SlottedSystem != null)&lt;br /&gt;                    .Where(i =&amp;gt; i.SlottedSystem is IShipEngine)&lt;br /&gt;                    .Sum(i =&amp;gt; (i.SlottedSystem as IShipEngine).Thrust)&lt;br /&gt;                    / (float)this.Size);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;/pre&gt;That's it&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;ok, thats a horrible bastardization of a data layer&lt;br /&gt;you did that in a getter? o.O&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;Hahahaha&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;dude, ICalculateSpeed ftw&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;Are you serious?&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;as a heart attack&lt;br /&gt;you CAN use a factory to keep a singleton of it&lt;br /&gt;but thats logic hiding in the data layer&lt;br /&gt;its a calculation leading from one entity to a speed value&lt;br /&gt;You do want to learn proper OO systems no?&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;Why would I use a singleton instead of a static method?&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;Its a piece of logic, which is encapsulated into an object&lt;br /&gt;therfore keeping w/ the DIP principle you have an interface to define the operation, and an object instance to operate it&lt;br /&gt;keeping a singleton just manages memory overhead&lt;br /&gt;but you can manage that w/ the Factory&lt;br /&gt;which yields flexibility&lt;br /&gt;rather than a run of the mill rigidity that using a Utility class w/ a static method gives you&lt;br /&gt;make sense?&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;Yeah&lt;br /&gt;Damn good song btw http://listen.grooveshark.com/s/The+Truth+Of+A+Liar/2gag9R?src=5&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;i'll have to check it out on pandora&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;I can definitely see where the flexibility comes in&lt;br /&gt;It builds more of an internal protocol-based system instead know-it-all master objects&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;see: God Object&lt;br /&gt;suprisingly, it builds a stronger system with fantastic segregation&lt;br /&gt;you can tune and tweak various parts of the system&lt;br /&gt;AND&lt;br /&gt;its bloody easy to unit test&lt;br /&gt;you can create various proxy objects to plug into the system that mock actual logic, so your system can be 100% testable&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;And now&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;especially testing negatively&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;I have struggle with the decision of getting this thing done or plow through it so I can use it&lt;br /&gt;It's a tool I wanted to use two weeks ago&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;Star Thugs?&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;yeah&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;hahaha&lt;br /&gt;rebuild it yo&lt;br /&gt;use it as a teaching moment for yourself&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;Well here's the good news&lt;br /&gt;I'm still using MVVM, even though my models are a bit massive&lt;br /&gt;So I can finish it off and refactor the models without remaining committed to my shit&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;sweet&lt;br /&gt;well i got NUnit to start running my F# unit tests&lt;br /&gt;namespace Llama.Test&lt;br /&gt;open NUnit.Framework&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;[&amp;lt;TestFixture&amp;gt;]&lt;br /&gt;type EndpointRegistryTests() =&lt;br /&gt;    [&amp;lt;Test&amp;gt;]&lt;br /&gt;    member x.add_value_to_registry() : unit =&lt;br /&gt;        printfn "hello testing world 2"&lt;br /&gt;        Assert.AreEqual(5, 5)&lt;br /&gt;&lt;/pre&gt;not bad for unit tests&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;Hahahaha&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;now i actually gotta fill in logic&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;Just testing the JIT&lt;br /&gt;Iz coo&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;next is start testing components in my node server&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;How portable is the ViewModel architecture to ASP MVC?&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;depends on what you do&lt;br /&gt;if its my framework Kronos&lt;br /&gt;extremely&lt;br /&gt;we actually had this type of layer for how data moves through layers&lt;br /&gt;&lt;br /&gt;ViewModel -&amp;gt; Domain&lt;br /&gt;View -&amp;gt; Controller -&amp;gt; Provider -&amp;gt; (Service : Optional) -&amp;gt; NHibernate&lt;br /&gt;the domain object would live till the controller&lt;br /&gt;then we'd do a transform using AutoMapper to a ViewModel to be used in the View&lt;br /&gt;we use this for a very damn good reason, Domain objects are actually dynamically generated inherited objects that do lazy loading etc that are attached to a Session&lt;br /&gt;So if we access a collection on an object in a view, we're literally running a db query in the view layer&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;lololol&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;So thats why we use ViewModels&lt;br /&gt;So you know, Crystal thought my description of your getter as being a grose bastardization was rude&lt;br /&gt;She says i should be nicer&lt;br /&gt;&amp;gt;,&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;Hahahaha&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;Granted, i won't be, because we devs are the way we are&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;'course&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;but its the thought that really counts&lt;br /&gt;i told her it def wasn't the worst thing i've ever said&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Sqrl says:&lt;/span&gt;&lt;br /&gt;Gawd, what do you do when ignorant people call cute flash animations "programming"?&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;Llama says:&lt;/span&gt;&lt;br /&gt;cuz they think it is&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-4730578471862979726?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/4730578471862979726/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=4730578471862979726' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/4730578471862979726'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/4730578471862979726'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2011/03/chat-between-frinds.html' title='Chat between frinds'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-7070654436699001063</id><published>2011-03-02T07:37:00.000-08:00</published><updated>2011-03-02T07:37:17.677-08:00</updated><title type='text'>The way of Testivus</title><content type='html'>A friend of mine linked me to&amp;nbsp;&lt;a href="http://www.agitar.com/downloads/TheWayOfTestivus.pdf"&gt;TheWayOfTestivus.pdf&lt;/a&gt;&amp;nbsp;the other day. &amp;nbsp;It is a funny read that talks about unit testing and has a very pragmatic view on it. &amp;nbsp;Read it enjoy it and apply it. I think you will find that it improves your development process if you do.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-7070654436699001063?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/7070654436699001063/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=7070654436699001063' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/7070654436699001063'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/7070654436699001063'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2011/03/way-of-testivus.html' title='The way of Testivus'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-4968491991488757770</id><published>2011-03-01T08:04:00.000-08:00</published><updated>2011-03-01T08:04:23.057-08:00</updated><title type='text'>CodeProject has some gems in it.</title><content type='html'>I friend linked me to &lt;a href="http://www.codeproject.com/KB/cs/maybemonads.aspx"&gt;this &lt;/a&gt;the other day and it changed how I program. &amp;nbsp;It's not very often that one article changes the way I handle coding but this allowed me to clean up a lot of code. &amp;nbsp;From the work in the article I have added one more function as well.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: consolas;"&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;static&lt;/span&gt;&amp;nbsp;TResult&amp;nbsp;Let&lt;tinput,&amp;nbsp;tresult&gt;(&lt;span style="color: blue;"&gt;this&lt;/span&gt;&amp;nbsp;TInput&amp;nbsp;o,&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Func&lt;/span&gt;&lt;tinput,&amp;nbsp;tresult&gt;&amp;nbsp;evaluator,&amp;nbsp;TResult&amp;nbsp;failValue)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;where&lt;/span&gt;&amp;nbsp;TResult&amp;nbsp;:&amp;nbsp;&lt;span style="color: blue;"&gt;class&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;where&lt;/span&gt;&amp;nbsp;TInput&amp;nbsp;:&amp;nbsp;&lt;span style="color: blue;"&gt;class&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;if&lt;/span&gt;&amp;nbsp;(o&amp;nbsp;==&amp;nbsp;&lt;span style="color: blue;"&gt;null&lt;/span&gt;)&amp;nbsp;&lt;span style="color: blue;"&gt;return&lt;/span&gt;&amp;nbsp;failValue;&lt;br /&gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;return&lt;/span&gt;&amp;nbsp;evaluator(o);&lt;br /&gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/tinput,&amp;nbsp;tresult&gt;&lt;/tinput,&amp;nbsp;tresult&gt;&lt;/pre&gt;&lt;pre style="font-family: consolas;"&gt;&lt;/pre&gt;&lt;pre style="font-family: consolas;"&gt;This one allows for the calling of functions that return a value.&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-4968491991488757770?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/4968491991488757770/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=4968491991488757770' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/4968491991488757770'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/4968491991488757770'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2011/03/codeproject-has-some-gems-in-it.html' title='CodeProject has some gems in it.'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-5673327889129932552</id><published>2011-02-16T13:59:00.000-08:00</published><updated>2011-02-16T13:59:09.710-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PetPeev'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='BadCode'/><title type='text'>Date Time you are doing it wrong again.</title><content type='html'>The other day I reading&amp;nbsp;&lt;a href="http://www.skorks.com/2011/02/the-greatest-developer-fallacy-or-the-wisest-words-youll-ever-hear/"&gt;the greatest developer fallacy or the wisest words you'll ever hear&lt;/a&gt;&amp;nbsp;and then today I found some code that I think&amp;nbsp;illustrated&amp;nbsp;his point that learning it when you need it isn't always the way to go. This code looks very much that way. &amp;nbsp;Although I think a quick Google search would have found better code then this even if you didn't know what words to look for.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: consolas;"&gt;System.Text.&lt;span style="color: #2b91af;"&gt;StringBuilder&lt;/span&gt;&amp;nbsp;mxIsDt&amp;nbsp;=&amp;nbsp;&lt;span style="color: blue;"&gt;new&lt;/span&gt;&amp;nbsp;System.Text.&lt;span style="color: #2b91af;"&gt;StringBuilder&lt;/span&gt;();&lt;br /&gt;mxIsDt.Append(&lt;span style="color: #2b91af;"&gt;DateTime&lt;/span&gt;.Now.Year.ToString());&lt;br /&gt;mxIsDt.Append(&lt;span style="color: #2b91af;"&gt;DateTime&lt;/span&gt;.Now.Month.ToString());&lt;br /&gt;mxIsDt.Append(&lt;span style="color: #2b91af;"&gt;DateTime&lt;/span&gt;.Now.Day.ToString());&lt;br /&gt;mxIsDt.Append(&lt;span style="color: #2b91af;"&gt;DateTime&lt;/span&gt;.Now.Hour.ToString());&lt;br /&gt;mxIsDt.Append(&lt;span style="color: #2b91af;"&gt;DateTime&lt;/span&gt;.Now.Minute.ToString());&lt;br /&gt;mxIsDt.Append(&lt;span style="color: #2b91af;"&gt;DateTime&lt;/span&gt;.Now.Second.ToString());&lt;br /&gt;&lt;span style="color: blue;"&gt;string&lt;/span&gt;&amp;nbsp;mxDate&amp;nbsp;=&amp;nbsp;mxIsDt.ToString();&lt;/pre&gt;&lt;pre style="font-family: consolas;"&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="Apple-style-span" style="font-family: consolas;"&gt;Which converts into around 70 lines of IL and takes just &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="white-space: normal;"&gt;19160&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="white-space: normal;"&gt;milliseconds&lt;/span&gt;&lt;span class="Apple-style-span" style="white-space: normal;"&gt;&amp;nbsp;to complete. &amp;nbsp; Now my question is why wouldn't you use ToString on DateTime to do this.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="white-space: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;pre style="font-family: consolas; white-space: normal;"&gt;&lt;span style="color: blue;"&gt;var&lt;/span&gt;&amp;nbsp;d&amp;nbsp;=&amp;nbsp;&lt;span style="color: #2b91af;"&gt;DateTime&lt;/span&gt;.Now.ToString(&lt;span style="color: #a31515;"&gt;"yyyyMdhms"&lt;/span&gt;);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/pre&gt;&lt;pre style="font-family: consolas; white-space: normal;"&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="Apple-style-span" style="font-family: consolas;"&gt;&lt;span class="Apple-style-span" style="white-space: normal;"&gt;Which takes 8 lines or less in IL and takes 1213 &lt;/span&gt;milliseconds&lt;span class="Apple-style-span" style="white-space: normal;"&gt; to complete. It's way less code easier to&amp;nbsp;maintain&amp;nbsp;and examples on how to do this can be found all over the web. &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="Apple-style-span" style="font-family: consolas;"&gt;&lt;span class="Apple-style-span" style="white-space: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="Apple-style-span" style="font-family: consolas;"&gt;&lt;span class="Apple-style-span" style="white-space: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="Apple-style-span" style="font-family: consolas;"&gt;&lt;span class="Apple-style-span" style="white-space: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-5673327889129932552?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/5673327889129932552/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=5673327889129932552' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/5673327889129932552'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/5673327889129932552'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2011/02/date-time-you-are-doing-it-wrong-again.html' title='Date Time you are doing it wrong again.'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-2702114613073812433</id><published>2011-01-03T10:49:00.000-08:00</published><updated>2011-01-03T10:49:48.858-08:00</updated><title type='text'>Date Time You did it wrong.</title><content type='html'>This is a priceless gem I found today&lt;div&gt;&lt;pre style="font-family: consolas;"&gt;TranslateText("MonthName"+(DateTime.Now.Month-2).ToString("D2"),"")&lt;/pre&gt;&lt;pre style="font-family: consolas;"&gt;It will even work for 10 months out of the year.&lt;/pre&gt;&lt;pre style="font-family: consolas;"&gt;&lt;/pre&gt;&lt;pre style="font-family: consolas;"&gt;It should be &lt;/pre&gt;&lt;pre style="font-family: consolas;"&gt;&lt;pre style="font-family: consolas;"&gt;TranslateText("MonthName"+(DateTime.Now.AddMonths(-2).Month).ToString("D2")&lt;/pre&gt;&lt;pre style="font-family: consolas;"&gt;Which works for 12 months out of the year.&lt;/pre&gt;&lt;/pre&gt;&lt;pre style="font-family: consolas;"&gt;&lt;span style="color: blue;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="font-family: consolas;"&gt;&lt;span style="color: blue;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-2702114613073812433?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/2702114613073812433/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=2702114613073812433' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/2702114613073812433'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/2702114613073812433'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2011/01/date-time-you-did-it-wrong.html' title='Date Time You did it wrong.'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-2310324587108885383</id><published>2010-07-27T07:31:00.001-07:00</published><updated>2010-07-27T07:31:02.239-07:00</updated><title type='text'>Getting the value of a property through reflection.</title><content type='html'>&lt;p&gt;For a project I am working on I needed to retrieve the value of a property.&amp;#160; Problem was I had a string that told me the name of the property.&amp;#160; Most .NET people out there would say just use reflection stupid.&amp;#160; Which is what I did but it was a learning experience for me. This is my first foray into reflection.&amp;#160; Here is the code.&lt;/p&gt;  &lt;pre style="font-family: consolas"&gt;&lt;span style="color: #5b696a"&gt;public&lt;/span&gt;&amp;#160;&lt;span style="color: #5b696a"&gt;static&lt;/span&gt;&amp;#160;&lt;span style="color: #5b696a"&gt;object&lt;/span&gt;&amp;#160;&lt;span style="color: #c7c7a5"&gt;GetPropertyValue&lt;/span&gt;(&lt;span style="color: #5b696a"&gt;object&lt;/span&gt;&amp;#160;&lt;span style="color: #c7c7a5"&gt;ObjectInstance&lt;/span&gt;, &lt;span style="color: #5b696a"&gt;string&lt;/span&gt;&amp;#160;&lt;span style="color: #c7c7a5"&gt;WantedProperty&lt;/span&gt;)&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #5b696a"&gt;var&lt;/span&gt;&amp;#160;&lt;span style="color: #c7c7a5"&gt;aviableProperties&lt;/span&gt;&amp;#160;&lt;span style="color: #967878"&gt;=&lt;/span&gt;&amp;#160;&lt;span style="color: #c7c7a5"&gt;ObjectInstance&lt;/span&gt;&lt;span style="color: #967878"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5"&gt;GetType&lt;/span&gt;()&lt;span style="color: #967878"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5"&gt;GetProperties&lt;/span&gt;();&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #5b696a"&gt;var&lt;/span&gt;&amp;#160;&lt;span style="color: #c7c7a5"&gt;workingProperty&lt;/span&gt;&amp;#160;&lt;span style="color: #967878"&gt;=&lt;/span&gt;&amp;#160;&lt;span style="color: #c7c7a5"&gt;aviableProperties&lt;/span&gt;&lt;span style="color: #967878"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5"&gt;FirstOrDefault&lt;/span&gt;(&lt;span style="color: #c7c7a5"&gt;c&lt;/span&gt;&amp;#160;&lt;span style="color: #967878"&gt;=&amp;gt;&lt;/span&gt;&amp;#160;&lt;span style="color: #c7c7a5"&gt;c&lt;/span&gt;&lt;span style="color: #967878"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5"&gt;Name&lt;/span&gt;&amp;#160;&lt;span style="color: #967878"&gt;==&lt;/span&gt;&amp;#160;&lt;span style="color: #c7c7a5"&gt;WantedProperty&lt;/span&gt;);&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #5b696a"&gt;if&lt;/span&gt; (&lt;span style="color: #c7c7a5"&gt;workingProperty&lt;/span&gt;&amp;#160;&lt;span style="color: #967878"&gt;!=&lt;/span&gt;&amp;#160;&lt;span style="color: #5b696a"&gt;null&lt;/span&gt;)&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #5b696a"&gt;return&lt;/span&gt;&amp;#160;&lt;span style="color: #c7c7a5"&gt;workingProperty&lt;/span&gt;&lt;span style="color: #967878"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5"&gt;GetValue&lt;/span&gt;(&lt;span style="color: #c7c7a5"&gt;ObjectInstance&lt;/span&gt;, &lt;span style="color: #5b696a"&gt;null&lt;/span&gt;);&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #5b696a"&gt;throw&lt;/span&gt;&amp;#160;&lt;span style="color: #5b696a"&gt;new&lt;/span&gt;&amp;#160;&lt;span style="color: #799754"&gt;ApplicationException&lt;/span&gt;(&lt;span style="color: #5b696a"&gt;string&lt;/span&gt;&lt;span style="color: #967878"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5"&gt;Format&lt;/span&gt;(&lt;span style="color: #8c7050"&gt;&amp;quot;The Property {0} was not found in the class.&amp;quot;&lt;/span&gt;, &lt;span style="color: #c7c7a5"&gt;WantedProperty&lt;/span&gt;));&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-2310324587108885383?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/2310324587108885383/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=2310324587108885383' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/2310324587108885383'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/2310324587108885383'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2010/07/getting-value-of-property-through.html' title='Getting the value of a property through reflection.'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-5041875706560683294</id><published>2010-07-13T15:56:00.001-07:00</published><updated>2010-07-13T16:04:25.452-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='MVC2'/><title type='text'>ValidationAttribute verses the contextual validation</title><content type='html'>&lt;p&gt;This last week I got tasked with building some validation for the customer object in our new system here at work. Since we are using MVC2 I can use DataAnnotations to do this.  Which in most situations would just mean I throw on some attributes like                [Required(ErrorMessage="No soup for you")]  But not where I work we can’t have one set of required fields no.  Each country has a different set of required fields.  This means that I not only need to know what the data I am validating is but what context it is validate in. &lt;/p&gt;  &lt;p&gt;This means I can’t use&lt;/p&gt;&lt;div  style="background-;color:black;"&gt;    &lt;pre  style="font-family:consolas;"&gt;&lt;span style="color:#5b696a;"&gt;public&lt;/span&gt; &lt;span style="color:#5b696a;"&gt;bool&lt;/span&gt; &lt;span style="color:#c7c7a5;"&gt;IsValid&lt;/span&gt;(&lt;span style="color:#5b696a;"&gt;object&lt;/span&gt; &lt;span style="color:#c7c7a5;"&gt;value&lt;/span&gt;)&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;since it has no idea of context.  However there is a second overload of IsValid that will work.  It took me a bit to understand how this works but it is very nice.&lt;/p&gt;&lt;div  style="background-;color:black;"&gt; &lt;pre  style="font-family:consolas;"&gt;&lt;span style="color:#5b696a;"&gt;protected&lt;/span&gt; &lt;span style="color:#799754;"&gt;ValidationResult&lt;/span&gt; &lt;span style="color:#c7c7a5;"&gt;IsValid&lt;/span&gt;(&lt;span style="color:#5b696a;"&gt;object&lt;/span&gt; &lt;span style="color:#c7c7a5;"&gt;value&lt;/span&gt;, &lt;span style="color:#799754;"&gt;ValidationContext&lt;/span&gt; &lt;span style="color:#c7c7a5;"&gt;validationContext&lt;/span&gt;)&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;the ValidationContext gives you access to the object that’s data member you are validating.  By using the ObjectType and ObjectInstances of the property you can get access to all the data members of the current object.&lt;/p&gt;&lt;p&gt;Using the above functions It is easy to create a validator that checks to see if a country should or shouldn’t be validate for a given data member and then validate it if I need to.&lt;/p&gt;&lt;div  style="background-;color:black;"&gt; &lt;pre  style="font-family:consolas;"&gt;[&lt;span style="color:#799754;"&gt;AttributeUsage&lt;/span&gt;(&lt;span style="color:#bec37d;"&gt;AttributeTargets&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;Property&lt;/span&gt; &lt;span style="color:#967878;"&gt;|&lt;/span&gt; &lt;span style="color:#bec37d;"&gt;AttributeTargets&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;Field&lt;/span&gt;)]&lt;br /&gt;&lt;span style="color:#5b696a;"&gt;public&lt;/span&gt; &lt;span style="color:#5b696a;"&gt;class&lt;/span&gt; &lt;span style="color:#799754;"&gt;RequiredForCountry&lt;/span&gt; : &lt;span style="color:#799754;"&gt;ValidationAttribute&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;   &lt;span style="color:#5b696a;"&gt;public&lt;/span&gt; &lt;span style="color:#5b696a;"&gt;string&lt;/span&gt; &lt;span style="color:#c7c7a5;"&gt;CountryIds&lt;/span&gt; { &lt;span style="color:#5b696a;"&gt;get&lt;/span&gt;; &lt;span style="color:#5b696a;"&gt;set&lt;/span&gt;; }&lt;br /&gt;   &lt;span style="color:#5b696a;"&gt;public&lt;/span&gt; &lt;span style="color:#5b696a;"&gt;int&lt;/span&gt; &lt;span style="color:#c7c7a5;"&gt;TermId&lt;/span&gt; { &lt;span style="color:#5b696a;"&gt;get&lt;/span&gt;; &lt;span style="color:#5b696a;"&gt;set&lt;/span&gt;; }&lt;br /&gt;&lt;br /&gt;   &lt;span style="color:#5b696a;"&gt;protected&lt;/span&gt; &lt;span style="color:#5b696a;"&gt;override&lt;/span&gt; &lt;span style="color:#799754;"&gt;ValidationResult&lt;/span&gt; &lt;span style="color:#c7c7a5;"&gt;IsValid&lt;/span&gt;(&lt;span style="color:#5b696a;"&gt;object&lt;/span&gt; &lt;span style="color:#c7c7a5;"&gt;value&lt;/span&gt;, &lt;span style="color:#799754;"&gt;ValidationContext&lt;/span&gt; &lt;span style="color:#c7c7a5;"&gt;validationContext&lt;/span&gt;)&lt;br /&gt;   {&lt;br /&gt;       &lt;span style="color:#5b696a;"&gt;if&lt;/span&gt; (&lt;span style="color:#5b696a;"&gt;string&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;IsNullOrEmpty&lt;/span&gt;(&lt;span style="color:#5b696a;"&gt;this&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;CountryIds&lt;/span&gt;))&lt;br /&gt;       {&lt;br /&gt;           &lt;span style="color:#5b696a;"&gt;throw&lt;/span&gt; &lt;span style="color:#5b696a;"&gt;new&lt;/span&gt; &lt;span style="color:#c7c7a5;"&gt;System&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#799754;"&gt;ApplicationException&lt;/span&gt;(&lt;span style="color:#5b696a;"&gt;string&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;Format&lt;/span&gt;(&lt;br /&gt;                              &lt;span style="color:#8c7050;"&gt;"The property {0} is not set up correctly in class {1}"&lt;/span&gt;,&lt;br /&gt;                             &lt;span style="color:#c7c7a5;"&gt;validationContext&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;MemberName&lt;/span&gt;,&lt;br /&gt;                             &lt;span style="color:#c7c7a5;"&gt;validationContext&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;ObjectType&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;FullName&lt;/span&gt;));&lt;br /&gt;       }&lt;br /&gt;       &lt;span style="color:#5b696a;"&gt;var&lt;/span&gt; &lt;span style="color:#c7c7a5;"&gt;countryId&lt;/span&gt; &lt;span style="color:#967878;"&gt;=&lt;/span&gt; &lt;span style="color:#c7c7a5;"&gt;GetCountryID&lt;/span&gt;(&lt;span style="color:#c7c7a5;"&gt;validationContext&lt;/span&gt;);&lt;br /&gt;       &lt;span style="color:#5b696a;"&gt;if&lt;/span&gt; (&lt;span style="color:#c7c7a5;"&gt;CountryIds&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;Contains&lt;/span&gt;(&lt;span style="color:#c7c7a5;"&gt;countryId&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;ToString&lt;/span&gt;()))&lt;br /&gt;       {&lt;br /&gt;           &lt;span style="color:#5b696a;"&gt;if&lt;/span&gt; (&lt;span style="color:#c7c7a5;"&gt;value&lt;/span&gt; &lt;span style="color:#967878;"&gt;==&lt;/span&gt; &lt;span style="color:#5b696a;"&gt;null&lt;/span&gt;)&lt;br /&gt;               &lt;span style="color:#5b696a;"&gt;return&lt;/span&gt; &lt;span style="color:#5b696a;"&gt;new&lt;/span&gt; &lt;span style="color:#799754;"&gt;ValidationResult&lt;/span&gt;(&lt;span style="color:#c7c7a5;"&gt;TermId&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;ToString&lt;/span&gt;());&lt;br /&gt;           &lt;span style="color:#5b696a;"&gt;var&lt;/span&gt; &lt;span style="color:#c7c7a5;"&gt;strCheck&lt;/span&gt; &lt;span style="color:#967878;"&gt;=&lt;/span&gt; &lt;span style="color:#c7c7a5;"&gt;value&lt;/span&gt; &lt;span style="color:#5b696a;"&gt;as&lt;/span&gt; &lt;span style="color:#5b696a;"&gt;string&lt;/span&gt;;&lt;br /&gt;           &lt;span style="color:#5b696a;"&gt;if&lt;/span&gt; (&lt;span style="color:#c7c7a5;"&gt;strCheck&lt;/span&gt; &lt;span style="color:#967878;"&gt;!=&lt;/span&gt; &lt;span style="color:#5b696a;"&gt;null&lt;/span&gt; &lt;span style="color:#967878;"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span style="color:#c7c7a5;"&gt;strCheck&lt;/span&gt; &lt;span style="color:#967878;"&gt;==&lt;/span&gt; &lt;span style="color:#5b696a;"&gt;string&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;Empty&lt;/span&gt;)&lt;br /&gt;               &lt;span style="color:#5b696a;"&gt;return&lt;/span&gt; &lt;span style="color:#5b696a;"&gt;new&lt;/span&gt; &lt;span style="color:#799754;"&gt;ValidationResult&lt;/span&gt;(&lt;span style="color:#c7c7a5;"&gt;TermId&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;ToString&lt;/span&gt;());&lt;br /&gt;       }&lt;br /&gt;       &lt;span style="color:#5b696a;"&gt;return&lt;/span&gt; &lt;span style="color:#799754;"&gt;ValidationResult&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;Success&lt;/span&gt;;&lt;br /&gt;   }      &lt;br /&gt;&lt;br /&gt;   &lt;span style="color:#5b696a;"&gt;private&lt;/span&gt; &lt;span style="color:#5b696a;"&gt;int&lt;/span&gt; &lt;span style="color:#c7c7a5;"&gt;GetCountryID&lt;/span&gt;(&lt;span style="color:#799754;"&gt;ValidationContext&lt;/span&gt; &lt;span style="color:#c7c7a5;"&gt;context&lt;/span&gt;)&lt;br /&gt;   {&lt;br /&gt;       &lt;span style="color:#5b696a;"&gt;switch&lt;/span&gt; (&lt;span style="color:#c7c7a5;"&gt;context&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;ObjectType&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;Name&lt;/span&gt;)&lt;br /&gt;       {&lt;br /&gt;           &lt;span style="color:#5b696a;"&gt;case&lt;/span&gt; &lt;span style="color:#8c7050;"&gt;"Customer"&lt;/span&gt;:&lt;br /&gt;               &lt;span style="color:#5b696a;"&gt;return&lt;/span&gt; (&lt;span style="color:#c7c7a5;"&gt;context&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;ObjectInstance&lt;/span&gt; &lt;span style="color:#5b696a;"&gt;as&lt;/span&gt; &lt;span style="color:#c7c7a5;"&gt;ICustomer&lt;/span&gt;)&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;MainAddress&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;Country&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;Id&lt;/span&gt;;                  &lt;br /&gt;           &lt;span style="color:#5b696a;"&gt;case&lt;/span&gt; &lt;span style="color:#8c7050;"&gt;"Order"&lt;/span&gt;:&lt;br /&gt;               &lt;span style="color:#5b696a;"&gt;return&lt;/span&gt; (&lt;span style="color:#c7c7a5;"&gt;context&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;ObjectInstance&lt;/span&gt; &lt;span style="color:#5b696a;"&gt;as&lt;/span&gt; &lt;span style="color:#c7c7a5;"&gt;IOrder&lt;/span&gt;)&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;Country&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;Id&lt;/span&gt;;                  &lt;br /&gt;           &lt;span style="color:#5b696a;"&gt;default&lt;/span&gt;:&lt;br /&gt;               &lt;span style="color:#5b696a;"&gt;return&lt;/span&gt; &lt;span style="color:#967878;"&gt;-&lt;/span&gt;&lt;span style="color:#8c7050;"&gt;1&lt;/span&gt;; &lt;span style="color:#756f51;"&gt;// eventually this will throw an error&lt;/span&gt;&lt;br /&gt;       }&lt;br /&gt;   }      &lt;br /&gt;}&lt;span class="Apple-style-span"   style="font-family:Georgia, serif;font-size:130%;"&gt;&lt;span class="Apple-style-span" style="font-size: 16px; white-space: normal;"&gt;&lt;span class="Apple-style-span"   style="font-family:monospace;font-size:100%;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px; white-space: pre;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;While the above code isn’t the prettiest code I have ever written it gets the job done and allows me to not have to write custom validation for every country.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-5041875706560683294?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/5041875706560683294/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=5041875706560683294' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/5041875706560683294'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/5041875706560683294'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2010/07/validationattribute-verses-contextual.html' title='ValidationAttribute verses the contextual validation'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-2221839101306702577</id><published>2010-06-30T10:49:00.001-07:00</published><updated>2010-06-30T10:50:32.876-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PetPeev'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='BadCode'/><title type='text'>Proper Use of Properties</title><content type='html'>&lt;p&gt;Today we are talking about properties.&amp;#160; How to use them and more importantly how not to use them.&lt;/p&gt;  &lt;p&gt;When dealing with properties like they wore written before 3.5 you should have some thing that looks like this.&lt;/p&gt;  &lt;div style="background-color: black"&gt;   &lt;pre style="font-family: consolas"&gt;&lt;span style="color: #5b696a"&gt;private&lt;/span&gt;&amp;#160;&lt;span style="color: #5b696a"&gt;string&lt;/span&gt;&amp;#160;&lt;span style="color: #c7c7a5"&gt;_test&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: #5b696a"&gt;public&lt;/span&gt;&amp;#160;&lt;span style="color: #5b696a"&gt;string&lt;/span&gt;&amp;#160;&lt;span style="color: #c7c7a5"&gt;Test&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #5b696a"&gt;get&lt;/span&gt; { &lt;span style="color: #5b696a"&gt;return&lt;/span&gt;&amp;#160;&lt;span style="color: #5b696a"&gt;this&lt;/span&gt;&lt;span style="color: #967878"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5"&gt;_test&lt;/span&gt;; }&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #5b696a"&gt;set&lt;/span&gt; { &lt;span style="color: #5b696a"&gt;this&lt;/span&gt;&lt;span style="color: #967878"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5"&gt;_test&lt;/span&gt;&amp;#160;&lt;span style="color: #967878"&gt;=&lt;/span&gt;&amp;#160;&lt;span style="color: #5b696a"&gt;value&lt;/span&gt;; }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;I love properties like this it’s only slightly less cool then using the 3.5 version of a property. The thing I don’t like about a property like this is when a programmer decides he doesn’t need to user the property and accesses the _test variable directly inside of the class to make a change.&amp;#160; So like this&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: black"&gt;&lt;br /&gt;  &lt;pre style="font-family: consolas"&gt;&lt;span style="color: #5b696a"&gt;this&lt;/span&gt;&lt;span style="color: #967878"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5"&gt;_test&lt;/span&gt;&amp;#160;&lt;span style="color: #967878"&gt;=&lt;/span&gt;&amp;#160;&lt;span style="color: #8c7050"&gt;&amp;quot;some string&amp;quot;&lt;/span&gt;;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;I consider this bad programming.&amp;#160; It makes maintaining code much more difficult and adds an unnecessary level of complexity. You have to look at two things now to see how a value gets set or modified.&amp;#160; To do all the access through the property takes about the same amount of work and ends up in a much cleaner code file.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: black"&gt;&lt;br /&gt;  &lt;pre style="font-family: consolas"&gt;&lt;span style="color: #5b696a"&gt;this&lt;/span&gt;&lt;span style="color: #967878"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5"&gt;Test&lt;/span&gt;&amp;#160;&lt;span style="color: #967878"&gt;=&lt;/span&gt;&amp;#160;&lt;span style="color: #8c7050"&gt;&amp;quot;Some string&amp;quot;&lt;/span&gt;;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Is actually one less key stroke and is so much easier to work with.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-2221839101306702577?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/2221839101306702577/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=2221839101306702577' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/2221839101306702577'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/2221839101306702577'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2010/06/who-ever-thought-this-was-good-idea-is.html' title='Proper Use of Properties'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-580794333891346973</id><published>2010-06-29T12:21:00.001-07:00</published><updated>2010-06-29T13:48:23.059-07:00</updated><title type='text'>This code just rocks.</title><content type='html'>&lt;p&gt;Usually I post examples of code that sucks.&amp;#160; Today I am posting an example of code that just rocks.&amp;#160; Why does it rock because it solves a problem in a very elegant way.&amp;#160; I have had to write code to do the same thing several times but mine never looks or works as this example. The code comes from &lt;a href="http://ravendb.net" target="_blank"&gt;ravenDB&lt;/a&gt;’s server. It handles the case where you need to run in elevated privileges but the program wasn’t started at such a state. &lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;/p&gt;  &lt;div style="background-color: black"&gt;   &lt;pre style="font-family: consolas"&gt;&lt;span style="color: #5b696a"&gt;private&lt;/span&gt;&amp;#160;&lt;span style="color: #5b696a"&gt;static&lt;/span&gt;&amp;#160;&lt;span style="color: #5b696a"&gt;void&lt;/span&gt;&amp;#160;&lt;span style="color: #c7c7a5"&gt;AdminRequired&lt;/span&gt;(&lt;span style="color: #8c0054"&gt;Action&lt;/span&gt;&amp;#160;&lt;span style="color: #c7c7a5"&gt;actionThatMayRequiresAdminPrivileges&lt;/span&gt;, &lt;span style="color: #5b696a"&gt;string&lt;/span&gt;&amp;#160;&lt;span style="color: #c7c7a5"&gt;cmdLine&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #5b696a"&gt;var&lt;/span&gt;&amp;#160;&lt;span style="color: #c7c7a5"&gt;principal&lt;/span&gt;&amp;#160;&lt;span style="color: #967878"&gt;=&lt;/span&gt;&amp;#160;&lt;span style="color: #5b696a"&gt;new&lt;/span&gt;&amp;#160;&lt;span style="color: #799754"&gt;WindowsPrincipal&lt;/span&gt;(&lt;span style="color: #799754"&gt;WindowsIdentity&lt;/span&gt;&lt;span style="color: #967878"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5"&gt;GetCurrent&lt;/span&gt;());&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #5b696a"&gt;if&lt;/span&gt; (&lt;span style="color: #c7c7a5"&gt;principal&lt;/span&gt;&lt;span style="color: #967878"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5"&gt;IsInRole&lt;/span&gt;(&lt;span style="color: #bec37d"&gt;WindowsBuiltInRole&lt;/span&gt;&lt;span style="color: #967878"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5"&gt;Administrator&lt;/span&gt;) &lt;span style="color: #967878"&gt;==&lt;/span&gt;&amp;#160;&lt;span style="color: #5b696a"&gt;false&lt;/span&gt;)&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #5b696a"&gt;if&lt;/span&gt; (&lt;span style="color: #c7c7a5"&gt;RunAgainAsAdmin&lt;/span&gt;(&lt;span style="color: #c7c7a5"&gt;cmdLine&lt;/span&gt;))&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #5b696a"&gt;return&lt;/span&gt;;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #c7c7a5"&gt;actionThatMayRequiresAdminPrivileges&lt;/span&gt;();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #5b696a"&gt;private&lt;/span&gt;&amp;#160;&lt;span style="color: #5b696a"&gt;static&lt;/span&gt;&amp;#160;&lt;span style="color: #5b696a"&gt;bool&lt;/span&gt;&amp;#160;&lt;span style="color: #c7c7a5"&gt;RunAgainAsAdmin&lt;/span&gt;(&lt;span style="color: #5b696a"&gt;string&lt;/span&gt;&amp;#160;&lt;span style="color: #c7c7a5"&gt;cmdLine&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #5b696a"&gt;try&lt;/span&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #5b696a"&gt;var&lt;/span&gt;&amp;#160;&lt;span style="color: #c7c7a5"&gt;process&lt;/span&gt;&amp;#160;&lt;span style="color: #967878"&gt;=&lt;/span&gt;&amp;#160;&lt;span style="color: #799754"&gt;Process&lt;/span&gt;&lt;span style="color: #967878"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5"&gt;Start&lt;/span&gt;(&lt;span style="color: #5b696a"&gt;new&lt;/span&gt;&amp;#160;&lt;span style="color: #799754"&gt;ProcessStartInfo&lt;/span&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #c7c7a5"&gt;Arguments&lt;/span&gt;&amp;#160;&lt;span style="color: #967878"&gt;=&lt;/span&gt;&amp;#160;&lt;span style="color: #c7c7a5"&gt;cmdLine&lt;/span&gt;,&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #c7c7a5"&gt;FileName&lt;/span&gt;&amp;#160;&lt;span style="color: #967878"&gt;=&lt;/span&gt;&amp;#160;&lt;span style="color: #799754"&gt;Assembly&lt;/span&gt;&lt;span style="color: #967878"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5"&gt;GetExecutingAssembly&lt;/span&gt;()&lt;span style="color: #967878"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5"&gt;Location&lt;/span&gt;,&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #c7c7a5"&gt;Verb&lt;/span&gt;&amp;#160;&lt;span style="color: #967878"&gt;=&lt;/span&gt;&amp;#160;&lt;span style="color: #8c7050"&gt;&amp;quot;runas&amp;quot;&lt;/span&gt;,&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; });&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #5b696a"&gt;if&lt;/span&gt; (&lt;span style="color: #c7c7a5"&gt;process&lt;/span&gt;&amp;#160;&lt;span style="color: #967878"&gt;!=&lt;/span&gt;&amp;#160;&lt;span style="color: #5b696a"&gt;null&lt;/span&gt;)&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #c7c7a5"&gt;process&lt;/span&gt;&lt;span style="color: #967878"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5"&gt;WaitForExit&lt;/span&gt;();&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #5b696a"&gt;return&lt;/span&gt;&amp;#160;&lt;span style="color: #5b696a"&gt;true&lt;/span&gt;;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #5b696a"&gt;catch&lt;/span&gt; (&lt;span style="color: #799754"&gt;Exception&lt;/span&gt;)&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #5b696a"&gt;return&lt;/span&gt;&amp;#160;&lt;span style="color: #5b696a"&gt;false&lt;/span&gt;;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-580794333891346973?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/580794333891346973/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=580794333891346973' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/580794333891346973'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/580794333891346973'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2010/06/this-code-just-rocks.html' title='This code just rocks.'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-9033830840646502061</id><published>2010-01-20T11:34:00.000-08:00</published><updated>2010-01-20T12:12:08.345-08:00</updated><title type='text'>Wow this one takes the cake.</title><content type='html'>So of late I have been working on a older system created in .NET by a delphi programmer.  It has some very interesting behaviors. &lt;br /&gt;&lt;br /&gt;private string Xml { set { this.Address = value; } }&lt;br /&gt;&lt;br /&gt;public FooClass(PaymentInfo info)&lt;br /&gt; : base(info) &lt;br /&gt;{&lt;br /&gt; this.Xml = string.Format("Some random string goes here" . .&lt;br /&gt;&lt;br /&gt;The problems with this are many.  The least of which would be the fact they created a property Xml that just sets another property Address.  Why would you do this. You can just call Address.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-9033830840646502061?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/9033830840646502061/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=9033830840646502061' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/9033830840646502061'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/9033830840646502061'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2010/01/wow-this-one-takes-cake.html' title='Wow this one takes the cake.'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-5915183392825914575</id><published>2009-08-27T12:13:00.000-07:00</published><updated>2009-08-27T12:17:20.900-07:00</updated><title type='text'>Walk Of Shame.</title><content type='html'>So today as I am looking into why a program failed.  I ran across a wonderful little bug that was completely my fault. The offending line of code is.&lt;br /&gt;&lt;!-- {\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red91\green105\blue106;\red26\green24\blue21;\red150\green120\blue120;\red199\green199\blue165;\red222\green222\blue203;\red121\green151\blue84;\red140\green112\blue80;}??\fs28 \cf1\cb2\highlight2 this\cf3 .\cf4 _AviableCabinets\cf3 .\cf4 RemoveAt\cf5 (\cf1 this\cf3 .\cf4 _AviableCabinets\cf3 .\cf4 FindIndex\cf5 (\cf4 c\cf5  \cf3 =&gt;\cf5  \cf4 c\cf3 .\cf4 Name\cf5  \cf3 ==\cf5  \cf6 LanguageDB\cf3 .\cf4 GetText\cf5 (\cf7 "SelectDestLocalAllCabinetsText"\cf5 )));} --&gt;&lt;br /&gt;&lt;div    style="   background: #1a1815;font-family:Courier New;font-size:14pt;color:#dedecb;"&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style=" background: #2e2c26;color:#5b696a;"&gt;   76&lt;/span&gt; &lt;span style="color:#5b696a;"&gt;this&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;_AviableCabinets&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;RemoveAt&lt;/span&gt;(&lt;span style="color:#5b696a;"&gt;this&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;_AviableCabinets&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;FindIndex&lt;/span&gt;(&lt;span style="color:#c7c7a5;"&gt;c&lt;/span&gt; &lt;span style="color:#967878;"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color:#c7c7a5;"&gt;c&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;Name&lt;/span&gt; &lt;span style="color:#967878;"&gt;==&lt;/span&gt; &lt;span style="color:#799754;"&gt;LanguageDB&lt;/span&gt;&lt;span style="color:#967878;"&gt;.&lt;/span&gt;&lt;span style="color:#c7c7a5;"&gt;GetText&lt;/span&gt;(&lt;span style="color:#8c7050;"&gt;"SelectDestLocalAllCabinetsText"&lt;/span&gt;)));&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;The error it will throw is index out of bounds.    &lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The solution is easy.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="font-family: Courier New; font-size: 14pt; color: #dedecb; background: #1a1815;"&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;   76&lt;/span&gt; &lt;span style="color: #5b696a;"&gt;var&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;cLoc&lt;/span&gt; &lt;span style="color: #967878;"&gt;=&lt;/span&gt; &lt;span style="color: #5b696a;"&gt;this&lt;/span&gt;&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;_AviableCabinets&lt;/span&gt;&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;FindIndex&lt;/span&gt;(&lt;span style="color: #c7c7a5;"&gt;c&lt;/span&gt; &lt;span style="color: #967878;"&gt;=&gt;&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;c&lt;/span&gt;&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;Name&lt;/span&gt; &lt;span style="color: #967878;"&gt;==&lt;/span&gt; &lt;span style="color: #799754;"&gt;LanguageDB&lt;/span&gt;&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;GetText&lt;/span&gt;(&lt;span style="color: #8c7050;"&gt;"SelectDestLocalAllCabinetsText"&lt;/span&gt;));&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;   77&lt;/span&gt;             &lt;span style="color: #5b696a;"&gt;if&lt;/span&gt; (&lt;span style="color: #c7c7a5;"&gt;cLoc&lt;/span&gt; &lt;span style="color: #967878;"&gt;&gt;&lt;/span&gt; &lt;span style="color: #967878;"&gt;-&lt;/span&gt;&lt;span style="color: #8c7050;"&gt;1&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;   78&lt;/span&gt;             {&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;   79&lt;/span&gt;                 &lt;span style="color: #5b696a;"&gt;this&lt;/span&gt;&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;_AviableCabinets&lt;/span&gt;&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;RemoveAt&lt;/span&gt;(&lt;span style="color: #c7c7a5;"&gt;cLoc&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;   80&lt;/span&gt;             }&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Some Times it is better to not do it all on one line.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-5915183392825914575?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/5915183392825914575/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=5915183392825914575' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/5915183392825914575'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/5915183392825914575'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2009/08/walk-of-shame.html' title='Walk Of Shame.'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-1138364504282042288</id><published>2009-07-24T08:05:00.000-07:00</published><updated>2009-07-24T08:12:33.955-07:00</updated><title type='text'>Getting the day of the week the first day of the month is.</title><content type='html'>A co-worker of mine is learning to program and decided to write a calendar program.  He needed a way to find out what day of the week the first day of the month would be.  In his explaining of how he was doing it we came up with the following code that would work for his needs.&lt;br /&gt;&lt;br /&gt;&lt;!--&lt;br /&gt;{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red222\green222\blue203;\red26\green24\blue21;\red91\green105\blue106;\red199\green199\blue165;\red150\green120\blue120;\red140\green112\blue80;\red166\green92\blue92;}??\fs28 \cf1\cb2\highlight2         \cf3 static\cf1  \cf3 void\cf1  \cf4 Main\cf1 (\cf3 string\cf1 [] \cf4 args\cf1 )\par ??        \{\par ??\par ??            \cf3 string\cf1  \cf4 date\cf1  \cf5 =\cf1  \cf6 "1-1-09"\cf1 ;\par ??            \cf3 string\cf1  \cf4 dofw\cf1  \cf5 =\cf1  \cf4 GetDayOfWeekFromString\cf1 (\cf4 date\cf1 );\par ??\par ??        \}\par ??\par ??        \cf3 private\cf1  \cf3 static\cf1  \cf3 string\cf1  \cf4 GetDayOfWeekFromString\cf1 (\cf3 string\cf1  \cf4 date\cf1 )\par ??        \{\par ??            \cf7 DateTime\cf1  \cf4 desiredDay\cf1  \cf5 =\cf1  \cf3 new\cf1  \cf7 DateTime\cf1 ();\par ??            \cf7 DateTime\cf5 .\cf4 TryParse\cf1 (\cf4 date\cf1 , \cf3 out\cf1  \cf4 desiredDay\cf1 );\par ??            \cf3 return\cf1  \cf4 desiredDay\cf5 .\cf4 DayOfWeek\cf5 .\cf4 ToString\cf1 ();\par ??        \}}&lt;br /&gt;--&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 14pt; color: #dedecb; background: #1a1815;"&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;17&lt;/span&gt;&amp;nbsp;&lt;span style="color: #5b696a;"&gt;static&lt;/span&gt; &lt;span style="color: #5b696a;"&gt;void&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;Main&lt;/span&gt;(&lt;span style="color: #5b696a;"&gt;string&lt;/span&gt;[] &lt;span style="color: #c7c7a5;"&gt;args&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;18&lt;/span&gt;&amp;nbsp;{&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;19&lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;20&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #5b696a;"&gt;string&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;date&lt;/span&gt; &lt;span style="color: #967878;"&gt;=&lt;/span&gt; &lt;span style="color: #8c7050;"&gt;"1-1-09"&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;21&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #5b696a;"&gt;string&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;dofw&lt;/span&gt; &lt;span style="color: #967878;"&gt;=&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;GetDayOfWeekFromString&lt;/span&gt;(&lt;span style="color: #c7c7a5;"&gt;date&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;22&lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;23&lt;/span&gt;&amp;nbsp;}&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;24&lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;25&lt;/span&gt;&amp;nbsp;&lt;span style="color: #5b696a;"&gt;private&lt;/span&gt; &lt;span style="color: #5b696a;"&gt;static&lt;/span&gt; &lt;span style="color: #5b696a;"&gt;string&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;GetDayOfWeekFromString&lt;/span&gt;(&lt;span style="color: #5b696a;"&gt;string&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;date&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;26&lt;/span&gt;&amp;nbsp;{&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;27&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #a65c5c;"&gt;DateTime&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;desiredDay&lt;/span&gt; &lt;span style="color: #967878;"&gt;=&lt;/span&gt; &lt;span style="color: #5b696a;"&gt;new&lt;/span&gt; &lt;span style="color: #a65c5c;"&gt;DateTime&lt;/span&gt;();&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;28&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #a65c5c;"&gt;DateTime&lt;/span&gt;&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;TryParse&lt;/span&gt;(&lt;span style="color: #c7c7a5;"&gt;date&lt;/span&gt;, &lt;span style="color: #5b696a;"&gt;out&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;desiredDay&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;29&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #5b696a;"&gt;return&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;desiredDay&lt;/span&gt;&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;DayOfWeek&lt;/span&gt;&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;ToString&lt;/span&gt;();&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;30&lt;/span&gt;&amp;nbsp;}&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;After I gave him that code I decided to just pack it into an extension function.  Like so.&lt;br /&gt;&lt;br /&gt;&lt;!--&lt;br /&gt;{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red222\green222\blue203;\red26\green24\blue21;\red91\green105\blue106;\red199\green199\blue165;\red166\green92\blue92;\red150\green120\blue120;\red140\green112\blue80;}??\fs28 \cf1\cb2\highlight2         \cf3 public\cf1  \cf3 static\cf1  \cf3 string\cf1  \cf4 GetFirstDayOfMonthDayOfWeek\cf1 (\cf3 this\cf1  \cf5 DateTime\cf1  \cf4 dt\cf1 )\par ??        \{ \par ??            \cf5 DateTime\cf1  \cf4 firstOfMonth\cf1  \cf6 =\cf1  \cf3 new\cf1  \cf5 DateTime\cf1 ();\par ??            \cf3 if\cf1  (\cf5 DateTime\cf6 .\cf4 TryParse\cf1 (\cf3 string\cf6 .\cf4 Format\cf1 (\cf7 "\{0\}/1/\{1\}"\cf1 , \cf4 dt\cf6 .\cf4 Month\cf1 , \cf4 dt\cf6 .\cf4 Year\cf1 ), \cf3 out\cf1  \cf4 firstOfMonth\cf1 ))\par ??            \{\par ??                \cf3 return\cf1  \cf4 firstOfMonth\cf6 .\cf4 DayOfWeek\cf6 .\cf4 ToString\cf1 ();\par ??            \}\par ??            \cf3 return\cf1  \cf3 string\cf6 .\cf4 Empty\cf1 ;\par ??        \}}&lt;br /&gt;--&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 14pt; color: #dedecb; background: #1a1815;"&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;36&lt;/span&gt;&amp;nbsp;&lt;span style="color: #5b696a;"&gt;public&lt;/span&gt; &lt;span style="color: #5b696a;"&gt;static&lt;/span&gt; &lt;span style="color: #5b696a;"&gt;string&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;GetFirstDayOfMonthDayOfWeek&lt;/span&gt;(&lt;span style="color: #5b696a;"&gt;this&lt;/span&gt; &lt;span style="color: #a65c5c;"&gt;DateTime&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;dt&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;37&lt;/span&gt;&amp;nbsp;{ &lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;38&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #a65c5c;"&gt;DateTime&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;firstOfMonth&lt;/span&gt; &lt;span style="color: #967878;"&gt;=&lt;/span&gt; &lt;span style="color: #5b696a;"&gt;new&lt;/span&gt; &lt;span style="color: #a65c5c;"&gt;DateTime&lt;/span&gt;();&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;39&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #5b696a;"&gt;if&lt;/span&gt; (&lt;span style="color: #a65c5c;"&gt;DateTime&lt;/span&gt;&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;TryParse&lt;/span&gt;(&lt;span style="color: #5b696a;"&gt;string&lt;/span&gt;&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;Format&lt;/span&gt;(&lt;span style="color: #8c7050;"&gt;"{0}/1/{1}"&lt;/span&gt;, &lt;span style="color: #c7c7a5;"&gt;dt&lt;/span&gt;&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;Month&lt;/span&gt;, &lt;span style="color: #c7c7a5;"&gt;dt&lt;/span&gt;&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;Year&lt;/span&gt;), &lt;span style="color: #5b696a;"&gt;out&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;firstOfMonth&lt;/span&gt;))&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;40&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;41&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #5b696a;"&gt;return&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;firstOfMonth&lt;/span&gt;&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;DayOfWeek&lt;/span&gt;&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;ToString&lt;/span&gt;();&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;42&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;43&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #5b696a;"&gt;return&lt;/span&gt; &lt;span style="color: #5b696a;"&gt;string&lt;/span&gt;&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;Empty&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;44&lt;/span&gt;&amp;nbsp;}&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Which can be called like this.&lt;br /&gt;&lt;!--&lt;br /&gt;{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red222\green222\blue203;\red26\green24\blue21;\red91\green105\blue106;\red199\green199\blue165;\red150\green120\blue120;\red166\green92\blue92;}??\fs28 \cf1\cb2\highlight2             \cf3 string\cf1  \cf4 dofw\cf1  \cf5 =\cf1  \cf6 DateTime\cf5 .\cf4 Now\cf5 .\cf4 GetFirstDayOfMonthDayOfWeek\cf1 ();}&lt;br /&gt;--&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 14pt; color: #dedecb; background: #1a1815;"&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;21&lt;/span&gt;&amp;nbsp;&lt;span style="color: #5b696a;"&gt;string&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;dofw&lt;/span&gt; &lt;span style="color: #967878;"&gt;=&lt;/span&gt; &lt;span style="color: #a65c5c;"&gt;DateTime&lt;/span&gt;&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;Now&lt;/span&gt;&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;GetFirstDayOfMonthDayOfWeek&lt;/span&gt;();&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Hope someone else finds it of use.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-1138364504282042288?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/1138364504282042288/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=1138364504282042288' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/1138364504282042288'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/1138364504282042288'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2009/07/getting-day-of-week-first-day-of-month.html' title='Getting the day of the week the first day of the month is.'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-7076723501630705960</id><published>2009-07-23T15:57:00.000-07:00</published><updated>2009-07-23T15:59:24.423-07:00</updated><title type='text'>My python hours worked calc.</title><content type='html'>I use this horrid little piece of code to tell me how long i work each day.  It isn't all that grate but it gets the job done. &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;ClockInHoure = 7&lt;br /&gt;ClockInMinuet = 10&lt;br /&gt;ClockOutHoure = 5&lt;br /&gt;ClockOutMinuet = 0&lt;br /&gt;lunchstartHoure = 11&lt;br /&gt;lunchstartMinuet = 28&lt;br /&gt;lunchEndHour = 12&lt;br /&gt;lunchEndMInuets = 05&lt;br /&gt;&lt;br /&gt;#caculate hours worked&lt;br /&gt;mHours = 12 - ClockInHoure&lt;br /&gt;aHours = ClockOutHoure&lt;br /&gt;#get theminuets &lt;br /&gt;mMinuets = mHours * 60 - ClockInMinuet&lt;br /&gt;aMinuets = aHours * 60 + ClockOutMinuet&lt;br /&gt;&lt;br /&gt;tMins = mMinuets + aMinuets&lt;br /&gt;&lt;br /&gt;Lhours = lunchEndHour - lunchstartHoure&lt;br /&gt;lmins = lunchstartMinuet - lunchEndMInuets&lt;br /&gt;&lt;br /&gt;bMin = Lhours * 60 - lmins&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;tMins -= bMin&lt;br /&gt;&lt;br /&gt;tHour = tMins / 60&lt;br /&gt;tMinuets = tMins % 60&lt;br /&gt;if(tMinuets &lt; 10):&lt;br /&gt;    pMin = "0"+ str(tMinuets)&lt;br /&gt;else:&lt;br /&gt;    pMin = str(tMinuets)&lt;br /&gt;print "%d:%s" %(tHour,pMin )&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-7076723501630705960?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/7076723501630705960/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=7076723501630705960' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/7076723501630705960'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/7076723501630705960'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2009/07/my-python-hours-worked-calc.html' title='My python hours worked calc.'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-4809408319665981214</id><published>2009-07-20T11:40:00.000-07:00</published><updated>2009-07-20T12:56:17.921-07:00</updated><title type='text'>Setting the selected treeItem in a treeview on right click</title><content type='html'>So over the past several weeks I have been working with a lot of TreeViews in WPF  I use a HierarchicalDataTemplate with a custom ItemContainerStyle for my nodes in the tree.  I have been having a rather hard time finding a way to easily set the right clicked on node before the context menu is opened on it.  My HierarchicalDataTemplate consists of a stackpanel with a context menu and a image and textblock.&lt;br /&gt;&lt;br /&gt;In the ContextMenu_Opened function i put the following code.&lt;br /&gt;&lt;!--&lt;br /&gt;{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red91\green105\blue106;\red26\green24\blue21;\red222\green222\blue203;\red199\green199\blue165;\red150\green120\blue120;\red121\green151\blue84;}??\fs28 \cf1\cb2\highlight2 var\cf3  \cf4 cMenu\cf3  \cf5 =\cf3  \cf4 sender\cf3  \cf1 as\cf3  \cf6 ContextMenu\cf3 ;\par ??            \cf1 var\cf3  \cf4 tbase\cf3  \cf5 =\cf3  (\cf4 cMenu\cf5 .\cf4 PlacementTarget\cf3  \cf1 as\cf3  \cf6 StackPanel\cf3 )\cf5 .\cf4 DataContext\cf3  \cf1 as\cf3  \cf6 BasicTreeViewBase\cf3 ;\par ??            \cf4 tbase\cf5 .\cf4 IsSelected\cf3  \cf5 =\cf3  \cf1 true\cf3 ;}&lt;br /&gt;--&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 14pt; color: #dedecb; background: #1a1815;"&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;93&lt;/span&gt;&amp;nbsp;&lt;span style="color: #5b696a;"&gt;var&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;cMenu&lt;/span&gt; &lt;span style="color: #967878;"&gt;=&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;sender&lt;/span&gt; &lt;span style="color: #5b696a;"&gt;as&lt;/span&gt; &lt;span style="color: #799754;"&gt;ContextMenu&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;94&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #5b696a;"&gt;var&lt;/span&gt; &lt;span style="color: #c7c7a5;"&gt;tbase&lt;/span&gt; &lt;span style="color: #967878;"&gt;=&lt;/span&gt; (&lt;span style="color: #c7c7a5;"&gt;cMenu&lt;/span&gt;&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;PlacementTarget&lt;/span&gt; &lt;span style="color: #5b696a;"&gt;as&lt;/span&gt; &lt;span style="color: #799754;"&gt;StackPanel&lt;/span&gt;)&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;DataContext&lt;/span&gt; &lt;span style="color: #5b696a;"&gt;as&lt;/span&gt; &lt;span style="color: #799754;"&gt;BasicTreeViewBase&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #5b696a; background: #2e2c26;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;95&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #c7c7a5;"&gt;tbase&lt;/span&gt;&lt;span style="color: #967878;"&gt;.&lt;/span&gt;&lt;span style="color: #c7c7a5;"&gt;IsSelected&lt;/span&gt; &lt;span style="color: #967878;"&gt;=&lt;/span&gt; &lt;span style="color: #5b696a;"&gt;true&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Which will set my selected item to true.  The BasicTreeViewBase is a ViewModdle object baised off of the code found at &lt;a href="http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx"&gt;TreeViewWithViewModel&lt;/a&gt; and is rather simple.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-4809408319665981214?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/4809408319665981214/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=4809408319665981214' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/4809408319665981214'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/4809408319665981214'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2009/07/setting-selected-treeitem-in-treeview.html' title='Setting the selected treeItem in a treeview on right click'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-4215525999151674228</id><published>2009-05-06T06:56:00.000-07:00</published><updated>2009-05-06T07:11:59.089-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='lazy'/><category scheme='http://www.blogger.com/atom/ns#' term='python'/><category scheme='http://www.blogger.com/atom/ns#' term='least effort'/><title type='text'>Some times you just have to rename files.</title><content type='html'>&lt;div&gt;So I needed to rename a bunch of files.  I needed to add the size of the file as a postfix.  Same name just an adition of 16x16 which when doing it by hand is tedious.  So this little script was created.  You have to dump it into the same folder as the files you are working with, and you have to put the path in walkPath.  I could have it pull the current directory from the os but that would take work.  &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#FFCC66;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;import &lt;/span&gt;os&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;walkPath = &lt;span class="Apple-style-span"  style="color:#33FF33;"&gt;r"some disk path"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;        &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#FFCC66;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;for &lt;/span&gt;d &lt;span class="Apple-style-span"  style="color:#FF9966;"&gt;in &lt;/span&gt;os.walk(walkPath):&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dirpath, dirnames, filenames = d&lt;/div&gt;&lt;div&gt;    &lt;span class="Apple-style-span"  style="color:#FFCC66;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for &lt;/span&gt;a &lt;span class="Apple-style-span"  style="color:#FFCC66;"&gt;in &lt;/span&gt;filenames:&lt;/div&gt;&lt;div&gt;        &lt;span class="Apple-style-span"  style="color:#FF9900;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if &lt;/span&gt;a.endswith(&lt;span class="Apple-style-span"  style="color:#33FF33;"&gt;".py"&lt;/span&gt;):&lt;/div&gt;&lt;div&gt;            &lt;span class="Apple-style-span"  style="color:#FFCC66;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pass&lt;/span&gt;&lt;/div&gt;&lt;div&gt;        &lt;span class="Apple-style-span"  style="color:#FFCC66;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&lt;/span&gt;:&lt;/div&gt;&lt;div&gt;            &lt;span class="Apple-style-span"  style="color:#FFCC66;"&gt;         &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print &lt;/span&gt;a&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;aSplit = a.split(&lt;span class="Apple-style-span"  style="color:#66FF99;"&gt;"."&lt;/span&gt;)&lt;/div&gt;&lt;div&gt;         &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;os.rename(a,aSplit[0]+"16x16."+aSplit[1])&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-4215525999151674228?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/4215525999151674228/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=4215525999151674228' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/4215525999151674228'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/4215525999151674228'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2009/05/some-times-you-just-have-to-rename.html' title='Some times you just have to rename files.'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-704369859537649461</id><published>2009-03-16T07:25:00.000-07:00</published><updated>2009-03-16T07:31:08.811-07:00</updated><title type='text'>Strings in c++</title><content type='html'>I made the mistake of taking a c++ class.  Well itn's not a mistake it is good to be reminded of how much effort things are in c++.  Take strings for example. In c# if you want to lower case a string you do a str.ToLower() and it is lower case in c++ you have to do some thign like this.&lt;div&gt;&lt;!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;}??\fs20 \cf1 static\cf0  \cf1 void\cf0  ToLower(string &amp;amp;itext)\par ??\tab \{\par ??\tab \tab transform(itext.begin(), itext.end(), itext.begin(), (\cf1 int\cf0 (*)(\cf1 int\cf0 )) tolower);\par ??\tab \}} --&gt; &lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;   30&lt;/span&gt;     &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; ToLower(string &amp;amp;itext)&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;   31&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;   32&lt;/span&gt;         transform(itext.begin(), itext.end(), itext.begin(), (&lt;span style="color: blue;"&gt;int&lt;/span&gt;(*)(&lt;span style="color: blue;"&gt;int&lt;/span&gt;)) tolower);&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;   33&lt;/span&gt;     }&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;This one wasn't all that bad it is still just one line. This what the first one I needed&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;for the project I am working on at the moment.  The other one I wished I had on several&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;was str.Trim() just to clear off the white space. So I spend 5 minuets googling and found&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;something simlar to this.  &lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;!--{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red163\green21\blue21;}??\fs20 \tab \cf3 static\cf0  \cf3 void\cf0  Trim(string &amp;amp;itext)\par ??\tab \{\par ??\tab \tab \cf3 int\cf0  startLoc = itext.find_first_not_of(\cf4 " \\t\\n"\cf0 );\par ??\tab \tab \cf3 int\cf0  endLoc = itext.find_last_not_of(\cf4 " \\t\\n"\cf0 );\par ??\tab \tab \cf3 if\cf0 ((std::string::npos == startLoc) || (std::string::npos == endLoc))\par ??\tab \tab \{\par ??\tab \tab \tab itext = \cf4 ""\cf0 ;\par ??\tab \tab \}\par ??\tab \tab \cf3 else\par ??\cf0 \tab \tab \{\par ??\tab \tab \tab itext = itext.substr(startLoc,endLoc - startLoc + 1);\par ??\tab \tab \}\par ??\tab \}} --&gt; &lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;   35&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; Trim(string &amp;amp;itext)&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;   36&lt;/span&gt; {&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;   37&lt;/span&gt;     &lt;span style="color: blue;"&gt;int&lt;/span&gt; startLoc = itext.find_first_not_of(&lt;span style="color: #a31515;"&gt;" \t\n"&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;   38&lt;/span&gt;     &lt;span style="color: blue;"&gt;int&lt;/span&gt; endLoc = itext.find_last_not_of(&lt;span style="color: #a31515;"&gt;" \t\n"&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;   39&lt;/span&gt;     &lt;span style="color: blue;"&gt;if&lt;/span&gt;((std::string::npos == startLoc) || (std::string::npos == endLoc))&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;   40&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;   41&lt;/span&gt;         itext = &lt;span style="color: #a31515;"&gt;""&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;   42&lt;/span&gt;     }&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;   43&lt;/span&gt;     &lt;span style="color: blue;"&gt;else&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;   44&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;   45&lt;/span&gt;         itext = itext.substr(startLoc,endLoc - startLoc + 1);&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;   46&lt;/span&gt;     }&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;   47&lt;/span&gt; }&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;it dosn't do any thing but white space but still it is better then a kick in the face.&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-704369859537649461?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/704369859537649461/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=704369859537649461' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/704369859537649461'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/704369859537649461'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2009/03/strings-in-c.html' title='Strings in c++'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-2914579891552292307</id><published>2008-12-31T11:24:00.001-08:00</published><updated>2008-12-31T11:24:50.496-08:00</updated><title type='text'>C# is so much easier then C++</title><content type='html'>&lt;p&gt;I have been given the opportunity to work on an old c++ program for work this last couple works.  I just have to say that C# is so much easier to follow and understand then MFC any day of the week.  I did learn how to check if a directory exists before creating it though.&lt;br /&gt;&lt;/p&gt;  &lt;div    style=" background: white;  font-family:courier new;font-size:10pt;color:black;"&gt;   &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt; 1569&lt;/span&gt; &lt;span style="color:blue;"&gt;if&lt;/span&gt;(GetFileAttributes(_T(tPath)) == INVALID_FILE_ATTRIBUTES)&lt;/pre&gt;&lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt; 1570&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt; 1571&lt;/span&gt;         SECURITY_ATTRIBUTES sa;&lt;/pre&gt;&lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt; 1572&lt;/span&gt;         sa.nLength = &lt;span style="color:blue;"&gt;sizeof&lt;/span&gt;(SECURITY_ATTRIBUTES);        &lt;/pre&gt;&lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt; 1573&lt;/span&gt;         sa.lpSecurityDescriptor = NULL;&lt;/pre&gt;&lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt; 1574&lt;/span&gt;         sa.bInheritHandle = FALSE;&lt;/pre&gt;&lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt; 1575&lt;/span&gt;         CreateDirectory(_T(tPath),&amp;amp;sa);&lt;/pre&gt;&lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt; 1576&lt;/span&gt;     }&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Just thought I put this here for when I need it again.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-2914579891552292307?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/2914579891552292307/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=2914579891552292307' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/2914579891552292307'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/2914579891552292307'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2008/12/c-is-so-much-easier-then-c.html' title='C# is so much easier then C++'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-7963706640299224701</id><published>2008-12-10T07:44:00.001-08:00</published><updated>2008-12-10T07:54:17.725-08:00</updated><title type='text'>Delimiters</title><content type='html'>&lt;p&gt;Let’s talk about string delimiters and why you shouldn’t hard code them. Take the following example.&lt;/p&gt;  &lt;div style="width: 99%; overflow: auto;"&gt;&lt;div    style=" background: white;  font-family:courier new;font-size:10pt;color:black;"&gt;   &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   16&lt;/span&gt; &lt;span style="color:blue;"&gt;return&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;String&lt;/span&gt;.Format(&lt;span style="color:#a31515;"&gt;"#Command#{0}#{1}#{2}#{3}#{4}#{5}#{6}#{7}#{8}#{9}"&lt;/span&gt;, completePath,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   17&lt;/span&gt;                                                                       GUID,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   18&lt;/span&gt;                                                                       UID,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   19&lt;/span&gt;                                                                       otherinfo,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   20&lt;/span&gt;                                                                       option1,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   21&lt;/span&gt;                                                                       displayText,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   22&lt;/span&gt;                                                                       filter,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   23&lt;/span&gt;                                                                       someint.ToString(),&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   24&lt;/span&gt;                                                                       file,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   25&lt;/span&gt;                                                                       seckret);&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;It and three other ones just like it can be found in the code I am currently working on. Now when you see this you think that isn’t all that bad. Until you need to change the delimiter for one reason or another. You could go with something like the following but it not the most readable thing you will ever see.&lt;/p&gt;&lt;div style="width: 99%; overflow: auto;"&gt;&lt;div    style=" background: white;  font-family:courier new;font-size:10pt;color:black;"&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   28&lt;/span&gt; &lt;span style="color:blue;"&gt;return&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;String&lt;/span&gt;.Format(&lt;span style="color:#a31515;"&gt;"{10}Command{10}{0}{10}{1}{10}{2}{10}{3}{10}{4}{10}{5}{10}{6}{10}{7}{10}{8}{10}{9}"&lt;/span&gt;,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   29&lt;/span&gt;                                                                       completePath,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   30&lt;/span&gt;                                                                       GUID,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   31&lt;/span&gt;                                                                       UID,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   32&lt;/span&gt;                                                                       otherinfo,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   33&lt;/span&gt;                                                                       option1,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   34&lt;/span&gt;                                                                       displayText,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   35&lt;/span&gt;                                                                       filter,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   36&lt;/span&gt;                                                                       someint.ToString(),&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   37&lt;/span&gt;                                                                       file,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   38&lt;/span&gt;                                                                       seckret,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   39&lt;/span&gt;                                                                       commandStringDelimiter);&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;This is a little better now you can just change “commandStringDelimiter” to a different value when you need to change the delimiter. But it’s not verry readabel a better soluction is to do build a function that can build the string for you. This allows you to hide how it is created and keep it all in one place. Like this.&lt;/p&gt;&lt;div style="width: 99%; overflow: auto;"&gt;&lt;div    style=" background: white;  font-family:courier new;font-size:10pt;color:black;"&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   54&lt;/span&gt; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; BuildFileCommandString(&lt;span style="color:blue;"&gt;params&lt;/span&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt;[] options)&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   55&lt;/span&gt;         {&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   56&lt;/span&gt;             &lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;string&lt;/span&gt;&amp;gt; cStr = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;string&lt;/span&gt;&amp;gt;();&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   57&lt;/span&gt;             cStr.Add(&lt;span style="color:#a31515;"&gt;"Command"&lt;/span&gt;);&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   58&lt;/span&gt;             cStr.AddRange(options);&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   59&lt;/span&gt;             &lt;span style="color:blue;"&gt;return&lt;/span&gt; &lt;span style="color:blue;"&gt;this&lt;/span&gt;.commandStringDelimiter + &lt;span style="color:blue;"&gt;string&lt;/span&gt;.Join(&lt;span style="color:blue;"&gt;this&lt;/span&gt;.commandStringDelimiter, cStr.ToArray());&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   60&lt;/span&gt;         }      &lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;You would call it like this.&lt;/p&gt;&lt;div style="width: 99%; overflow: auto;"&gt;&lt;div    style=" background: white;  font-family:courier new;font-size:10pt;color:black;"&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   41&lt;/span&gt; BuildFileCommandString(completePath,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   42&lt;/span&gt;                        GUID,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   43&lt;/span&gt;                        UID,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   44&lt;/span&gt;                        otherinfo,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   45&lt;/span&gt;                        option1,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   46&lt;/span&gt;                        displayText,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   47&lt;/span&gt;                        filter,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   48&lt;/span&gt;                        someint.ToString(),&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   49&lt;/span&gt;                        file,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   50&lt;/span&gt;                        Seckret);&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;You will also notice that I used a string.Join rather then a string.Format this just makes it more readable to me.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-7963706640299224701?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/7963706640299224701/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=7963706640299224701' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/7963706640299224701'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/7963706640299224701'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2008/12/delimiters.html' title='Delimiters'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-2417315688297013857</id><published>2008-10-29T12:14:00.001-07:00</published><updated>2008-10-29T12:16:11.382-07:00</updated><title type='text'>Cool if statement.</title><content type='html'>&lt;p&gt;I ran into this little if statement while fixing moving some code around today. It does something like 18 string functions and that is assuming that Path.GetExtension is just one string function call.&lt;/p&gt;  &lt;div    style=" background: white;  font-family:courier new;font-size:10pt;color:black;"&gt;   &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   30&lt;/span&gt; &lt;span style="color:blue;"&gt;if&lt;/span&gt; (&lt;span style="color:#2b91af;"&gt;Path&lt;/span&gt;.GetExtension(path).ToLower() == &lt;span style="color:#a31515;"&gt;".tif"&lt;/span&gt;&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   31&lt;/span&gt;     || &lt;span style="color:#2b91af;"&gt;Path&lt;/span&gt;.GetExtension(path).ToLower() == &lt;span style="color:#a31515;"&gt;".pdf"&lt;/span&gt;&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   32&lt;/span&gt;     || &lt;span style="color:#2b91af;"&gt;Path&lt;/span&gt;.GetExtension(path).ToLower() == &lt;span style="color:#a31515;"&gt;".jpg"&lt;/span&gt;&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   33&lt;/span&gt;     || &lt;span style="color:#2b91af;"&gt;Path&lt;/span&gt;.GetExtension(path).ToLower() == &lt;span style="color:#a31515;"&gt;".png"&lt;/span&gt;&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   34&lt;/span&gt;     || &lt;span style="color:#2b91af;"&gt;Path&lt;/span&gt;.GetExtension(path).ToLower() == &lt;span style="color:#a31515;"&gt;".gif"&lt;/span&gt;&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   35&lt;/span&gt;     || &lt;span style="color:#2b91af;"&gt;Path&lt;/span&gt;.GetExtension(path).ToLower() == &lt;span style="color:#a31515;"&gt;".jpeg"&lt;/span&gt;)&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I decided that it needed to be removed and I replaced it with this.&lt;/p&gt;&lt;div    style=" background: white;  font-family:courier new;font-size:10pt;color:black;"&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   25&lt;/span&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; ext = &lt;span style="color:#2b91af;"&gt;Path&lt;/span&gt;.GetExtension(path).ToLower();            &lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   26&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;string&lt;/span&gt;&amp;gt; validExt = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;string&lt;/span&gt;&amp;gt; { &lt;span style="color:#a31515;"&gt;".tif"&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;".pdf"&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;".jpg"&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;".png"&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;".gif"&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;".jpeg"&lt;/span&gt; };&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   27&lt;/span&gt; if(validExt.Contains(ext)) &lt;/pre&gt;&lt;/div&gt;&lt;p&gt;But you could also do  this with LINQ&lt;/p&gt;&lt;div    style=" background: white;  font-family:courier new;font-size:10pt;color:black;"&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   25&lt;/span&gt; &lt;span style="color:blue;"&gt;var&lt;/span&gt; extensions = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;string&lt;/span&gt;&amp;gt; { &lt;span style="color:#a31515;"&gt;".jpg"&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;".jpeg"&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;".tif"&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;".png"&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;".gif"&lt;/span&gt; };&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   26&lt;/span&gt; &lt;span style="color:blue;"&gt;if&lt;/span&gt; ((&lt;span style="color:blue;"&gt;from&lt;/span&gt; i &lt;span style="color:blue;"&gt;in&lt;/span&gt; extensions &lt;span style="color:blue;"&gt;where&lt;/span&gt; i == &lt;span style="color:#2b91af;"&gt;Path&lt;/span&gt;.GetExtension(dir).ToLower() &lt;span style="color:blue;"&gt;select&lt;/span&gt; i).Count() &amp;gt; 0)&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I like the second version the best but that is just personal preference.  Both alternatives are way better then the first option.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-2417315688297013857?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/2417315688297013857/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=2417315688297013857' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/2417315688297013857'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/2417315688297013857'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2008/10/cool-if-statement.html' title='Cool if statement.'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-1102198104454954414</id><published>2008-10-28T16:07:00.001-07:00</published><updated>2008-10-28T16:18:32.774-07:00</updated><title type='text'>Fun with directory security</title><content type='html'>&lt;p&gt;So for the last couple weeks we have been having a problem with our installer and it’s setting of access rights on directories. This was mostly a problem with vista and well I got made the “vista access rights expert” so that translates into you get to figure out what is wrong.&lt;/p&gt;  &lt;div    style=" background: white;  font-family:courier new;font-size:10pt;color:black;"&gt;   &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   15&lt;/span&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; Main(&lt;span style="color:blue;"&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   16&lt;/span&gt; {&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   17&lt;/span&gt;     &lt;span style="color:blue;"&gt;string&lt;/span&gt; aPath = &lt;span style="color:#a31515;"&gt;@"C:\ProgramData\TestApp"&lt;/span&gt;;&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   18&lt;/span&gt;     &lt;span style="color:blue;"&gt;string&lt;/span&gt; fPath = &lt;span style="color:#2b91af;"&gt;Path&lt;/span&gt;.Combine(aPath, &lt;span style="color:#a31515;"&gt;"files"&lt;/span&gt;);&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   19&lt;/span&gt;     &lt;span style="color:#2b91af;"&gt;Directory&lt;/span&gt;.CreateDirectory(fPath);&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   20&lt;/span&gt;     SetPermissions(aPath);            &lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   21 &lt;/span&gt;}&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   22&lt;/span&gt; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; SetPermissions(&lt;span style="color:blue;"&gt;string&lt;/span&gt; dir)&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   23&lt;/span&gt; {&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   24&lt;/span&gt;     &lt;span style="color:#2b91af;"&gt;DirectoryInfo&lt;/span&gt; info = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;DirectoryInfo&lt;/span&gt;(dir);&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   25&lt;/span&gt;     &lt;span style="color:#2b91af;"&gt;DirectorySecurity&lt;/span&gt; ds = info.GetAccessControl();            &lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   26&lt;/span&gt;     ds.AddAccessRule(&lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;FileSystemAccessRule&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;@"BUILTIN\Users"&lt;/span&gt;, &lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   27&lt;/span&gt;                      &lt;span style="color:#2b91af;"&gt;FileSystemRights&lt;/span&gt;.FullControl,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   28&lt;/span&gt;                      &lt;span style="color:#2b91af;"&gt;InheritanceFlags&lt;/span&gt;.ContainerInherit,                            &lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   29&lt;/span&gt;                      &lt;span style="color:#2b91af;"&gt;PropagationFlags&lt;/span&gt;.None,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   30&lt;/span&gt;                      &lt;span style="color:#2b91af;"&gt;AccessControlType&lt;/span&gt;.Allow));&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   31&lt;/span&gt;     info.SetAccessControl(ds);            &lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   32&lt;/span&gt; }&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The code started out looking something like this. It adds a security rule for all users to the folder allowing use users access to data on the local system. Problem is that if a program tries to access the files it throws an access denied error. Even though the user’s effective permission to the folder is FullControl. He doesn’t have any access to the files in the folder, and can’t access the files dir at all. After several hours of reading and trying different things all the smart people I drug into help me with the problem came up with three small changes that make it all work without a problem.&lt;/p&gt;&lt;div    style=" background: white;  font-family:courier new;font-size:10pt;color:black;"&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   15&lt;/span&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; Main(&lt;span style="color:blue;"&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   16&lt;/span&gt; {&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   17&lt;/span&gt;     &lt;span style="color:blue;"&gt;string&lt;/span&gt; aPath = &lt;span style="color:#a31515;"&gt;@"C:\ProgramData\TestApp"&lt;/span&gt;;&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   18&lt;/span&gt;     &lt;span style="color:blue;"&gt;string&lt;/span&gt; fPath = &lt;span style="color:#2b91af;"&gt;Path&lt;/span&gt;.Combine(aPath, &lt;span style="color:#a31515;"&gt;"files"&lt;/span&gt;);&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   19&lt;/span&gt;     &lt;span style="color:#2b91af;"&gt;Directory&lt;/span&gt;.CreateDirectory(aPath);&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   20&lt;/span&gt;     SetPermissions(aPath);&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   21&lt;/span&gt;     &lt;span style="color:#2b91af;"&gt;Directory&lt;/span&gt;.CreateDirectory(fPath);&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   22 &lt;/span&gt;}&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   23 &lt;/span&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; SetPermissions(&lt;span style="color:blue;"&gt;string&lt;/span&gt; dir)&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   24&lt;/span&gt; {&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   25&lt;/span&gt;     &lt;span style="color:#2b91af;"&gt;DirectoryInfo&lt;/span&gt; info = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;DirectoryInfo&lt;/span&gt;(dir);&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   26&lt;/span&gt;     &lt;span style="color:#2b91af;"&gt;DirectorySecurity&lt;/span&gt; ds = info.GetAccessControl();&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   27&lt;/span&gt;     ds.AddAccessRule(&lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;FileSystemAccessRule&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;@"BUILTIN\Users"&lt;/span&gt;,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   28&lt;/span&gt;                      &lt;span style="color:#2b91af;"&gt;FileSystemRights&lt;/span&gt;.FullControl,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   29&lt;/span&gt;                      &lt;span style="color:#2b91af;"&gt;InheritanceFlags&lt;/span&gt;.ObjectInherit |&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   30&lt;/span&gt;                      &lt;span style="color:#2b91af;"&gt;InheritanceFlags&lt;/span&gt;.ContainerInherit,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   31&lt;/span&gt;                      &lt;span style="color:#2b91af;"&gt;PropagationFlags&lt;/span&gt;.None,&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   32&lt;/span&gt;                      &lt;span style="color:#2b91af;"&gt;AccessControlType&lt;/span&gt;.Allow));&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   33&lt;/span&gt;     info.SetAccessControl(ds);&lt;/pre&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color:#2b91af;"&gt;   34&lt;/span&gt; }&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The changes that needed to be made wore creating the base directory and setting permissions before the sub folder was added. In the set permissions folder there was also a second flag added to the inheritance option of FileSystemAccessRule that changed it so that both files and folders inherited the settings.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-1102198104454954414?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/1102198104454954414/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=1102198104454954414' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/1102198104454954414'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/1102198104454954414'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2008/10/fun-with-directory-security.html' title='Fun with directory security'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-3559764055187855675</id><published>2008-10-06T07:36:00.001-07:00</published><updated>2008-10-06T07:37:05.749-07:00</updated><title type='text'>The DAO Class</title><content type='html'>&lt;p&gt;In the project I am currently working on we have lots of objects and each object has it's own DAO class.&amp;#160; This is fine every class should have a DAO object.&amp;#160; Or I should say that there should be a DAO object that every class can use to access it's data from it's storage location. The thing is that most systems I have worked with don't do it this way.&amp;#160; They have a DAO object that creates objects.&amp;#160; Not objects that use the DAO system to create them selves. &lt;/p&gt;  &lt;p&gt;I will give you an example.&amp;#160; Say you have a class called foo and you want to get an instance of it from the database. With the DAO as create system you have to do the following.&lt;/p&gt;  &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt"&gt;   &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;#160;&amp;#160; 20&lt;/span&gt;&amp;#160;&lt;span style="color: #2b91af"&gt;foo&lt;/span&gt; bar = &lt;span style="color: #2b91af"&gt;fooDAO&lt;/span&gt;.GetFooByID(fooID);&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;bar gets created in the fooDAO object so basically any place where you want to work with foo you have to have fooDAO around and visible in scope as well.&amp;#160; No in the way I like to see things like this done a foo object has a reference to the fooDAO in his class so when you are creating the foo object you just say:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt"&gt;&lt;br /&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;#160;&amp;#160; 19&lt;/span&gt;&amp;#160;&lt;span style="color: #2b91af"&gt;foo&lt;/span&gt; bar = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;foo&lt;/span&gt;(fooID);&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;So some people will say you haven't accomplished all that much by pushing it down into the class.&amp;#160; Which is true you still have the same amount of code, but when the guy that writes the business logic is working with foo now he doesn't have to know about fooDAO or care about it. He gets to make calls like. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt"&gt;&lt;br /&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;#160;&amp;#160; 22&lt;/span&gt; bar.Save();&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;rather then calls like this.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt"&gt;&lt;br /&gt;  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;&amp;#160;&amp;#160; 23&lt;/span&gt;&amp;#160;&lt;span style="color: #2b91af"&gt;fooDAO&lt;/span&gt;.UpdateFoo(bar);&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Then when the day comes where it is time to stop using the cheep read free database you decided to use and switch over to a more powerful database. All of your updates can be done one place for each class type, and if you designed it right and use an well defined interface for your DAO object you will be able just to change the DAO object reference in each class.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-3559764055187855675?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/3559764055187855675/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=3559764055187855675' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/3559764055187855675'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/3559764055187855675'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2008/10/dao-class.html' title='The DAO Class'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-7500422383596255735</id><published>2008-10-01T08:17:00.001-07:00</published><updated>2008-10-01T08:17:53.974-07:00</updated><title type='text'>Best varible name ever.</title><content type='html'>So today I was looking at a coworker’s code.  I am doing CURD processes for the system I am working on this isn’t creative code or even variable code beyond you change the names of what you are keeping in the database.   But while grabbing his code to use as a template for the new function I ran across this little pearl of code.  My work went from boring to enjoyable in second all because of one line of code that made me laugh.   Her it is.&lt;br /&gt;&lt;br /&gt; &lt;!--&lt;br /&gt;{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;}??\fs20 \cf1 object\cf0  of_my_affection = command.ExecuteScalar();\par ??}&lt;br /&gt;--&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;&amp;nbsp;&amp;nbsp;716&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;object&lt;/span&gt; of_my_affection = command.ExecuteScalar();&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Sometimes having a bit of fun in your code makes it better than all the naming conventions you could ever use.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-7500422383596255735?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/7500422383596255735/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=7500422383596255735' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/7500422383596255735'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/7500422383596255735'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2008/10/best-varible-name-ever.html' title='Best varible name ever.'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-4587275922907132133</id><published>2008-09-26T06:52:00.000-07:00</published><updated>2008-09-26T07:07:19.389-07:00</updated><title type='text'>Returning the comparison results</title><content type='html'>Over the last couple weeks I have been looking at some of my old code as well as going over other peoples projects.  A personal pet peeve of mine keeps popping up in the code the worst part is when I started out programming I did the same thing.  It’s when you do a Boolean comparison then return true or false rather than just returning the results of the comparison.  Below is an example of what I am talking about.&lt;br /&gt;&lt;!--&lt;br /&gt;{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;}??\fs20             \cf3 if\cf0  (foo == otherFoo)\par ??            \{\par ??                \cf3 return\cf0  \cf3 true\cf0 ;\par ??            \}\par ??            \cf3 else\par ??\cf0             \{\par ??                \cf3 return\cf0  \cf3 false\cf0 ;\par ??            \}}&lt;br /&gt;--&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;21&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;if&lt;/span&gt; (foo == otherFoo)&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;22&lt;/span&gt;&amp;nbsp;{&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;23&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt; &lt;span style="color: blue;"&gt;true&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;24&lt;/span&gt;&amp;nbsp;}&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;25&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;else&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;26&lt;/span&gt;&amp;nbsp;{&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;27&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt; &lt;span style="color: blue;"&gt;false&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;28&lt;/span&gt;&amp;nbsp;}&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;The above is an example of what not to do.  There have been many times in my life where I have done this not thinking about what I was doing.  I am glad to say that time has passed.  I have talked to others about it and they say they do it because it is more explicit and easier to read.  I have a hard time agreeing with this stance how can the above be easier to read then the following.&lt;br /&gt;&lt;br /&gt;&lt;!--&lt;br /&gt;{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;}??\fs20 \cf1 return\cf0  foo == otherFoo;  }&lt;br /&gt;--&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;21&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;return&lt;/span&gt; foo == otherFoo;&amp;nbsp; &lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;It’s short simple and easy to read.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-4587275922907132133?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/4587275922907132133/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=4587275922907132133' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/4587275922907132133'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/4587275922907132133'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2008/09/over-last-couple-weeks-i-have-been.html' title='Returning the comparison results'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-6606827467973698136</id><published>2008-09-19T08:13:00.000-07:00</published><updated>2008-09-19T08:15:41.082-07:00</updated><title type='text'>Adding unique items to a list the fun way</title><content type='html'>&lt;!--&lt;br /&gt;{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red43\green145\blue175;}??\fs20 \cf1 public\cf0  \cf1 static\cf0  \cf1 void\cf0  AddIfUnique&amp;lt;T&amp;gt;(\cf1 this\cf0  \cf4 List\cf0 &amp;lt;T&amp;gt; tList, T toInsert, \cf4 Func\cf0 &amp;lt;T,T,\cf1 bool\cf0 &amp;gt; func)\par ??        \{\par ??            \cf1 if\cf0  (!tList.Exists(p =&amp;gt; func(p,toInsert)))\par ??            \{\par ??                tList.Add(toInsert);\par ??            \}\par ??        \}}&lt;br /&gt;--&gt;&lt;br /&gt;In some of the work I do I have to combine several lists into one list and only add a item if it is unique by some arbitrary rule.  I have done this so often in the last month I was about to write a code snipit for it.  Then I started learning about template functions and realized I could just make one function to do this for me.  I started out using Contains(vale,IEqualityComparer&lt;&gt;) to see if the item was already in a list this was a lot of effort and I never did figure out how to make a IEqualityCompare delegate.  But there is this nice little method on lists called Exists which takes a predicate for comparisone.  Which solved all my problems.  The extention function I came up with seen below is probaly my favrite so far.&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;36&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; AddIfUnique&amp;lt;T&amp;gt;(&lt;span style="color: blue;"&gt;this&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;List&lt;/span&gt;&amp;lt;T&amp;gt; tList, T toInsert, &lt;span style="color: #2b91af;"&gt;Func&lt;/span&gt;&amp;lt;T,T,&lt;span style="color: blue;"&gt;bool&lt;/span&gt;&amp;gt; func)&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;37&lt;/span&gt;&amp;nbsp;{&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;38&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;if&lt;/span&gt; (!tList.Exists(p =&amp;gt; func(p,toInsert)))&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;39&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;40&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; tList.Add(toInsert);&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;41&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;42&lt;/span&gt;&amp;nbsp;}&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;The usage for it is as follows.&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;15&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;DirectoryInfo&lt;/span&gt; mainDir = &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;DirectoryInfo&lt;/span&gt;(&lt;span style="color: #a31515;"&gt;@"c:\"&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;16&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;FileSystemInfo&lt;/span&gt;&amp;gt; item = &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;FileSystemInfo&lt;/span&gt;&amp;gt;();&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;17&lt;/span&gt;&amp;nbsp;item.AddRange(mainDir.GetFiles());&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;18&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;DirectoryInfo&lt;/span&gt; mainDir2 = &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;DirectoryInfo&lt;/span&gt;(&lt;span style="color: #a31515;"&gt;@"e:\"&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;19&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;FileSystemInfo&lt;/span&gt;&amp;gt; tList = &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;FileSystemInfo&lt;/span&gt;&amp;gt;();&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;20&lt;/span&gt;&amp;nbsp;tList.AddRange(mainDir2.GetFiles());&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;21&lt;/span&gt;&amp;nbsp;tList.ForEach(c =&amp;gt; item.AddIfUnique(c, (k, j) =&amp;gt; k.Name == j.Name));&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;In the above code the item list will end up with all file names that are unique.  While this example is not the most useful example out there it does show how it works.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-6606827467973698136?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/6606827467973698136/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=6606827467973698136' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/6606827467973698136'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/6606827467973698136'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2008/09/in-some-of-work-i-do-i-have-to-combine.html' title='Adding unique items to a list the fun way'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-6824503419789177521</id><published>2008-09-16T06:16:00.000-07:00</published><updated>2008-11-14T06:56:29.919-08:00</updated><title type='text'>ForEach the functional way.</title><content type='html'>&lt;!-- {\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red43\green145\blue175;}??\fs20 \cf1 public\cf0  \cf1 static\cf0  \cf1 void\cf0  ForEach&lt;t&gt;(\cf1 this\cf0  \cf4 IEnumerable\cf0 &lt;t&gt; list, \cf4 Action\cf0 &lt;t&gt; func)\par ??        \{\par ??            \cf1 foreach\cf0  (T t \cf1 in\cf0  list)\par ??            \{\par ??                func(t);\par ??            \}\par ??        \}       \par ??\par ??        \cf1 public\cf0  \cf1 static\cf0  \cf1 void\cf0  ForEach&lt;t&gt;(\cf1 this\cf0  \cf4 IEnumerable\cf0 &lt;t&gt; list, \cf4 Action\cf0 &lt;t&gt; func1, \cf4 Action\cf0 &lt;t,&gt;&gt; func2)\par ??        \{\par ??            \cf1 foreach\cf0  (T t \cf1 in\cf0  list)\par ??            \{\par ??                func2(t, func1);\par ??            \}\par ??        \}} --&gt;&lt;br /&gt;Before I started my current job I worked as a software tester and did a lot of automated testing in python.  I love working in python it takes most of the effort out of programming you just write down what you want and it compiles and runs.  Down side is python is not a strongly typed language and I picked up some very bad habits form python.  Which others have proceeded to beat out of me.   One thing that python did have that I truly miss is the map function. It makes working on lists so much cleaner, and when you mix that with lambda you come out being able to do a lot of work in very few lines of code.  A couple weeks ago I was talking with a friend of mine about how C# had no map functions and how if I had it I could shrink a bunch of code down to next to nothing.  The following functions are the results of that conversation.  At the time I didn't want to return a list at the time I was doing a lot of file maintenance and just wanted to traverse the folder structures in a clean way.  So llama being the guy he is emailed me these two functions.&lt;br /&gt;&lt;div    style="   background: white;font-family:Courier New;font-size:10pt;color:black;"&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;12&lt;/span&gt; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; ForEach&amp;lt;T&amp;gt;(&lt;span style="color:blue;"&gt;this&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;IEnumerable&lt;/span&gt;&amp;lt;T&amp;gt; list, &lt;span style="color:#2b91af;"&gt;Action&lt;/span&gt;&amp;lt;T&amp;gt; func)&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;13&lt;/span&gt; {&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;14&lt;/span&gt;     &lt;span style="color:blue;"&gt;foreach&lt;/span&gt; (T t &lt;span style="color:blue;"&gt;in&lt;/span&gt; list)&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;15&lt;/span&gt;     {&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;16&lt;/span&gt;         func(t);&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;17&lt;/span&gt;     }&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;18&lt;/span&gt; }&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;19&lt;/span&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;20&lt;/span&gt; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; ForEach&amp;lt;T&amp;gt;(&lt;span style="color:blue;"&gt;this&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;IEnumerable&lt;/span&gt;&amp;lt;T&amp;gt; list, &lt;span style="color:#2b91af;"&gt;Action&lt;/span&gt;&amp;lt;T&amp;gt; func1, &lt;span style="color:#2b91af;"&gt;Action&lt;/span&gt;&amp;lt;T, &lt;span style="color:#2b91af;"&gt;Action&lt;/span&gt;&amp;lt;T&amp;gt;&amp;gt; func2)&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;21&lt;/span&gt; {&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;22&lt;/span&gt;     &lt;span style="color:blue;"&gt;foreach&lt;/span&gt; (T t &lt;span style="color:blue;"&gt;in&lt;/span&gt; list)&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;23&lt;/span&gt;     {&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;24&lt;/span&gt;         func2(t, func1);&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;25&lt;/span&gt;     }&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;26&lt;/span&gt; }&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Here is an example of how they can be used.&lt;br /&gt;&lt;div    style="   background: white;font-family:Courier New;font-size:10pt;color:black;"&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;14&lt;/span&gt; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; WalkFiles(&lt;span style="color:blue;"&gt;string&lt;/span&gt; filePath, &lt;span style="color:#2b91af;"&gt;Action&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;string&lt;/span&gt;&amp;gt; workerFunc)&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;15&lt;/span&gt; {&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;16&lt;/span&gt;     &lt;span style="color:blue;"&gt;if&lt;/span&gt; (WalkFilesCont)&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;17&lt;/span&gt;     {&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;18&lt;/span&gt;         &lt;span style="color:blue;"&gt;if&lt;/span&gt; (&lt;span style="color:#2b91af;"&gt;Directory&lt;/span&gt;.Exists(filePath))&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;19&lt;/span&gt;         {&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;20&lt;/span&gt;             System.IO.&lt;span style="color:#2b91af;"&gt;Directory&lt;/span&gt;.GetFiles(filePath).ForEach(workerFunc);&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;21&lt;/span&gt;             System.IO.&lt;span style="color:#2b91af;"&gt;Directory&lt;/span&gt;.GetDirectories(filePath).ForEach(workerFunc, WalkFiles);&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;22&lt;/span&gt;         }&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;23&lt;/span&gt;     }&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color:#2b91af;"&gt;24&lt;/span&gt; }&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;I use them in a lot of other areas I even have one variation that behaves like a map in python I don't do much work on lists though where I need to see a result passed back so it doesn't get as much use.  These first function gets used quite a bit more than I expected.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-6824503419789177521?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/6824503419789177521/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=6824503419789177521' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/6824503419789177521'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/6824503419789177521'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2008/09/before-i-got-started-my-current-job-i.html' title='ForEach the functional way.'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-6846900487500489474</id><published>2008-09-11T11:07:00.000-07:00</published><updated>2008-09-11T11:21:29.074-07:00</updated><title type='text'>Programming the hard way</title><content type='html'>&lt;!--&lt;br /&gt;{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red163\green21\blue21;}??\fs20         \par ??        \cf3 using\cf0  (FileStream fs = \cf3 new\cf0  FileStream(FilePath, FileMode.Open))\par ??        \{\par ??            \cf3 using\cf0  (BinaryReader br = \cf3 new\cf0  BinaryReader(fs))\par ??                rawTiffData = br.ReadBytes((\cf3 int\cf0 )fs.Length);\par ??        \}\par ??        tiffData = \cf4 Convert\cf0 .ToBase64String(rawTiffData);\par ??        \par ??        \cf3 string\cf0  name = tiffPath.Substring(tiffPath.LastIndexOf(\cf5 '\\\\'\cf0 ) + 1,\par ??            tiffPath.LastIndexOf(\cf5 '.'\cf0 ) - tiffPath.LastIndexOf(\cf5 '\\\\'\cf0 ) - 1);\par ??\par ??}&lt;br /&gt;--&gt;&lt;br /&gt;On several occasions in my short life I have ran across coders that insist on not using the prebuilt classes and functions that come with .net.  I can understand not using a 3rd party lib when you write the entire product for the ground up, but if you are using .net you might as well use it to its fullest extent.&lt;br /&gt;Take the following code:&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;&amp;nbsp;9&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;using&lt;/span&gt; (FileStream fs = &lt;span style="color: blue;"&gt;new&lt;/span&gt; FileStream(FilePath, FileMode.Open))&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;10&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;11&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;using&lt;/span&gt; (BinaryReader br = &lt;span style="color: blue;"&gt;new&lt;/span&gt; BinaryReader(fs))&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;12&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; rawTiffData = br.ReadBytes((&lt;span style="color: blue;"&gt;int&lt;/span&gt;)fs.Length);&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;13&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;14&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; tiffData = &lt;span style="color: #2b91af;"&gt;Convert&lt;/span&gt;.ToBase64String(rawTiffData);&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;15&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;16&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;string&lt;/span&gt; name = tiffPath.Substring(tiffPath.LastIndexOf(&lt;span style="color: #a31515;"&gt;'\\'&lt;/span&gt;) + 1,&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;17&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; tiffPath.LastIndexOf(&lt;span style="color: #a31515;"&gt;'.'&lt;/span&gt;) - tiffPath.LastIndexOf(&lt;span style="color: #a31515;"&gt;'\\'&lt;/span&gt;) - 1);&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;It will open up a tiff file and read in all of the bytes and then convert it to base 64 encoding. Then he gets the name of the file without its extension. Let's do the same thing but using the .Net functions that should be used.&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;&amp;nbsp;9&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rawTiffData = &lt;span style="color: #2b91af;"&gt;File&lt;/span&gt;.ReadAllBytes(&lt;span style="color: blue;"&gt;this&lt;/span&gt;.FilePath);&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;10&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; tiffData = &lt;span style="color: #2b91af;"&gt;Convert&lt;/span&gt;.ToBase64String(rawTiffData);&lt;/span&gt;&lt;br /&gt;&lt;span style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;11&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;string&lt;/span&gt; name = &lt;span style="color: #2b91af;"&gt;Path&lt;/span&gt;.GetFileNameWithoutExtension(&lt;span style="color: blue;"&gt;this&lt;/span&gt;.FilePath);&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;The second section of code is almost self documenting. You can at a glance see what is going where and why.  You also don't have to worry about getting your substring wrong or someone a year down the road coming in and making a small change to the substring call to make it better. Adding a bug that is not trivial to find.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-6846900487500489474?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/6846900487500489474/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=6846900487500489474' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/6846900487500489474'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/6846900487500489474'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2008/09/programming-hard-way.html' title='Programming the hard way'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5993074704535120230.post-9188098282625365391</id><published>2008-09-10T07:51:00.000-07:00</published><updated>2008-09-18T12:20:54.297-07:00</updated><title type='text'>Good code layout.</title><content type='html'>&lt;p&gt;Recently I have been looking at and writing a lot of c# code. It's nice when you get paid to program in the language you want to learn.  I have noticed in several places where people build the same complete object with one or two difference in two separate locations in the code usually a if else statement.  I have a big belief in don't repeat yourself when programming.   If you find you are writing the exact same code or close to it over and over again you are doing something wrong. Here is a good example of what I am talking about.  It also isn't too far from the code that made me want to write this post.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: rgb(51, 51, 255);"&gt;String&lt;/span&gt; Foo1 = &lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;"3.4.5"&lt;/span&gt;;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: rgb(51, 51, 255);"&gt;String&lt;/span&gt; Foo2= &lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;"3.4.6"&lt;/span&gt;;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: rgb(51, 51, 255);"&gt;mObject&lt;/span&gt; boo = &lt;span class="Apple-style-span" style="color: rgb(51, 51, 255);"&gt;null&lt;/span&gt;;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: rgb(51, 51, 255);"&gt;if&lt;/span&gt;(&lt;span class="Apple-style-span" style="color: rgb(51, 51, 255);"&gt;new&lt;/span&gt; Version(Foo1) &gt; new Version(Foo2))&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;boo = &lt;span class="Apple-style-span" style="color: rgb(51, 51, 255);"&gt;new&lt;/span&gt; &lt;span class="Apple-style-span" style="color: rgb(51, 51, 255);"&gt;mObject&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;vLam = &lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;"yummy"&lt;/span&gt;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;jArp= &lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;"jello"&lt;/span&gt;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cFile= &lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;"No" &lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;};&lt;br /&gt;}&lt;br /&gt;Else&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;boo = &lt;span class="Apple-style-span" style="color: rgb(51, 51, 255);"&gt;new&lt;/span&gt; &lt;span class="Apple-style-span" style="color: rgb(51, 51, 255);"&gt;mObject&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;vLam = &lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;"yummy"&lt;/span&gt;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;jArp= &lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;"jam"&lt;/span&gt;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cFile= &lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;"Yes"&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;};&lt;br /&gt;}&lt;br /&gt;&lt;p&gt;In the above code we see an example of what not to do.  You are creating dynamic objects to make a decision that could be made using a string comparison operator which isn't really on topic but is worth mentioning.  Also you have double the code you need in creating your object.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Now let's do it in the cleaner way that I would like to see one instantiation and then just assign the values as we go.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: rgb(51, 51, 255);"&gt;String&lt;/span&gt; Foo1 = &lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;"3.4.5"&lt;/span&gt;;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: rgb(51, 51, 255);"&gt;String&lt;/span&gt; Foo2= &lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;"3.4.6"&lt;/span&gt;;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: rgb(51, 51, 255);"&gt;bool&lt;/span&gt; isFoo2Less = Foo1.CompareTo(Foo2) &gt; &lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;0&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: rgb(51, 51, 255);"&gt;mObject&lt;/span&gt; boo = &lt;span class="Apple-style-span" style="color: rgb(51, 51, 255);"&gt;new&lt;/span&gt; &lt;span class="Apple-style-span" style="color: rgb(51, 51, 255);"&gt;mObject&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;vLam = &lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;"yummy"&lt;/span&gt;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;jArp= (isFoo2Less)? &lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;"jello"&lt;/span&gt;  : &lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;"jam"&lt;/span&gt;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cFile=(isFoo2Less)? &lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;"No"&lt;/span&gt; : &lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;"Yes"&lt;/span&gt;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;p&gt;We end up with less lines of code and even though we add a variable to the mix and do two checks. The maintainability of this code is much easier and will cause less confusion over the life of the program.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5993074704535120230-9188098282625365391?l=bitsoffoo.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bitsoffoo.blogspot.com/feeds/9188098282625365391/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5993074704535120230&amp;postID=9188098282625365391' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/9188098282625365391'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5993074704535120230/posts/default/9188098282625365391'/><link rel='alternate' type='text/html' href='http://bitsoffoo.blogspot.com/2008/09/good-code-layout.html' title='Good code layout.'/><author><name>Erin</name><uri>http://www.blogger.com/profile/02595867288580221282</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry></feed>
