coding-style

Complete set of Indentation rules in haskell

孤街浪徒 提交于 2019-12-12 12:15:27
问题 From where can I get complete set of Indentation rules for Haskell code writing? Past SO questions which are similar to my following question has led me to ask above question. What are the reasons behind the error message: parse error on input 'something' ? Error message I got: baby.hs:103:2: parse error on input `myList'(error in this line) Code I am trying to compile: myList = ["aeroplane", "Aeroplane", "AeRoPlAne", "helicopter", "HELICOPTER", "Zebra"] quicksort :: (Ord a) => [a] -> [a]

Auto Boxing vs static numbers

我怕爱的太早我们不能终老 提交于 2019-12-12 12:14:05
问题 Is it valuable for using Integer i = NumberUtils.INTEGER_ONE instead of Integer i = 1 ? I don't know what happen behind auto boxing. Thanks 回答1: Basically it will be compiled into: Integer i = Integer.valueOf(NumberUtils.INTEGER_ONE); assuming INTEGER_ONE is declared as an int . At execution time, assuming INTEGER_ONE has the value 1, that will actually return a reference to the same object each time, guaranteed by the Java Language Specification, because it's in the range -128 to 127. Values

How do you deal with new features of C# so that they don't lead to poorly written code?

我们两清 提交于 2019-12-12 10:59:44
问题 A number of features were introduced into C# 3.0 which made me uneasy, such as object initializers, extension methods and implicitly typed variables. Now in C# 4.0 with things like the dynamic keyword I'm getting even more concerned. I know that each of these features CAN be used in appropriate ways BUT in my view they make it easier for developers to make bad coding decisions and therefore write worse code. It seems to me that Microsoft are trying to win market share by making the coding

Is Resharper correct?

自古美人都是妖i 提交于 2019-12-12 10:53:06
问题 I just installed Reshaper 4.5 and it has come up with the following suggestions: return this.GetRuleViolations().Count() == 0; -- REMOVE this. new string[] { this.ID.ToString(), this.Registration } -- REMOVE string, MAKE ANONYMOUS TYPE int i = Method.GetNumber(); -- REPLACE int WITH var Should I do these? I think in some cases it is going to make the code less readable but will it improve performance? what are the benefits of making these changes? Thanks 回答1: 1) The explicit this pointer is

What is the preferred way to check for a Null pointer in C++?

一个人想着一个人 提交于 2019-12-12 09:53:37
问题 Options A: if (NULL == pSomethingColumn) // Yes, we use Yoda conditions if (NULL != pSomethingColumn) Or if (pSomethingColumn) if (!pSomethingColumn) I am looking for references explaining the reasoning as well. I have heard some people say that technically NULL does not have to be defined as 0 , but come on! if that was the case, then the sucker (our app) would crash in -2147483648 different ways. So, if NULL != 0 , then we will have big problems. Please help me settle a pointless syntax

shorthand typedef pointer to a constant struct

谁说胖子不能爱 提交于 2019-12-12 09:49:33
问题 Declaring a struct with typedef typedef struct some_struct { int someValue; } *pSomeStruct; and then passing it as a parameter to some function with const declaration, implying 'const some_struct * var' void someFunction1( const pSomeStruct var ) turns out to become some_struct * const var This is also stated in Section 6.7.5.1 of the ISO C standard which states that 'const' in this case applies to the pointer and not to the data to which it points. So the question is - is there a way to

Is dollar operator ($) considered bad form? Why?

佐手、 提交于 2019-12-12 09:33:57
问题 In Haskell, I often write expressions with $'s. I find it quite natural and readable, but I sometimes read it is bad form and do not understand why it should be. 回答1: The following are all good form: foo = bar . baz . quux foo x = bar . baz . quux $ x foo x = (bar . baz . quux) x foo x = bar (baz (quux x)) I've put them in rough order of my preference, though as always taste varies, and context may demand a different choice. I've also occasionally seen foo = bar . baz . quux when each of the

Too many imports spamming my code

故事扮演 提交于 2019-12-12 08:22:48
问题 In my project I have a shapes package which has shapes I designed for my graphics program e.g Rectangle, Circle. I also have one or two more packages that have the same names as java.awt classes. Now, since I do not want to rename every class in my code-base, to show my source files which class I mean when I , say, declare a new Rectangle, I need to either: 1- import the rectangle class explicitly, i.e import shapes.Rectangle OR 2- import only the java.awt classes I need and not import java

Get all elements in array besides the first one.. ? (php)

三世轮回 提交于 2019-12-12 08:19:02
问题 Is there a way to specify getting all but the first element in an array? I generally use foreach() to loop through my arrays. say array(1,2,3,4,5), i would only want 2, 3, 4 ,5 to show and for it to skip 1. 回答1: There are multiple ways of approaching this problem. The first solution is to use a flag boolean to indicate the first element and proceed in your foreach $firstElement = true; foreach($array as $key => $val) { if($firstElement) { $firstElement = false; } else { echo "$key => $val\n";

Why are some functions declared extern and header file not included in source in Git source code?

本小妞迷上赌 提交于 2019-12-12 07:55:04
问题 I wanted to see the source code of a real world application to understand good programming practices etc. So I chose Git and downloaded the source for version 1.8.4. After randomly browsing through various files something caught my attention in these two files: strbuf.h strbuf.c These two files apparently define an API with this documentation. I have two questions : Why the function declarations at line 16,17,18,19 & global variable at line 6 in 'strbuf.h' declared extern ? Why "strbuf.h" is