Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [code-formatting]

focuses on legibility and consistent look of code: lexical-level intelligibility is a basic element of coding-style

0
votes
2answers
208 views

What arguments in favor of automatic, mandatory, uniform code formatting in a software project? [closed]

I am the manager of a small team of software engineers. I am looking for arguments in favor of automatic, mandatory code formatting. For me it is natural, it goes with the Quality Assurance process ...
-2
votes
1answer
154 views

What Is the Best (Conventional) Way to Format Code for PyQt5

I was looking into PyQt5 for one of my side-projects and would really like to get to learn it better. However, I wasn't sure how to correctly format the code. I've seen tutorials do class definitions ...
2
votes
2answers
152 views

Where to put private computed properties?

In Clean code it's suggested that private helper functions should always exist directly below the function they're directly used within. Should I be doing this when using computed properties? It's the ...
2
votes
2answers
272 views

Highlighting importance of order when using short-circuited conditions

I was working on a piece of code when I noticed that an if statement could work or crash depending on the order used for the parts connected with and. You can replicate the problem like this: ...
2
votes
1answer
236 views

Workflow for git / code formatting / commit hooks etc

Our team is growing, and with it, discontent with common coding standards being imposed on developers with alternate (strong, bordering on religious) views on what constitutes a good coding style. ...
1
vote
1answer
79 views

Making control flow explicit through printing instead of using comments?

