code-formatting

How to correctly format PHP 'IF ELSE' statements?

It's been a long running issue that I've come across in many-a-hot-and-steamy coding sessions. One person codes this way another codes that way. So after much push and pull I'm curious... Is there any correct way of phrasing a PHP 'IF ELSE' statement? Personally I use the: if ($variable == 'setvalue') { $variable = executefunction...

Switching methods for a single result.

Heyall, I have a situation where I require to consult different objects in PHP via different methods to find some data. The question regards more about formatting the code than an actual programming issue. What I am trying to do is not using several if's to gather this data like: $data = obj->getData(); if (!isset($data)) $data = othO...

Eclipse Ganymede for OS X contains no HTML formatter. Alternatives?

In Eclipse 3.4 for Windows, the Source -> Format option for formatting Java code was extended to format HTML code. However, for OS X, this option is disabled. Additionally, there are no formatting options in the Preferences. I've downloaded all the Web Tools for Eclipse and the option is still unavailable. Which plugin/feature allows f...

Is there away to have vs2008 collapse nested classes?

I'd like to be able to collapse (with the default chord ctrl+m, ctrl+o) the following class Foo { string Test { get; set; } string Test2 { get; set; } class Bar { string Test3 { get; set; } string Test4 { get; set; } } } To class Foo { string Test { get; set; } string Test2 { get; set; } ...

What's the best way to format source code on IMs to preserve indenting?

Is there a way to preserve indenting in instant messengers when you are pasting source code to a co-worker? In particular I'm trying to write some python code via google talk, but all tabs are removed. ...

Format source code on save in Visual Studio 2005

I would like Visual Studio to format my source code every time I save. I can do this in Eclipse. Can it be done in Visual Studio 2005? ...

C# to format (indent, align) C# properly

We have a code generator that munges the schema of a given database to automate our inhouse n-tier architecture. The output is various C# partial classes, one per file. In the code to munge all the strings, we try and keep on top of the indenting and formatting as much as possible, but invariably when you come to open the file in Vis...

How can I apply a new emacs C style to reformat all my source files?

I'd like to re-format all my source files using the Google formatting function for emacs: google-c-style.el (see here). How can I apply this function to all my source files at once, so that they are all formatted and indented correctly according to the Google style? ...

How does the Traditional "HTML is only for content" line of thought handle dynamic formatting?

For so long, I've read and understood the following truths concerning web development: HTML is for content CSS is for presentation JavaScript is for behavior. This is normally all fine and good, and I find that when I strictly follow these guidelines and use external .css and .js files, it makes my entire site much much more manageab...

How to enforce maximum line length in Emacs?

In Emacs, how can I enforce a maximum line length of, say, 80 characters? I want it to insert proper line breaks in my code, much like fill-paragraph for text, if possible, with the correct insertion of the second part of the line. Here a little example: LongNameType<PrettyLong, AlsoLong> doSomethingWithLongFunctionName(int a, int b); ...

Turn off auto formatting in Visual Studio

I'm code purist, preferring own style of code formatting (opposite to suggested by VS 2008) I've turned off auto-formatting options in Tools/options. In most cases it works. But noticed that after refactoring VS demolishes my code... (Eg after using such option as encapsulate field, extract method, using surrounding snippets...) This ...

format code from ide ( VS2008)

Every once in a while I will paste in some code and it will lose all its tabs and look pretty bad I know that in the vs2008 xml viewer there is a button to format(indent) all the code to the correct hierarchy Is there such a function or macro or shortcut key that i could apply this to a section of code (or to all the code in that windo...

Is it common to indent code at scope only braces?

For generated code I have an option to either indent or or not indent at braces which are only used to house variables at scope. Currently it does not indent at this level and I am wondering if I am going to imply a nested structure by indenting it? What is the common practice? /* loop through the total number of letter a rules */ fo...

Are there any free cmd-line scripts which can re-format PHP source-code?

I'm using a pre-commit hook to lint-check PHP source submitted by our staff, and everyone's really happy with the results. The staff have agreed it would be useful to have the code re-formatted to follow (customizable) style rules on commit. Are there any FOSS scripts which can do this from the command-line? ...

Indenting #defines

Hi all, I know that #defines etc. are normally never indented. Why? I'm working in some code at the moment which has a horrible mixture of #defines, #ifdefs, #elses, #endifs, #etc. All these often mixed in with normal C code. The non-indenting of the #defines makes them hard to read. And the mixture of indented code with non-indented...

How can I prettify Perl code generated by Perl?

I have a test generator written in Perl. It generates tests that connect to a simulator. These tests are themselves written in Perl and connect to the simulator via its API. I would like the generated code to be human-readable, which means I'd like it to be properly indented and formatted. Is there a good way to do it? Details follo...

Online Tool to Unminify / Decompress JavaScript

Are there any scripts and/or online tools that can reverse the effects of minification similar to how Tidy can clean up horrific HTML? I'm specifically looking to unminify a minified JavaScript file, so variable renaming (like with compression or packing) should theoretically not be an issue. ...

Industry spread code formatting tools

What are the tools that are most used in the industry for formatting source code, C++ in particular, so to obtain a style consistency of the whole code base? Possibly tools that would allow the user to select which style to apply (e.g. BSD, GNU, etc...)? I could not find many references on the web to solid, wide-spread tools for such a ...

Sorting methods in Eclipse

Is there an easy way to sort methods within a class in Eclipse? ...

Formatting PHP Code within Vim

I'm currently using Vim as a lightweight IDE. I have NERDTree, bufexplorer, supertab, and ctags plugins which do almost everything I want. Only big thing missing for me is auto code formatting. I'm working with some messy PHP code which has inconsistent indenting and code formatting, ideally I could highlight the code I want formatted (...