maintainability

Cruft code. IoC to the rescue

不羁的心 提交于 2019-12-02 17:12:50
In question about usefulness of IoC Container, the winning submitter mentioned that with an IoC container you can take this: public class UglyCustomer : INotifyPropertyChanged { private string _firstName; public string FirstName { get { return _firstName; } set { string oldValue = _firstName; _firstName = value; if(oldValue != value) OnPropertyChanged("FirstName"); } } private string _lastName; public string LastName { get { return _lastName; } set { string oldValue = value; _lastName = value; if(oldValue != value) OnPropertyChanged("LastName"); } } } to this: var bindingFriendlyInstance = IoC

Design of an Alternative (Fluent?) Interface for Regular Expressions

狂风中的少年 提交于 2019-12-02 16:17:13
I've just seen a huge regex for Java that made me think a little about maintainability of regular expressions in general. I believe that most people - except some badass perl mongers - would agree that regular expressions are hardly maintainable. I was thinking about how this situation could be fixed. So far, the most promising idea I have is using a fluent interface . To give an example, instead of: Pattern pattern = Pattern.compile("a*|b{2,5}"); one could write something like this import static util.PatternBuilder.* Pattern pattern = string("a").anyTimes().or().string("b").times(2,5).compile

managing document.ready event(s) on a large-scale website

北慕城南 提交于 2019-12-02 15:11:05
NOTE: I have now created a jQuery plugin which is my attempt of a solution to this issue. I am sure that it could be improved and i've probably overlooked lots of use cases, so if anyone wants to give feedback feel free :-) https://github.com/WickyNilliams/ReadyBinder I don't have a problem as such, but thought this would be an interesting point for discussion, and i hope people have some interesting ideas for this. Basically, i work on a large-scale website and increasingly we are writing more and more JavaScript. This is fine, i enjoy JS' unique approach and i find the quirkiness in some of

Code Metrics Calculation in Visual Studio

主宰稳场 提交于 2019-12-02 14:52:10
What is the prefered score range for the code metrics calculation for the following Maintainability Index Cyclomatic Complexity Depth of Inheritance class Coupling The theoretically optimal values are: Maintainability index: 100. Higher values indicate better maintainability. Cyclomatic complexity: 1. The number of different paths that code can take. Depth of inheritance: 1. The number of class definitions above this one in the inheritance tree, not including interfaces. Class coupling: 0. Number of other entities this entity is dependent on. There are no hard and fast "good" ranges, though it

Python loops vs comprehension lists vs map for side effects (i.e. not using return values)

耗尽温柔 提交于 2019-12-01 10:27:23
TL;DR Which is the best? 1.- [r.update(r.pop('some_key')) for r in res if r.get('some_key')] 2.- map(lambda r: r.update(r.pop('some_key') if r.get('some_key') else []), res) 3.- map(lambda r: r.update(r.pop('some_key')), filter(lambda r: r.get('some_key'), res)) 4.- for r in res: if r.get('some_key'): for element in r['some_key']: r[element] = r['some_key'][element] del r['some_key'] 5.- Insert your own approach here Note : This is not production code. It is code that is run in a test suite, so I am more concerned about legibility/maintainability than performance. Nevertheless I would also

Python loops vs comprehension lists vs map for side effects (i.e. not using return values)

匆匆过客 提交于 2019-12-01 08:57:37
问题 TL;DR Which is the best? 1.- [r.update(r.pop('some_key')) for r in res if r.get('some_key')] 2.- map(lambda r: r.update(r.pop('some_key') if r.get('some_key') else []), res) 3.- map(lambda r: r.update(r.pop('some_key')), filter(lambda r: r.get('some_key'), res)) 4.- for r in res: if r.get('some_key'): for element in r['some_key']: r[element] = r['some_key'][element] del r['some_key'] 5.- Insert your own approach here Note : This is not production code. It is code that is run in a test suite,

Database normalization design - single or multiple tables

倾然丶 夕夏残阳落幕 提交于 2019-12-01 08:48:21
Should this be represented in the database as 1 table or 3 tables? I and my friend have different opinions about this so I'd like to see the general views on this. (Maybe it should be a vote for either solution?) Create Table Order // Basic fields of the table - ID (Primary key) - CustomerID (integer, with a FK) - Quantity - ProductID (integer, with a FK) // Then depending on user selection, either these fields need to be specified // (could be factored out to a separate table): { - InternalAccountID (integer, with a FK) - InternalCompanyID (integer, with a FK) } // Or these (could be factored

Database normalization design - single or multiple tables

痞子三分冷 提交于 2019-12-01 06:03:51
问题 Should this be represented in the database as 1 table or 3 tables? I and my friend have different opinions about this so I'd like to see the general views on this. (Maybe it should be a vote for either solution?) Create Table Order // Basic fields of the table - ID (Primary key) - CustomerID (integer, with a FK) - Quantity - ProductID (integer, with a FK) // Then depending on user selection, either these fields need to be specified // (could be factored out to a separate table): { -

Is there any appreciable difference between if and if-else?

断了今生、忘了曾经 提交于 2019-12-01 01:40:14
问题 Given the following code snippets, is there any appreciable difference? public boolean foo(int input) { if(input > 10) { doStuff(); return true; } if(input == 0) { doOtherStuff(); return true; } return false; } vs. public boolean foo(int input) { if(input > 10) { doStuff(); return true; } else if(input == 0) { doOtherStuff(); return true; } else { return false; } } Or would the single exit principle be better here with this piece of code... public boolean foo(int input) { boolean toBeReturned

Using Named Immediately-Invoked Function Expression (IIFE) instead of comments

你说的曾经没有我的故事 提交于 2019-11-30 12:06:50
What are the pros and cons of utilizing Named IIFEs within JS code to describe and group related code? I've been using this "pattern" to lend structure to my more procedural code that gets executed only in one place. Example (function hideStuffOnInstantiaton(){ $('oneThing').hide().removeClass(); $('#somethign_else').slideUp(); $('.foo').fadeOut(); }()); I find this preferable to both: // hide Stuff on Instantiaton $('oneThing').hide().removeClass(); $('#somethign_else').slideUp(); $('.foo').fadeOut(); since over time the comment may get separated from the code and its not immediately obvious