Menu
  • HOME
  • TAGS

F# wrapping statements in a do block

f#,functional-programming,conventions,statements

Since it's not really "natural" to work with statements in functional programming, we explicitly wrap the statements in a do block to show that they are side-effects. I agree with you. However, if you look into F# code in the wild, they tend to be loose in that matter....

Connect Rails Application To Existing Database

ruby-on-rails,database,conventions

You don't need to run migrations to have the model. Either skip them (--no-migration) or remove the file after generating. As for table names, look at table_name=. primary_key= may also be handy. class Form << ActiveRecord::Base self.table_name = 'form' end http://api.rubyonrails.org/classes/ActiveRecord/ModelSchema/ClassMethods.html#method-i-table_name-3D http://api.rubyonrails.org/classes/ActiveRecord/AttributeMethods/PrimaryKey/ClassMethods.html#method-i-primary_key-3D ...

Using multiple memory allocation functions in the same program

c,memory-management,malloc,conventions,guidelines

Yes. Generally it depends on what is needed. malloc() can be used when a block of un-initialized memory is needed. (malloc is slightly faster than calloc). calloc() can be used when a block of 'zeroed-out' memory is needed. (calloc() is similar to malloc() + memset()) strdup() allocates a copy of...

How do web browsers find a source map for a JavaScript file?

javascript,jquery,html,conventions,map-files

The reasoning behind dropping source mapping from recent versions is described on the JQuery blog This release does not contain the sourcemap comment in the minified file. Sourcemaps have proven to be a very problematic and puzzling thing to developers, spawning hundreds of confused developers on forums like StackOverflow and...

What is the naming convention for CMake scripts?

cmake,naming-conventions,filenames,conventions,convention

There's a convention for CMake modules: snake-case function_or_macro() is implemented in CamelCase FunctionOrMacro.cmake file. So when in doubt, use CamelCase. And use verbs, nouns are for classes....

What is the point of the _StructName convention in C?

c,gtk,conventions

From a strict coding standpoint, it has no purpose. However, in header files it can serve as a type of interface definition, which list the "public" interface of GTK+. By the way, this style follows other GNU libraries. Anyway, I think we can safely say, that with modern C compilers...

Does my backbone.js project require component on a file or is that just a convention?

javascript,file,backbone.js,conventions

No, Backbone doesn't mind if each component is in a separate file or all in a single file. You're correct that JavaScript will just execute what is given to it. I'm assuming this is running in the browser and that the previous developer is somehow loading in the individual components...

the where statement from f90 to matlab conversion

matlab,fortran,conventions

Not correct, no. In the Fortran no_converge ought to be an array of the same size (and shape) as A and B; its elements will be set to 1 where abs(A-B)>e and 0 elsewhere. So in your Matlab code no_converge shouldn't be a scalar but an array. However, without sight...

What dimensions are required in an IOAPI NetCDF file?

format,conventions,netcdf,ioapi

Most recent documentation seems to be included in https://github.com/cjcoats/ioapi-3.2 And there is a section called FILES: Variables, Layers, and Time Steps where You can read that "There are eight types of data currently supported by the I/O API." Without knowing Your files exactly, I cannot tell what format they should...

Is there an updated version of the Java Code Conventions [on hold]

java,coding-style,conventions,code-conversion

Is there an official or at least a de facto official conventions that are more recent? No there isn't a more recent official Sun / Oracle version of the Guidelines. (Or if there is, it is internal to Sun / Oracle.) There are other more recent Java style guides...

Good practice: Constant to non-constant cast

c++,casting,const,conventions

When you choose your parameter to be a const reference, you're telling the user "You can trust that if you pass me an object, it will not get modified [through this reference]†." You should do that as often as possible, because the user can understand more about what your function...

difference between dowhile and do while in fortran90

matlab,fortran,conventions,do-while

Okay, now I think I got your question: the dowhile: statement gives a label or name to the loop, and consequently the loop called dowhile is terminated using the enddo statement. You could have used a different name for the loop as well: mainloop: do while <conditions> ! ... enddo...

Is it preferred to use else or else-if for the final branch of a conditional

if-statement,conditional-statements,conventions

You should know every execution path through your conditional logic regardless. That being said, a simple else for the remaining case is usually the most clear. If you only have an else if it makes the next guy scratch his head and wonder if you are missing something. If it...

NodeJS best practices: Errors for flow control?

javascript,node.js,sails.js,conventions

The above answer is good for Express, but in Sails controllers you should not be calling next; best practice is to always return a response. In most example Sails code you won't even see next as an argument to a controller action function. Also note that Sails comes with some...

Sort by Similarity instead of Alphabetically

algorithm,sorting,conventions

This depends on, among other things, programming language of your choosing. In, say, Java, you can use Collections.sort(List<T> list, Comparator<? super T> c), for which you pass a comparator that can do whategver you want it to do, like return the comparison value based on similarity. In other languages, or...

Branch on boolean statement applied to each element of an iterable

python,list,python-3.x,conventions

You can use any: >>> mylist = [1, 2, 3] >>> any(x > 4 for x in mylist) False >>> any(x % 2 == 0 for x in mylist) True if any(my_condition(x) for x in mylist): .... NOTE: Using generator expression instead of list comprehension, you don't need to evaluate...

using variable in initialization of same variable

c,variables,conventions

C & C++ consider that char* str = strinit(str); is legal; because it is evaluated to: char* str; str = strinit(str); see Why is 'int i = i;' legal? ...

Proper way to set up Date class with validation

c#,class,conventions,accessor,mutators

You are calling setDay (in your Overloaded constructor) before you call setMonth and setYear. Since you need year and month to use DayaInMonth, you need to call those setters in your constructor first.