I would have the opinion and good practices in script programming about using print statements to materialize the control flow (I usually use an anchor mark, then the name of the function just entered,...
4
votes
9answers
2k views

How small should functions be?

I'm new at writing professional code (the bulk of my experience is with personal projects) so excuse me if this is trivial. When I write code I find myself being a little inconsistent with how much ...
4
votes
7answers
2k views

Why should we not put end brackets on the same line? [closed]

When writing block code in languages like C++ and Java, people usually argue over whether brackets at the end of a line should have their own line. if (condition) { if (condition) { However, I have ...
1
vote
0answers
108 views

Alternative to reorder c++ tokens

Our organization is looking to standardize the way we use const T& and T const& and while we initially looked at clang-format to solve the job, it doesn't reorder tokens so there is no way to ...
-2
votes
4answers
4k views

Multiline formatting of long function signatures/calls [closed]

Let's say you have a signature like so: public void MyFooBar(IExtraSuperLongTypeName param1, TypeA param2 ISomeotherReallyLongTypeName param3, TypeB param4, TypeC param5) Formatting in on one line ...
2
votes
3answers
754 views

Including the type name in a variable name

Abstract: Is it acceptable to include the type name in the variable name? My scenario: I am working with C# MVVM, and I have a lot of ICommand properties in my ViewModel, named various things like ...
2
votes
2answers
1k views

Why does gofmt discourage blank lines at the end of files?

Since I started programming, I've always been taught to leave a trailing blank line at the end of my files, the reason usually being something relating to how it makes concatenated files easier to ...
1
vote
2answers
2k views

What's the use of lint warnings vs errors? [closed]

I'm hoping someone who's given this some thought can help me understand. Most style-checking tools seem to distinguish between warnings and errors. To me, the point of a lint error is that a style ...
1
vote
1answer
202 views

Right-aligning code [closed]

I recently was looking for a CSS solution to vertically-align elements, and I found one here. One thing that I thought was nice was the right-justified code; example: .vertical-center { // ... ...
0
votes
1answer
254 views

Changing repetitive code to improve good programming design

In Java Swing if you want to add a listener to a component, it would look something like this... JButton j = new JButton(); int counter = 0; j.addAncestorListener(new AncestorListener() { @...
7
votes
4answers
3k views

Code formatting: is it worth to make bad code to look bad? [closed]

In Code Complete 2nd Edition, Steve McConnell wrote the following (page 732): Techniques that make good code look good and bad code look bad are more useful than techniques that make all code ...
2
votes
1answer
258 views

What is the name/origin for this C code indentation style?

Look at the formatting of the variable declarations. I haven't encountered this indentation style in the past, but lately I stumbled upon two different code examples which use this style. Where does ...
2
votes
3answers
780 views

Does code format affect performance?

I think I have came across a few times when I reformat some segment of code, it performed the way I wanted it to other than the other poorly formatted segment of code? Does code format affect ...
5
votes
3answers
266 views

Does code formatting have to matter?

UPDATE: an issue would arise from stuff that is not strictly defined by a formatter, like consecutive empty lines etc., that would get lost in the process (local to server to local reformatting) which ...
0
votes
2answers
980 views

Erlang return value conventions

Should functions that return tuples, always return tuples? For example, I have a function is_user_name_allowed that returns a tuple in this he form if the username is not allowed: {false, ["Reason 1"...
6
votes
1answer
971 views

Erlang function naming conventions

I understand the general Erlang conventions for functions are using snake case or camel case, but what about exported functions? For example, say I have a gen_server module that defines a check to ...
4
votes
4answers
1k views

Identify this programming style

Some of the legacy code I've inherited uses the fact that C# supports multiple assignment to write code like: void DisableControls() { ddlStore.Enabled = ddlProgram.Enabled ...
6
votes
1answer
19k views

How to break these long C++ lines in a neat way? [closed]

I'm on my first bigger C++ project and find that I have some really long lines. My goal is to break them to 79 columns, but I do not really know how to do this in a neat way. Are there some guidelines ...
2
votes
1answer
889 views

How far to go when standardizing code [duplicate]

My small team and I have created a decent sized web application (~50k lines), with a fully featured API, all in Perl. As us perl hackers know.. it is easy to get sloppy. We had to port over a lot of ...
6
votes
2answers
184 views

Styling/formatting file for programmers, has it been done?

has there ever been a proposal for establishing a formatting style file for programmers? In web programming, we have CSS files that help separate style from 'code', so two people can see the same code ...
3
votes
4answers
166 views

Structuring an input file [closed]

I am in the process of structuring a small program to perform some hydraulic analysis of pipe flow. As I am envisioning this, the program will read an input file, store the input parameters in a ...
0
votes
2answers
372 views

Why doesn't Python just establish a format for declaring tab widths?

I've read the flame wars over the use of spaces and tabs. When working with any markup language (when scope isn't very important and when pressing space 4 times is a PITA), I tend to minimize the tab ...
7
votes
3answers
362 views

Is there any situation in which it would be appropriate to use unless… else?

This construction is considered wrong unless #.. else #.. end This is for the general reason of double-negative confusions. It translates to: if not #.. if not not #.. end We all agree ...
0
votes
2answers
275 views

Code formatting for variable declarations [closed]

Is it looked down upon or bad to write multiple variable declarations on the same line? As in: boolean playMoreGames = true; int length; boolean win; int ...
15
votes
7answers
4k views

Should I write compact code or code with lots of spaces? [duplicate]

I have two friends that have completely different schools of thought on how to lay out their code. The first says that code should be well-indented and use lots of spaces and to name variables ...
5
votes
1answer
950 views

Chosing a parser for a code beautifier

I'm in the planning stage of making a code beautifier (similar to AStyle or Uncrustify) - originally I was going to just contribute to one of those projects, but reviewing their source led me to the ...
20
votes
5answers
20k views

Is it a good idea to format the code in eclipse using auto format

I use eclipse for coding, and the language which we use is Java. Once it was suggested by someone that to properly format the code, using the auto formatter(CTRL+SHIFT+F) While this command does ...
88
votes
17answers
15k views

Is imposing the same code format for all developers a good idea?

We are considering to impose a single standard code format in our project (auto format with save actions in Eclipse). The reason is that currently there is a big difference in the code formats used by ...
4
votes
1answer
350 views

Are there published guidelines, standards, or references that propose more than 80 chars per line?

Despite increases in screen size and resolution, many sources still suggest that code be limited to 80 characters per line. I realize than there are many different opinions on this subject, but I ...
-1
votes
1answer
346 views

Javascript Form Validation

When validating a JavaScript form, would it be better to process each input field individually, or, where possible check collectively? e.g. validate() { noblanks() fieldOne() fieldTwo(...
5
votes
3answers
346 views

How to work with badly written and formatted code

I was wondering how people deal with working in a project with badly written and formatted code, I'm talking mixed tabs and spaces, unnecessary parentheses and newlines and a whole bunch of warnings ...
7
votes
2answers
835 views

What code format has been verified by case studies as most readable? [closed]

Are there any eye-tracking case studies, or similar research done to verify what code format is easiest to read, maintain and work with? I always format my code the following way: function thing() { ...
11
votes
4answers
498 views

Is it a good practice to use Auto Format the text?

I'm using Eclipse and I will talk about it as an example but I am sure that this is the case in any other IDE. Eclipse has the CTRL-Shift-F command which automatically formats your code. Is it a good ...
2
votes
6answers
23k views

IF ELSE shorthand. Does it hurt readability [duplicate]

Possible Duplicate: Is the ternary operator evil? Does using shorthand if else statments hurt readability? Compare: string name = street != null ? street.Owner : "Not known"; With: string ...
29
votes
14answers
4k views

Why isn't rich code formatting more common?

I was reading Code Complete and in the chapter on layout and style, he was predicting that code editors would use some sort of rich text formatting. That means, instead of code looking like this ...
4
votes
2answers
207 views

Parameter order: size, count or the other way round

I hope this is the right forum for this ... Well, in C, the standard library uses usually (void* buffer, int size) when referring to some data buffer. I wonder if there is a rationale for this order ...
10
votes
2answers
4k views

Algorithm for formating SQL code

I need a tool (for in house usage) that will format SQL code (SQL Server/MySQL). There are various 3rd party tools and online web sites that do it but no exactly how I need it. So I want to write my ...
16
votes
3answers
10k views

Closing tag (?>) on PHP files?

Some people swear by closing their PHP files with ?>, some say it's more optimized to leave it off. I know that it's not essential to have it on there, I'm just wondering what the pros and cons ...
24
votes
5answers
1k views

Formatting code a bad thing when using a VCS?

I almost always format my code before I commit to make sure it's done properly. Most of my team don't really care and don't always format their code properly (minor things that don't affect the code ...
10
votes
3answers
329 views

Code formatting : Laying out functions based on call hierarchy within a class file?

A suggestion from Bob Martin's "Clean code" has me scratching my head.. "If once function calls another, they should be vertically close and the caller should be above the callee" So far, I've been ...
1
vote
7answers
305 views

Single line comments for multiple indented lines of code [closed]

After many years of coding, trying various programming styles, weeding out unreadable or impractical stuff, I still can't figure out one thing: what is the best way to single-line-comment multiple ...
8
votes
1answer
16k views

Header comment format

I realize that the "header comment" format varies from programmer to programmer, but what would be an example of a "good" header comment?
1
vote
3answers
799 views

Formatting PHP, what works more efficiently?

I was just wondering what makes PHP work faster. I have a few methods that I always go and do, but that only improves the way I can read it, but how about the interpreter? Should I include the curly ...
36
votes
30answers
21k views

Is it common to print out code on paper? [closed]

I like to keep my lines of code under 80 characters because: I don't have to do any horizontal scrolling; I know the line is probably too complicated if it exceeds this limit; and it prints out ...
13
votes
3answers
4k views

Best way to organize SQL queries stored in your code ? (or should you?) [closed]

I am sure I am not the only one who gets frustrated when they see a page of code littered with SQL queries. The ActiveRecord and other ORM patterns help mitigate a good amount of SQL used in a project,...