Things I miss about Ruby when working in C#

By: Johnathon Wright on: April 09, 2013

h2. Preface: nil

for those of you who don't know, nil is like NULL, but way cooler. But if you don't know, just pretend it means NULL, but if you ask whether NULL is true or false, it will say, "Oh, yeah, I'm false." Yes, I know, if you haven't heard of nil this makes you think I'm on crack. Roll with me.

h2. Returning a value or "Sorry, no."

I miss being able to return either the value OR nil, meaning, "no." For instance, I have people picking a date from some dropdowns on a form. Then I need to (a) know whether it's a valid date and (b) know what date it is. Ignoring, for a minute, that this problem wouldn't exist in ruby, I could do this.

Note: begin/rescue is ruby's try/catch.

---ruby def selected_date begin Date.new( year, month, day ) rescue InvalidDateError # I have never had to do this so I don't actually know which error it would be.** nil end

end

but in C#: ---csharp private Boolean specifiedDateValid() { int year = int.Parse( yearTextbox.Text ); int month = int.Parse( monthTextbox.Text ); int day = int.Parse( dayTextbox.Text );

        DateTime ignore = new DateTime();
        string datestring = month.ToString() + "/" + day.ToString() + "/" + year.ToString();

        return( DateTime.TryParse( datestring, out ignore ) );          
    }


    private DateTime specifiedDate()
    {
        int year = int.Parse( yearTextbox.Text );
        int month = int.Parse( monthTextbox.Text );
        int day = int.Parse( dayTextbox.Text );

        return(
            new DateTime( year, month, day ));
    }

another example. I'm creating a search method. Search by parameters A, B and C. Well, I decide maybe I will also want the option of searching by A and B. So I'll just leave C blank. But that will make C# flip out... in Ruby, you can just say, "Hey, is that value blank? Or nil? If so, just ignore it".

h2. Not having to deal with Tedium

I just spent 20 minutes PARSING A DATE. Yes, I realize there are a ton of interesting things about that... but there are also a ton of interesting things elsewhere, and I should never have to deal with this unless my client is Doctor Who or whatever. Even though there are a lot of dates in Ruby, I have never had to deal with parsing dates. OK actually that's not true... I did have to deal with it once. But that was because my users were entering dates like "3/310" ... which was a typo and Ruby's prebuilt tools were like, "Yeah, uh.... year? valid date? give me something I can work with here."

It isn't fair to say I never have to deal with tedium... but honestly I would say it's almost a daily thing with C# and about 90% better in Ruby.

h2. Enumerable Blocks and Tap and Blocks In General

h2. I feel like I'm sacrificing my effectiveness on the alter of infrastructure.

So I recently wrote a Month model because I needed to model that. And then I wanted to get a list of months from month x to month y. For instance, right now I need all months from January of the previous year until December of the current year. But for the sake of completeness, I might want to go backwards... in fact, I anticipate needing that.

In Ruby: ---ruby class Month ... existing implementation def <=>(othermonth) self.firstday <=> othermonth.firstday end end

# and then you could get a range by using Ruby's "range" syntax:

firstmonth..lastmonth

In C#:

# I'm not sure. I know you would have to implement some kind of interface... perhaps iComperable if memory serves? And then I guess you could do a for loop, but then you wouldn't know for sure whether you needed a < or > operator.

h1. Things I just don't like and/or don't understand about C#

h2. In winforms, it seems like you can't really get away from the codebehind... or whatever that's called... the cs file behind a screen. Everything has to happen in that one file... from validation to parsing of values to ... processing... a nightmare.

h2. Some things I miss about C# when working in Ruby

  • Date#ToString has some intuitive formats... on the other hand, Ruby's way is more repeatable.
  • interfaces. Yes, that's right. I miss interfaces. Ruby has duck typing... and that works for me. But sometimes I just wish I could ... just ... have interface guarantees.

h2. Some things I'm unsure whether to love or hate

  • "using" statements. On one hand, it's great to know exactly what's in there. On the other hand, some limited magic is part of Ruby, both for good and evil. But mostly for good. Depending on the dev.




Comments:

hermes belts said: My spouse and i ended up being quite glad that Chris managed to carry out his reports because of the ideas he discovered in your web pages. It is now and again perplexing just to always be giving away strategies that many the others have been selling. And now we do understand we have got the blog owner to appreciate because of that. Most of the explanations you've made, the simple website navigation, the friendships you make it possible to foster - it's got everything extraordinary, and it's really leading our son in addition to us do think that matter is pleasurable, which is incredibly pressing. Many thanks for everything! hermes belts [url=http://www.hermesbelts.com]hermes belts[/url]

