coding-style

Why is programming to abstract classes instead of interfaces wrong? [closed]

不羁的心 提交于 2019-12-10 23:49:07
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 months ago . I am going through the differences between Struts1 and Strust2 , i found out that , A common problem in Struts 1 is programming to abstract classes instead of interfaces. Could anybody please let me know , Why is programming to abstract classes instead of interfaces is a problem

Are there any plugins for Visual Studio which automatically formats code how I like?

☆樱花仙子☆ 提交于 2019-12-10 23:36:24
问题 When I open any code file, whether something i've written or something from another developer, I want it to automatically format it with my preference of bracing, indentation, line spacing, etc.. Ideally, when saving a file to disk, it would only save the formatting for code/lines i've touched. It would still display the rest of the code formatted, however it would not save these to disk (so as to not piss off other developers). 回答1: You could use Resharper for this. It will show warnings for

Why prefer var strList = new List<string>(); over List<string> strList = new List<string>();? [closed]

旧巷老猫 提交于 2019-12-10 22:24:59
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . Why when creating object it is preferred to use var keyword than real type? var strList = new List<string>(); //good? List<string>

Showing and Hiding of Objects in JQuery

不羁岁月 提交于 2019-12-10 21:46:39
问题 I would like to show and hide the objects (divs, texts or btns) according to some conditions. In C#, we can write like the following to reduce amount of codings: txtA.visible = (type == "A"); txtB.visible = (type == "B"); txtC.visible = (type == "C"); In JQuery, to show and hide, I use .show() and .hide() methods. But, I have to write many lines for that simple feature. For eg: if (type == "A") $("#txtA").show(); else $("#txtA").hide(); if (type == "B") $("#txtB").show(); else $("#txtB").hide

Understanding different styles of #defines in c

自闭症网瘾萝莉.ら 提交于 2019-12-10 21:33:08
问题 I was looking at different source codes in C programming language and found different styles of #define's used. I know technically their use case and irrespective of their style they will work as expected but from coding guidelines, I would like to ask what do they mean and when to use a particular one. #define MY_DEFINE_H #define MY_DEFINE_H_ #define MY_DEFINE_H__ #define __MY_DEFINE_H__ Also if possible please share some reference so that I can go through detailed in it. 回答1: Note that you

Using single characters for variable names in loops/exceptions

£可爱£侵袭症+ 提交于 2019-12-10 21:33:00
问题 I've had a couple of discussions with a co-worker about the use of single letter variable names in certain circumstances inside our codebase, at which we both disagree. He favours more verbose naming convention for these, and I do not. There are three scenarios in my opinion where I use single letter variable names: Loops - i for(int i = 0; i < 10; i++) { ... } Lambda expressions in C# - x/y/z : .Where(x => x == 5) Exceptions - e : try { ... } catch(ExceptionType e) { /* usage of 'e' */ }

Strange Java Coding Style - Why?

本小妞迷上赌 提交于 2019-12-10 21:28:13
问题 I've just came across some code which is slightly strange, I was wondering if anyone could shed light on why it might be written like this. I think it's got something to do with concurrency - so that the variables can't get changed if another thread accesses it (because variable updates aren't atomic). Or it's speed (because local variables are faster than class level variables?) OR I'm wrong on everything I've written here :) Oh, I'm not talking about the Hungarian notation, I'm talking

Class's operator() or bind a function as a functor?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 21:26:24
问题 There are two ways to make a functor (a function that holds a state): bind a function and define a state: bind(f, _1, state) double g(double x, double state) { return x+state; } function f = bind(g,_1,state); use () operator and a class: struct f { double state; f(double state_):state(state_) {} double operator()(double x) {return x+state;} }; I find that bind -method is faster to write but I'm wondering if there are some hidden stones since most of the time in literature I see functor as

Defining const pointer to a const string

二次信任 提交于 2019-12-10 20:04:16
问题 Readed bog of Ulrich Drepper and come across 2 entries that looks like conficting. In the first one (string in global space) Ulrich states that the string should be defines as: const char _pcre_ucp_names[] = "blabla"; while already in second one (string in function) he argues it should be declared as: static const char _pcre_ucp_names[] = "blabla"; Can you explain what is the better name to declate a string? UDP: First of all I removed C++ tag - this question is valid for C as well for C++.

detect 4 permutations of 2 variable values in a switch case statement

折月煮酒 提交于 2019-12-10 19:59:21
问题 I have 2 variables, width and height as integers. Any of these can be positive or negative (not zero). So naturally there are 4 cases; width > 0 && height > 0 width > 0 && height < 0 width < 0 && height > 0 width < 0 && height < 0 Now I want to take different action on each of these 4 cases without using 4 if statements. Is there a way to aggregate these cases so that it can be put as a simple switch case switch( aggregate ){ case 1: case 2: case 3: case 4: } If there is no better way than