Can “number += 1” be explained intuitively/mnemonically?

operators,conventions

Putting the non-equals sign before the equals sign reduces perceived ambiguity: a-=b can only mean "Decrement a by b", but a=-b could also mean "Set a to the negated value of b". This wouldn't technically be ambiguous, since the C parsing rules are clear that token consumption is greedy (that...

Should indentation always be minimized? [closed]

coding-style,indentation,conventions

I personally believe that both if(flag) { //long computation return; } else { //long computation return; } as well as if(flag) { //long computation return; } //long computation return; are antipatterns, because they make it more difficult to reason about program flow and the possible return values. They also more...

PowerShell code formatting

powershell,optimization,conventions

I expect you are using a third party product to write your Java code? There is a third party product that can reformat PowerShell automatically: http://www.sapien.com/blog/2014/06/10/powershell-studio-2014-code-formatting/

Conventions for “function expression” declaration

javascript,conventions,function-expression

You did fine. Using the opening ( is not syntactically required in this context, but it makes a great warning to the human reader of the code about what is going on. The convention helps. At the end, the invoking parens () can go inside, or outside, the closing )....

When naming objects in an OOP language, what is the difference between “map” and “transform”?

oop,map,transformation,naming,conventions

In computer science, a "Map" is used to associate a known value/entity to another known value/entity e.g as in your question, ObjectA can be mapped to ObjectB. A "Transform" is used to convert/transform any acceptable value into another using a function e.g. a "transform" to calculate x^2; x could be...

Global variables in Android

android,global-variables,conventions

If you're looking to send a variable from 1 activity to the next, put it in the Intent. If you really have data that needs to be shared between all activities (such as login information or key data structures used by most/all activities) then you should use a singleton pattern.

Rails convention on adding database entries from outside source regularly

ruby-on-rails,ruby,database,conventions

I think it depends of your application restrictions and business requirements. My opinion is that both ways are good. But I'd prefer to connect directly to database of use some message queue, just to avoid HTTP, to decrease number of HTTP calls....

Is there a reason to prefer '&&' over '&' in 'if' statements, other than short-circuiting?

r,vectorization,conventions

Short answer: Yes, the different symbol makes the meaning more clear to the reader. Thanks for this interesting question! If I can summarize, it seems to be a follow-up specifically about this section of my answer to the question you linked, ... you want to use the long forms only...

Procedural code conventions on HTML files

php,html,oop,conventions

The most simple form for you would be to include your class file into your php document to separate it on that level. Then in your php file that needs to utilize the class you would: require_once('filename.php'); // before you work with the class and usually at the top of...

Convention: when writing methods, should I return values, or change data directly?

java,python,methods,return,conventions

Java has certain classes that are immutable. You (as a Java developer) can also create such classes. You cannot change the internal state of any object from an immutable class even if you want to (e.g. you cannot add 1 to an Integer object without creating a new Integer object,...

Java classes with very limited use, but not limited to one class. External or inner?

java,class,package,subclass,conventions

Different programmers and organisations use different standards for this and I don't think there is one right answer. The important thing is to pick a standard and stick to it. My personal standard is that inner classes are always private. If a subclass needs access to it then it either...

Are getters required when the field vars are final?

java,conventions

This compiles but it's not considered good code. MY_INT violates the naming convention: names with all caps are used for static final variables, also known as "class constants" (see this and this, Google's Java style guide too). to conform to naming conventions, it would be better to rename to myInt....

Two method arguments or a new class.. for (X and Y cords) [closed]

conventions

There are a few reasons for this. First, it helps to group parameters meaningfully. In this trivial example, it's immediately obvious that x and y go together, but it might not be as immediately obvious when dealing with a more obscure example. Perhaps more importantly, it cuts down on having...

Is there an good reason to prefix all JavaScript modules with '$'?

javascript,conventions

IMO no. It's convenient, sure, because it's easy to type. For this project, I say continue using it to maintain consistency. But... The problem I feel is that there is an association between '$' and jquery, so confusion -- such as this -- is bound to arise. And when jquery...

How to pass a class/module definition into another file

python,import,module,conventions

In your test_file.py: from file import Card ... card1 = Card(10, "Diamond") # Do something with it By the way, do not name your file file.py: file is a built-in function....

Setting Default Parameters in C++

c++,function,conventions,xcode

C++ and C are parsed top-down. When the compiler interprets a statement, it doesn't know about things it hasn't read yet. In your first example, you declare a function called "volume", prototyped as taking 3 floats and returning a float. You then try to call a function called "volume" that...

What is the benefit of nesting functions (in general/in Swift)

function,swift,conventions,code-organization,nested-function

So if the purported benefit is to "organize the code", why not just have the nested function independently, outside of the outer function? That, to me, seems more organized. Oh, I totally disagree. If the only place where the second function is needed is inside the first function, keeping...

Why every for loop starts with int i=0? [closed]

for-loop,naming-conventions,conventions

i and j have typically been used as subscripts in quite a bit of math for quite some time (e.g., even in papers that predate higher-level languages, you frequently see things like "Xi,j", especially in things like a summation). When they designed Fortran, they (apparently) decided to allow the same,...

Entity Framework Many to Many columns concept

c#,sql,entity-framework,many-to-many,conventions

When designing many-2-many relationship(i.e Student - Teacher) based on intermediate table (Student2Teacher) with only 2 foreign key columns, you'll end up having entities with navigation properties without intermediate table(no entity will be created for that table in context at all): Student.Teachers <- EntityCollection<Teacher> Teacher.Students <- EntityCollection<Student> Meanwhile, if you add...