jordans said: I enjoy you because of every one of your labor on this web page. Gloria take interest in carrying out investigations and it's easy to understand why. We hear all about the lively method you render practical thoughts via this website and even invigorate participation from some other people on that concept while my princess is truly starting to learn a lot. Take advantage of the remaining portion of the year. You are doing a tremendous job. jordans

russell westbrook shoes said: I needed to draft you the very small note just to thank you over again on your magnificent opinions you've discussed in this case. It's simply incredibly generous with people like you to offer unhampered what exactly a lot of people could have offered for an ebook to help make some money for their own end, even more so seeing that you could possibly have tried it if you desired. These strategies additionally worked as the good way to fully grasp many people have the same fervor like my personal own to grasp whole lot more on the subject of this matter. I am sure there are numerous more pleasant occasions ahead for those who look over your website. russell westbrook shoes

louboutin shoes said: I have to express my appreciation to you just for rescuing me from this problem. As a result of checking through the online world and coming across tips which were not helpful, I figured my life was gone. Being alive without the presence of strategies to the issues you've fixed by means of your main article content is a crucial case, and those which could have in a negative way damaged my career if I hadn't encountered your blog post. The capability and kindness in touching all the details was helpful. I am not sure what I would have done if I had not come upon such a step like this. I can also at this moment look ahead to my future. Thank you very much for the expert and sensible guide. I will not be reluctant to suggest the website to any person who requires care about this subject matter. louboutin shoes

bape clothing said: My wife and i were so contented Jordan could finish off his studies via the ideas he grabbed in your site. It is now and again perplexing to simply happen to be offering concepts which usually men and women may have been making money from. And now we take into account we need the blog owner to be grateful to for that. Most of the illustrations you made, the straightforward blog menu, the relationships you can make it possible to engender - it's all great, and it's really facilitating our son and the family reason why that situation is exciting, and that is tremendously pressing. Thank you for everything! bape clothing

curry 7 said: I and also my guys have already been viewing the good pointers found on your web page and instantly I had an awful suspicion I had not thanked the web blog owner for those strategies. The boys had been so thrilled to study all of them and already have in actuality been taking advantage of them. I appreciate you for simply being very accommodating and also for finding this form of brilliant useful guides millions of individuals are really desperate to be aware of. My personal honest apologies for not expressing gratitude to earlier. curry 7

balenciaga shoes said: I together with my friends have been studying the good things on the website and so at once developed an awful feeling I never expressed respect to you for those tips. Most of the women are actually totally happy to read through them and have in effect absolutely been having fun with those things. Thank you for actually being indeed considerate as well as for obtaining this sort of superior themes most people are really needing to be aware of. Our own sincere regret for not saying thanks to you sooner. balenciaga shoes

nike air max said: My spouse and i got really ecstatic when Peter managed to do his researching while using the precious recommendations he received while using the blog. It is now and again perplexing to simply be handing out secrets and techniques that some other people may have been trying to sell. And we do know we need the blog owner to be grateful to for this. Most of the illustrations you have made, the simple web site navigation, the friendships you can make it easier to instill - it is many overwhelming, and it is aiding our son and us feel that this topic is enjoyable, which is certainly pretty indispensable. Thanks for the whole thing! nike air max

nike epic react flyknit said: Thank you for all of the work on this web site. Ellie loves doing internet research and it's really simple to grasp why. A number of us know all relating to the powerful method you provide good suggestions by means of this blog and as well recommend response from visitors about this concept plus our princess is without a doubt becoming educated so much. Enjoy the rest of the new year. You have been performing a good job. nike epic react flyknit

chrome hearts online said: Would you be all in favour of exchanging links? chrome hearts online

giannis antetokounmpo shoes said: It is best to participate in a contest for among the best blogs on the web. I'll advocate this web site! giannis antetokounmpo shoes

yeezy boost said: Aw, this was a really nice post. In concept I want to put in writing like this additionally ?taking time and actual effort to make an excellent article?but what can I say?I procrastinate alot and on no account seem to get one thing done. yeezy boost

air jordan said: When I initially commented I clicked the -Notify me when new feedback are added- checkbox and now every time a remark is added I get four emails with the same comment. Is there any manner you'll be able to take away me from that service? Thanks! air jordan

