conventions

Standard C functions: Check for -1 or 0?

Many standard C and POSIX functions return -1 for error, and 0 on success, for example truncate, fflush, msync, etc. int ret = truncate("/some/file", 42); Is it better practice to check for success with ret != -1 or ret == 0, and why? My Thoughts It's my experience most people check for the error case (ret != -1), as there is typica...

using fluent-nhibernate, is there convention to make the foreign-key column in one-to-many relation not null ?

I'm using fluent-nhibernate conventions to map my entityies: public class HasManyConvention : IHasManyConvention { public void Apply(FluentNHibernate.Conventions.Instances.IOneToManyCollectionInstance instance) { instance.Key.Column(instance.EntityType.Name + "ID"); instance.Cascade.AllDelete...

Are there any conventions on throwing exceptions from implementations of IObserver?

Hi! I'm implementing IObserver. Are there any conventions about throwing exceptions from IObserver? Can OnNext or any other method of my implementation throw exceptions? What should happen if exception is thrown in OnNext or OnCompleted - should I catch all exceptions and call this.OnError(ex)? What will happen if OnError throws? ...

Fluent NHibernate different Conventions for different base types

Hi All At this moment we are keeping all Entities and Mappings into same assembly. Our entities derived from a basic class Entity which is an EntityWithTypedId Also we are having a table name Convention telling to pluralize the table names. Now I want to create other two base types e.q. AggregateRootEntity and AggregateEntity, both d...

Does naming conventions make better maintainable code?

I like to give my variables, methods and objects descriptive names. Obviously not going overboard, but let me give you a couple of examples. public class Account { public decimal Balance { get; set; } } Account account = new Account(); account.Balance = 1000; Some people would opt to go for the following, which really does not ma...

What should have javadoc in Java ?

What should be documented by javadoc comments (classes, methods, constructors and fields? Or only classes methods and constructors?)? Is there any convention about that ? Please provide links to relevant resources in your answer whenever possible. Thank you EDIT: The question is not about how is it usualy done or what is logical to com...

General convention for python libraries that also have an interface module?

Right now I've got a project that has the following layout: foo/ __init__.py __main__.py foo.py In this case, foo.py is actually the main api file, so developers are meant to do "from foo import foo", but I also wanted to make it so that end users could just run ~$ foo and get an interface. which, when I do a distutils install,...

Scala naming convention for "setters" on immutable objets

I do not know what to call my "setters" on immutable objects? For a mutable object Person, setters work like this: class Person(private var _name: String) { def name = "Mr " + _name def name_=(newName: String) { _name = newName } } val p = new Person("Olle") println("Hi "+ p.name) p.name = "Pelle" println("Hi "+ p.name) Th...

When to use 'this' keyword in Java?

Possible Duplicate: Java - when to use 'this' keyword Is it generally good convention to references class attributes with 'this.' even if it would reference the attribute by default anyway? Or should I only use it when absolutely necessary? It would make things clearer to the programmer, and to avoid any confusing errors if t...

Learning simple programming conventions

Where can I learn more about simple programming conventions and design patterns? When I say simple I mean which is the preferred way of writing the following equivalent functions: function() { if (condition) { # condition wraps the entire function } } or function() { if (!condition) { return; } # rest of the funct...

C++ Function Conventions?

Just had a 'Fundamentals of Programming' lecture at uni and was told that the convention for using/declaring functions is to have the main() function at the top of the program, with functions/procedures below it and to use forward declarations to prevent compiler errors. However, I've always done it the other way - functions at top main...

REST convention for resources with slashes

Is there any REST convention for handleling resources with slashes? For instance, let's say a normal REST resource works like this: /ice cream/chocolate - returns the ingredients of chocolate ice cream /ice cream/rocky road - returns the ingredients of rocky road ice cream /ice cream/strawberry/banana - returns the stawberry banana in...

Python: how to add contents of iterable to set?

In Python, what is the "one [...] obvious way" to add all items of an iterable to an extant set? ...