coding-style

Abuse of match?

假如想象 提交于 2019-12-03 15:30:48
Would you consider the following block of code match abuse and if so what's a more elegant way to do it without a big if-else-if block? def sum(base: Int, xs: List[Int]): Int = { base match { case 0 => 1 case _ if (base < 0) => 0 case _ if (xs.isEmpty) => 0 case _ => xs.sum } } Yes, this an abuse of match. You've basically just written a big if-else-if block, but in a more awkward form. What's wrong with if-statements? I think it's much cleaner to just write this: def countChange(money: Int, coins: List[Int]): Int = { if(money == 0) 1 else if (money < 0) 0 else if (coins.isEmpty) 0 else

Unnecessary 'else' statement [duplicate]

北城余情 提交于 2019-12-03 14:58:52
问题 This question already has answers here : Should a function have only one return statement? (50 answers) Closed last year . As you know, in Eclipse you can turn on " Unnecessary 'else' statement " check that will trigger on if-then-else with premature return. And, from my experience, there are two most possible situations when use such statement: 1) Pre-check: if (!validate(arg1)) { return false; } doLotOfStuff(); 2) Post-check: doLotOfStuff(); if (condition) { return foo; } else { return bar;

Still lost on Repositories and Decoupling, ASP.NET MVC

∥☆過路亽.° 提交于 2019-12-03 14:34:31
I'm still on my eternal quest to build (and understand) modern programming convention of decoupling, IoC, DI, etc. I'm to the part where I am trying to figure out how to build a repository. I've examined the post at Database abstraction layer design - Using IRepository the right way? which was very helpful, but I've still got some problems that are just befuddling me all the way. I have my program in now 4 layers... Web (Project | ASP.NET MVC Application) - References Models.dll and Persistence.dll Models (Domain Objects) Persistence (Fluent nHibernate Mapping of Domain Objects) Utilities

Using default font styles in Android

拥有回忆 提交于 2019-12-03 14:32:20
How do you use the Android default font sizes in xml? I tried: android:textAppearance="@android:style/TextAppearance_Large" But I get: error: Error: No resource found that matches the given name (at 'textAppearance' with value '@android:style/TextAppearance_Large'). Isn't it android:textAppearance="?android:attr/textAppearanceLarge" for a TextView? 来源: https://stackoverflow.com/questions/3405161/using-default-font-styles-in-android

Declaring a looooong single line string in C#

那年仲夏 提交于 2019-12-03 14:28:11
问题 Is there a decent way to declare a long single line string in C#, such that it isn't impossible to declare and/or view the string in an editor? The options I'm aware of are: 1: Let it run. This is bad because because your string trails way off to the right of the screen, making a developer reading the message have to annoying scroll and read. string s = "this is my really long string. this is my really long string. this is my really long string. this is my really long string. this is my

Ensure coding-style during a git commit [closed]

ぃ、小莉子 提交于 2019-12-03 14:26:21
Closed. This question is off-topic. It is not currently accepting answers. Learn more . Want to improve this question? Update the question so it's on-topic for Stack Overflow. Im my company i set-up a continuous integration test and i run the tests when someone push the code on the server. Now i want to check that the code match with the our basic coding rules, the first rule is "run mogrify on your code!" There is something to do this check "out the shelf"? the output of this analisys can be stored on a file or something else. thanks I would suggest using a lint like tool, e.g. for ObjectC

Where to put inner classes? [closed]

♀尐吖头ヾ 提交于 2019-12-03 14:25:32
问题 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 8 years ago . Some might like to argue that this is a candidate for the least important issue of all times. Yet code style is a very important topic

How to code in professional manner? [closed]

瘦欲@ 提交于 2019-12-03 14:14:57
问题 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 7 years ago . I was wondering, how a program can be written in a perfect professional style. Many times it happens that we write a very good program

Why use infinite loops?

落花浮王杯 提交于 2019-12-03 13:52:13
Another poster asked about preferred syntax for infinite loops . A follow-up question: Why do you use infinite loops in your code? I typically see a construct like this: for (;;) { int scoped_variable = getSomeValue(); if (scoped_variable == some_value) { break; } } Which lets you get around not being able to see the value of scoped_variable in the for or while clause. What are some other uses for "infinite" loops? A loop like: while (true) { // do something if (something else) break; // do more } lets you break out of the loop in the middle, rather than at the start (while/for) or end (do

Using AStyle in Vim

妖精的绣舞 提交于 2019-12-03 13:25:25
I am trying to get AStyle working with Vim so that I can use the "=" key to re-indent various sections of code. For example, I'd like to be able to type my usual =iB to indent the current block of code using AStyle rather than the built in indenter. I tried just setting equalprg=astyle in my vimrc, but the problem is that astyle only receives the selected block but thinks that it's receiving a whole file. Therefore, the indentation is completely off when I try to only indent a nested class. I know that I can always reformat an entire file at once, but is there a way to use astyle in vim which