yeezy supply said: There's noticeably a bundle to find out about this. I assume you made certain good factors in options also. yeezy supply

yeezy said: After I initially commented I clicked the -Notify me when new feedback are added- checkbox and now every time a remark is added I get four emails with the identical comment. Is there any means you possibly can take away me from that service? Thanks! yeezy

jordan 12 said: There's noticeably a bundle to learn about this. I assume you made certain good points in features also. jordan 12

golden goose outlet said: Youre so cool! I dont suppose Ive read something like this before. So nice to seek out any individual with some original ideas on this subject. realy thank you for starting this up. this web site is one thing that's wanted on the internet, somebody with a bit of originality. helpful job for bringing something new to the internet! golden goose outlet

yeezy said: you may have an important blog right here! would you prefer to make some invite posts on my blog? yeezy

nike shox said: Howdy! I just wish to give an enormous thumbs up for the great data you have here on this post. I might be coming back to your weblog for extra soon. nike shox

longchamp handbags said: I enjoy you because of all of the labor on this blog. My aunt really loves conducting research and it's really easy to understand why. Most people notice all concerning the lively method you give worthwhile tips on your blog and even invigorate contribution from some other people about this issue and our favorite girl is always becoming educated so much. Take advantage of the remaining portion of the year. You are always conducting a superb job. longchamp handbags

ggdb said: My husband and i were really satisfied when Jordan could finish up his analysis from your ideas he gained from your own site. It is now and again perplexing to just choose to be handing out concepts that some other people may have been selling. Therefore we already know we've got the website owner to give thanks to for this. The main explanations you've made, the easy website menu, the friendships your site help engender - it's got all incredible, and it is making our son in addition to us understand this subject matter is enjoyable, which is certainly seriously important. Thanks for the whole thing! ggdb

supreme clothing said: My wife and i have been really thankful Chris could deal with his survey from your precious recommendations he was given in your site. It's not at all simplistic to just possibly be handing out facts which usually many others might have been trying to sell. So we see we have got the blog owner to appreciate because of that. The illustrations you have made, the straightforward web site menu, the relationships you will help to promote - it's got most exceptional, and it's really helping our son and us consider that the matter is thrilling, and that's exceedingly mandatory. Thanks for all the pieces! supreme clothing

yeezy 700 said: I must voice my respect for your kind-heartedness for people that need help with that concept. Your very own commitment to passing the solution throughout has been incredibly insightful and have consistently permitted professionals like me to arrive at their dreams. Your new important report can mean so much a person like me and additionally to my office colleagues. Many thanks; from all of us. yeezy 700

moncler said: I would like to show my appreciation to the writer just for bailing me out of this instance. After looking out through the search engines and finding thoughts which are not productive, I believed my life was well over. Existing minus the strategies to the problems you've fixed as a result of your guide is a critical case, as well as the kind that would have badly affected my entire career if I had not come across your blog post. Your expertise and kindness in touching all the stuff was tremendous. I don't know what I would have done if I had not discovered such a solution like this. It's possible to at this time look forward to my future. Thanks for your time very much for this high quality and effective guide. I won't think twice to suggest your blog to any individual who should get tips on this subject. moncler

off white clothing said: Thanks so much for giving everyone an extremely special opportunity to read from this website. It really is so fantastic and full of amusement for me and my office friends to visit your site no less than thrice every week to read through the fresh tips you have. And of course, I am usually motivated with the outstanding tactics you serve. Selected 1 ideas in this posting are really the very best we have ever had. off white clothing

kd 12 shoes said: I precisely desired to thank you so much again. I am not sure what I would've tried in the absence of the entire tips provided by you regarding such a field. Certainly was a real terrifying circumstance in my opinion, but understanding a expert style you resolved the issue made me to leap over gladness. I will be happy for your support as well as hope that you recognize what a powerful job that you are providing teaching the mediocre ones with the aid of your webpage. Most probably you've never got to know any of us. kd 12 shoes

yeezy boost 380 said: Thanks a lot for providing individuals with remarkably pleasant opportunity to read in detail from this site. It really is so enjoyable and as well , full of a great time for me personally and my office co-workers to search the blog minimum thrice weekly to learn the fresh guides you have got. And of course, I'm also certainly motivated with all the gorgeous hints you serve. Some 2 ideas in this article are in truth the best we've ever had. yeezy boost 380

