coding-style

Why does .NET's StringValidator's Validate method throws an exception when it doesn't succeed?

安稳与你 提交于 2019-12-10 11:27:50
问题 As you can see in the MSDN StringValidator documentation, the Validate method returns void . If validation doesn't succeed the Validate method throws ArgumentException . I thought that "You only throw an exception when something exceptional happens". Surely a validator that failed to validate isn't exceptional.. Why not return bool? What am I missing here? Is this a "style issue" (i.e. if it was returning bool, it would still be correct, but just different style)? Note: Method CanValidate may

php OOP Exceptions or die()?

岁酱吖の 提交于 2019-12-10 10:47:10
问题 I am developing some project. And I want to control different errors. I know that in all popular frameworks and php projects there are different Exceptions. But I think that is not required work. If the error is occured we can make die() with our message. 1. What are the main pluses of Exceptions? 2. Can I control my errors with die()? Thank you. 回答1: Well, you could use die() . But that makes all errors fatal. Meaning that you cannot try to recover from the error at all. In some cases that's

Thoughts on variable/function naming conventions

巧了我就是萌 提交于 2019-12-10 10:28:25
问题 I've been coding on and off my whole life. I've mostly coded Perl, but also some Java, PHP, C, C++. I've even took a stab at Emacs Lisp, and I've done the occasional shell script. However, I've never actually engaged the subject to gain any kind of expertise – other things have had higher priorities for me. I don't consider myself to be really proficient in any language but Perl, and also now Haskell which I'm taking a course in right now. Lately, I've been thinking about my style of coding.

Try/Catch Use Convention(s)

≯℡__Kan透↙ 提交于 2019-12-10 09:28:13
问题 What is the convention for Try/Catch outside of obviously needed locations(such as getting specific user input)? While code re-use is an important idea behind OOP, is it expected that each (example) array access should have a try/catch? Is it primarily the designer's decision of what can throw an exception, and those parts of the program that should be well regulated enough to never throw an exception? Ex. An array of playing cards is, and should always be, 52 cards. No try/catch is necessary

Long parameter list in constructor in Java [duplicate]

亡梦爱人 提交于 2019-12-10 05:24:16
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: What's the best way to refactor a method that has too many (6+) parameters? If a constructor has a long parameter list, should we consider it bad style and refactor it? If yes, how? 回答1: It may be an appropriate set of parameters, but a lot of the time my answer would be yes. Break the parameters into a logical subgroupings if they exist i.e. rather than creating a Car from many different parts, group some parts

Issue with applying style on WPF UserControl

时光毁灭记忆、已成空白 提交于 2019-12-10 05:12:35
问题 I have a user-control and I want to use it in some other project. There is no problem when I set some value to its properties directly: <local:MyUserControl prop1="val1" prop2="val2"> ... </local:MyUserControl> But I can't apply a style to it. I tried: <Window ...> <Window.Resources> <Style x:Key="MyUserControlStyle" TargetType="{x:Type local:MyUserControl}"> <Setter Property="prop1" Value="val1"/> <Setter Property="prop2" Value="val2"/> </Style> </Window.Resources> <Grid> <local

Thoughts on try-catch blocks

梦想与她 提交于 2019-12-10 04:47:16
问题 What are your thoughts on code that looks like this: public void doSomething() { try { // actual code goes here } catch (Exception ex) { throw; } } The problem I see is the actual error is not handled, just throwing the exception in a different place. I find it more difficult to debug because i don't get a line number where the actual problem is. So my question is why would this be good? ---- EDIT ---- From the answers it looks like most people are saying it's pointless to do this with no

String.Format or Not? [duplicate]

我只是一个虾纸丫 提交于 2019-12-10 04:35:48
问题 This question already has answers here : Closed 11 years ago . Duplicate from : String output: format or concat in C#? Especially in C# world using String.Format for everything is really common, normally as VB.NET developer unless I have to* I don't String.Format, I prefer normal string concatenation, such as: V1 = V2 & "test-x" & V3 & "-;" to me it's better than this: V1 = String.Format("{0} test-x {1} -;", V2, V3) Am I missing something? Or is this just a personal preference? Reasons to Use

Generate Coding guidelines from CheckStyle

南笙酒味 提交于 2019-12-10 04:26:48
问题 Is there a way to generate a 'nice' Coding conventions / guidelines document from existing CheckStyle configuration file? This document must contain the description of the rules enforced, and the configuration values (like the max line length, violation severity, etc). The benefit of having such a document is to ramp up a new team member faster, without reading CheckStyle configuration file. 回答1: I would generally advise against generating even parts of a coding guidelines document, because

Checkstyle rule to prevent invocation of some methods and constructors

Deadly 提交于 2019-12-10 04:24:50
问题 Is it possible to use Checkstyle to forbid usage of some constructors or method that use system-dependent defaults (locale, charset, etc..). I prefer to enforce a policy where the programmer should be explicit about system-dependent values. So I consider the following items to be dangerous: all the constructors of java.io.FielWriter using system-dependent encoding the OutputStreamWriter(OutputStream os) constructor of java.io.OutputStreamWriter using system-dependent encoding the java.lang