Haskell record syntax

Well if no one else is going to try, then I’ll take another (slightly more carefully researched) stab at answering these questions. tl;dr Question 1: That’s just the way the dice rolled. It was a circumstantial choice and it stuck. Question 2: Yes (sorta). Several different parties have certainly been thinking about the issue. Read … Read more

What is the best or most interesting use of Extension Methods you’ve seen? [closed]

This is one that’s been getting some play from me lately: public static IDisposable Tag(this HtmlHelper html, string tagName) { if (html == null) throw new ArgumentNullException(“html”); Action<string> a = tag => html.Write(String.Format(tag, tagName)); a(“<{0}>”); return new Memento(() => a(“</{0}>”)); } Used like: using (Html.Tag(“ul”)) { this.Model.ForEach(item => using(Html.Tag(“li”)) Html.Write(item)); using(Html.Tag(“li”)) Html.Write(“new”); } Memento is … Read more

Python decorator best practice, using a class vs a function

It is rather subjective to say whether there are “advantages” to each method. However, a good understanding of what goes under the hood would make it natural for one to pick the best choice for each occasion. A decorator (talking about function decorators), is simply a callable object that takes a function as its input … Read more

What is the purpose of “!” and “?” at the end of method names?

It’s “just sugarcoating” for readability, but they do have common meanings: Methods ending in ! perform some permanent or potentially dangerous change; for example: Enumerable#sort returns a sorted version of the object while Enumerable#sort! sorts it in place. In Rails, ActiveRecord::Base#save returns false if saving failed, while ActiveRecord::Base#save! raises an exception. Kernel::exit causes a script … Read more

Is there a literal notation for an array of symbols?

Yes! This is possible now in Ruby 2.0.0. One way to write it is: %i{foo bar} # => [:foo, :bar] You can also use other delimiters, so you could also write %i(foo bar) or %i!foo bar! for example. This feature was originally announced here: http://www.ruby-lang.org/zh_TW/news/2012/11/02/ruby-2-0-0-preview1-released/ It is mentioned in the official documentation of Ruby here: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)