supreme clothing said: I wish to show thanks to you for bailing me out of such a dilemma. Right after searching throughout the world-wide-web and coming across advice that were not powerful, I assumed my entire life was done. Existing without the presence of answers to the difficulties you have sorted out by way of your site is a critical case, and the ones that could have in a negative way damaged my career if I hadn't encountered your blog post. That expertise and kindness in controlling all the details was tremendous. I don't know what I would've done if I hadn't encountered such a point like this. I can at this moment relish my future. Thanks for your time very much for your impressive and result oriented help. I won't be reluctant to recommend your web sites to anybody who desires care on this problem. supreme clothing

supreme sweatshirt said: I and also my buddies have already been studying the nice tactics located on your site and so quickly got a terrible suspicion I never thanked the web site owner for those secrets. The boys came as a result warmed to see them and now have in reality been tapping into them. Many thanks for being quite helpful and for using variety of exceptional information millions of individuals are really eager to be aware of. Our own honest regret for not expressing gratitude to you sooner. supreme sweatshirt

air jordan said: I wish to express my thanks to you just for bailing me out of this type of problem. Because of surfing throughout the search engines and seeing tricks which are not powerful, I believed my life was gone. Existing minus the answers to the problems you've fixed through your good post is a serious case, as well as those which might have in a negative way damaged my career if I had not encountered your web site. Your actual capability and kindness in touching the whole thing was useful. I'm not sure what I would've done if I hadn't discovered such a solution like this. I can at this moment look ahead to my future. Thanks very much for the high quality and sensible help. I will not be reluctant to endorse your web sites to any individual who desires guide on this area. air jordan

golden goose sneakers said: I want to express appreciation to the writer for rescuing me from this particular predicament. Just after looking out throughout the world-wide-web and getting ways that were not helpful, I was thinking my life was well over. Being alive without the presence of strategies to the problems you've fixed all through your main article content is a serious case, and the kind which may have in a wrong way damaged my career if I had not discovered your web blog. Your actual ability and kindness in touching every part was important. I am not sure what I would have done if I had not discovered such a thing like this. I am able to at this moment relish my future. Thanks a lot so much for the specialized and amazing guide. I will not think twice to endorse your web blog to anybody who should have support on this situation. golden goose sneakers

giannis antetokounmpo shoes said: I intended to send you this little bit of observation to thank you over again on your magnificent secrets you have contributed on this site. It is seriously generous of people like you to provide extensively all a number of people could have offered as an ebook in making some cash for themselves, and in particular now that you could have done it if you ever considered necessary. The tactics in addition served like a great way to comprehend the rest have similar desire similar to my own to understand a good deal more with regards to this problem. I am sure there are many more fun sessions in the future for those who find out your website. giannis antetokounmpo shoes

kevin durant shoes said: I together with my guys have already been viewing the great thoughts on your web blog then unexpectedly came up with an awful suspicion I never thanked you for those tips. Those young men had been so very interested to learn them and have seriously been enjoying those things. Many thanks for being quite kind and then for making a decision on variety of magnificent subject matter most people are really eager to understand about. My very own sincere regret for not expressing appreciation to you sooner. kevin durant shoes

bape said: Thanks for all of your work on this blog. My niece takes pleasure in making time for investigations and it's really easy to understand why. My partner and i hear all about the compelling means you create efficient guidance via your web site and as well as cause response from other individuals on that idea so our princess is truly discovering so much. Take advantage of the rest of the year. You are conducting a terrific job. bape

longchamp bags said: I simply wished to thank you so much once more. I'm not certain the things that I would have sorted out in the absence of these information discussed by you relating to that area. This has been a scary crisis for me, but discovering your expert strategy you resolved it took me to weep with gladness. I will be thankful for this service and even hope that you recognize what a powerful job that you are accomplishing training men and women via your website. I am sure you have never met any of us. longchamp bags

stone island said: I wanted to put you the little remark in order to thank you so much the moment again over the splendid ideas you have documented here. It was simply pretty open-handed with people like you to supply openly what a number of us would have supplied as an electronic book to help with making some bucks on their own, most notably given that you could possibly have done it in case you wanted. These points additionally worked to provide a great way to comprehend someone else have the same interest similar to my own to understand a great deal more when considering this issue. I know there are thousands of more pleasant times ahead for people who looked at your blog post. stone island
Back