Tag Info

New answers tagged

-1

I have interpreted your question as: How can members of a group each create code that adheres some uniform indentation standard, while still allowing individual contributors to view that indentation differently? Suppose you used a four-space "standard" indent, and then had your coworkers use a macro to rewrite line-leading groups of four spaces to some ...


-1

Does your team use an IDE? Then just use the auto-indent feature if it has it. Most IDEs will have it, and you could even use a common configuration. e.g I do all my indenting in Eclipse with a Ctrl-I. I do not have to count spaces or tabs, and the code is very readable. (We have tried using the Eclipse Java code-formatter, but we gave up) ..and ...


-1

Does it even matter? See some questions on SE getting awfully hung up over ridiculous, irrelevant matters. Extensive questions following extensive answers into things that really aren't worth the time or effort. In some IDEs, you might even undo all of your preferences the minute you hit Ctrl+K+D anyway (at least for VS). EDIT Since some people may ...


-1

Honestly – it so doesn't matter how big the indentation is exactly. Personally, I tend to use only 2 spaces for imperative languages, but though I find it ugly I'm ok with anything up to 8 spaces. What you should of course aim for is that the indentation be consistent. Agreeing on a standard would definitely be a good idea. However, it's IMO not such ...


-1

If I'm editing existing code I tend to adopt the style of that code if someone else is working on it or is likely to come back to it in the near future. If the 'offending' coder is long gone then I will often 'tidy up' if the style is particularly 'weird', but to be honest bad style is somewhat correlated with bad code, so I usually have a good motive for ...


19

Use tabs. this is what they were invented for. If you use tabs then the indentation can be set according to each's preference. You know the phrase "use the right tool for the job", tabs are the right tool when it comes to indentation. (edit: for the downvoters, imagine you go to a new company and they say "our coding standard which you must follow is ...


47

A development team should work as a team, not as a collection of individuals. One important part of this team cohesion is agreeing a common set of coding standards that all must follow. There's no right or wrong with such standards, but it is vital that all agree to abide by the majority or agreed consensus. So hold a group meeting discussion to agree an ...


43

Use a pre-commit hook so that all code gets formatted automatically on its way to repository, and have your IDE reformat the code to your liking whenever it's fetched from repository. It's probably doable, although I agree with @DocBrown - if you're professionals, you should be able to pick a compromise and not sweat over such details. You will encounter ...


90

You could use tabs to indent your code, then allow each user to customise their tab width. Alternatively, agree on a set standard and stick to it - there are far more important things to worry about in software development than tab width. That said, anecdotally most people use four spaces as standard.


0

I have done it many ways. The approach you took is effective, though I often find my code is more readable if I use some extra characters on the variable name to help identify that there is one object, and I'm merely connecting to two facets of it: I myTestObject_i = new Test(); // creates a test, casts it to I J myTestObject_j = (J)myTestObject_i; ...


2

Why not this? public class Main { public static void main(String[] args) { Test i = new Test(); foo(i); ffoo(i); } public static void foo(I i) { i.doSomeThing(); } public static void ffoo(J j) { j.print(); } } It looks like, in the context of your code, you need a Test instance. You don't ...


0

No, you don't need them, and I consider it an anti-pattern to automatically make interfaces for every class reference. There is a real cost to making Foo/FooImpl for everything. The IDE may create the interface/implementation for free, but when you're navigating code, you have the extra cognitive load from F3/F12 on foo.doSomething() taking you to the ...


0

Since the childList field is private, a method must be in MyContainerVO somewhere. However, if the functionality to convert a Collection of ContainerChilds into a Map, based on various keys, is a useful general purpose utility, I would make it a static method of ContainerChild. e.g. public static Map<String,String> ...


3

If putting the functions chronologically improves the readability of the code, it means that you are using functions wrong. The primary purpose of dividing the code to function is to reduce the amount of context you need to hold in your mind at any given time. (functions have other usages when you use recursion or higher-order functions, but that's clearly ...


2

Is there a standard way to indicate that a function returns a new pointer? No, there is no "standard way" (but there is an API design policy currently considered "best practice"). Because of this ambiguity ("what does a function returning a pointer want me to do with it?"), it is currently considered best practice to impose the lifetime and ownership ...


1

A class is responsible for its own state. So validate to the extent that it keeps or puts things in an acceptable state. If a module will be used in a wrong way, we want to throw exception immediately instead of any unpredictable behavior. No, don't throw an exception, instead deliver predictable behavior. Corollary to state responsibility is to make ...


18

Return a unique_ptr: std::unique_ptr<Vertex> new_vertex(const Options& options) { // do stuff... return std::make_unique<Vertex>(...); } There can only ever be one unique_ptr pointing to a given object (unless you abuse it by casting to a Vertex* and back, anyway). You can't ever copy a unique_ptr, only move it. When a unique_ptr is ...


2

There are two speeds in software: the time it takes to write/read/debug the code; and the time it takes to execute the code. If you can convince me (and your code reviewers) that the hashmap function is indeed slower than the if/then/else (after refactoring to make a static hashmap) AND you can convince me/reviewers that its called enough times to make an ...


2

As I understand you're asking about indentation. There is currently no standard concerning indentation in HTML and CSS files. Nor should there be any. Let your editor software worry about the indentation.


2

Tabs have no innate size, their interpretation is up to the observer. If you're the observer, you get to decide how you want to view your tabs, or if you're using other kinds of whitespace, however many you want to have. The syntax in the CSS specification uses [ \t\r\n\f]+ (one or more of the bracketed things) for whitespace, implying that the kind of ...



Top 50 recent answers are included