dry

Is there any advantage on separating iPhone and iPad classes on a Universal app?

雨燕双飞 提交于 2019-12-10 14:12:11
问题 I have a Universal (for both iPhone and iPad) application. Are there any advantages on separating the iPad from the iPhone classes in the folder structure? Here is an example of what I mean: - MyApp - Resources - Classes - iPad - SomeUniqueClassOnIPad.h - SomeUniqueClassOnIPad.m - iPhone - SomeUniqueClassOnIPhone.h - SomeUniqueClassOnIPhone.m - SomeUniversalClass.h - SomeUniversalClass.m Is that common in objective-c projects? 回答1: One of the rules within coding is never to have duplicate

How can I define the size of the drawables in the style file?

早过忘川 提交于 2019-12-10 13:42:59
问题 I would like to specify just once in res/values/styles.xml the size of two checkboxes and their four shape drawables res/drawable/cb1_checked.xml res/drawable/cb1_unchecked.xml res/drawable/cb2_checked.xml res/drawable/cb2_unchecked.xml . This way the size would appear one time in the style rather than four in the drawables. Neither of the two attempts below work. Can you suggest a solution? (If you see what's wrong with these two attempts, please do mention it.) -----------------------------

DRY IDisposable Pattern

余生颓废 提交于 2019-12-10 10:06:34
问题 A lot of my classes repeat the below code to implement IDisposable. This seems to violate the DRY (Don't Repeat Yourself) principle. I could avoid some of the work by creating an AbstractDisposable base class, but that seems inappropriate / wouldn't work if I needed to extend other existing objects (assuming those objects weren't themselves disposable). Another option would be to use a template/meta language where I could specify lists of managed and unmanaged resources for each class and

ASP.NET MVC 2 - When To Use Templates vs When to Use Partial Views

旧时模样 提交于 2019-12-10 04:04:41
问题 One of the new features in ASP.NET MVC 2 Preview 1 is support for the concept of Editor Templates and Display Templates which allow you to pre-define how a given object will be rendered for display or editing with a simple HTML helper call: <%=Html.EditorFor(customer => customer) %> <%=Html.DisplayFor(customer => customer) %> This is pretty cool, but I don't really see the difference between this and a Partial View that serves the same purpose. Furthermore, in the examples I saw the Editor

Removing code duplication from const and non-const methods that return iterators

点点圈 提交于 2019-12-10 02:25:19
问题 I'm considering this question on const and non-const class methods. The preferred answer is taken from Effective C++ by Scott Meyers, where the non-const method is implemented in terms of the const method. Extending this further, how can code duplication be reduced if the methods return iterators instead of references? Modifying the example in the linked question: class X { std::vector<Z> vecZ; public: std::vector<Z>::iterator Z(size_t index) { // ... } std::vector<Z>::const_iterator Z(size_t

How to generate a non-const method from a const method?

岁酱吖の 提交于 2019-12-09 05:30:06
问题 While striving for const-correctness, I often find myself writing code such as this class Bar; class Foo { public: const Bar* bar() const { /* code that gets a Bar somewhere */ } Bar* bar() { return const_cast< Bar* >( static_cast< const Foo* >(this)->bar()); } }; for lots of methods like bar() . Writing these non-const methods which call the const ones by hand is tedious; besides, I feel I am repeating myself – which makes me feel bad. What can I do to alleviate this task? (Macros and code

Best Practices for using partials in Rails

筅森魡賤 提交于 2019-12-09 05:23:02
问题 In keeping with the DRY-principle I try to use partials as soon as I am repeating a particular pattern more than once or twice. As a result, some of my views consist of ten or more different partials. I am worried that this might have a negative effect on the overall performance. Some programming books compare the use of partials with the use of methods. So should I use the same rationale to determine when to use them? What is the best practice regarding size and quantity of partials in a

How to avoid repetition of .then() and .catch() after $http requests?

南笙酒味 提交于 2019-12-08 19:42:35
I have a simple userAPI service in my angular app: app.service('userAPI', function ($http) { this.create = function (user) { return $http .post("/api/user", { data: user }) .then(function (promise) { return promise.data }) .catch(function (error) { return error.data }) } this.read = function (user) { return $http .get("/api/user/" + user.id) .then(function (promise) { return promise.data }) .catch(function (error) { return error.data }) } this.update = function (user) { return $http .patch("/api/user/" + user.id, { data: user }) .then(function (promise) { return promise.data }) .catch(function

How to avoid repetition of .then() and .catch() after $http requests?

China☆狼群 提交于 2019-12-08 04:03:35
问题 I have a simple userAPI service in my angular app: app.service('userAPI', function ($http) { this.create = function (user) { return $http .post("/api/user", { data: user }) .then(function (promise) { return promise.data }) .catch(function (error) { return error.data }) } this.read = function (user) { return $http .get("/api/user/" + user.id) .then(function (promise) { return promise.data }) .catch(function (error) { return error.data }) } this.update = function (user) { return $http .patch("

How to minify my repeating text equals and replacewith code

穿精又带淫゛_ 提交于 2019-12-08 02:32:35
问题 How do I minify my jQuery code as it's very repetitive and I'm sure doesn't need to be so long. The code does exactly what I need it to do, I just need to minify to keep it looking clean and use less lines of code. Any guidance is greatly appreciated and helps with my learning. I came up with this code to answer my previous question. So I am learning thanks to the people on this site. I just need a little nudge in the right direction now and then. :-) $('#hidden-shoe-sizes').contents()