Comments on: How do you indent your code? http://www.terminally-incoherent.com/blog/2007/06/26/how-do-you-indent-your-code/ I will not fix your computer. Tue, 04 Aug 2020 22:34:33 +0000 hourly 1 https://wordpress.org/?v=4.7.26 By: Davidson http://www.terminally-incoherent.com/blog/2007/06/26/how-do-you-indent-your-code/#comment-67361 Thu, 20 Mar 2014 05:27:37 +0000 http://www.terminally-incoherent.com/blog/2007/06/26/how-do-you-indent-your-code/#comment-67361

at my college, all teachers use the K&R style, I simply ‘fix’ all the codes that are available for it; curiously when I started programming I used only this style but after a while Allman won me over, regardless of whether the code may be greater readability greatly increases.

Reply  |  Quote
]]>
By: Ein Doofus http://www.terminally-incoherent.com/blog/2007/06/26/how-do-you-indent-your-code/#comment-21647 Sun, 11 Mar 2012 00:02:46 +0000 http://www.terminally-incoherent.com/blog/2007/06/26/how-do-you-indent-your-code/#comment-21647

So this on the net and I had to add my 2 cents. I’m trying to get used to looking at Allman now after coming from the Java world and it looks awful. It reminds me of those double-spaced papers from high school.

I mean the key to reading code a block of code is the indentation, so why would you indent two lines when one is enough? Are you seriously telling me that you can’t tell where the block of code begins with this:
if(a==b) {
// do something
foo();
}

Allman creates an unnecessary amount of white space.

Reply  |  Quote
]]>
By: Mirko http://www.terminally-incoherent.com/blog/2007/06/26/how-do-you-indent-your-code/#comment-4991 Thu, 28 Jun 2007 16:42:56 +0000 http://www.terminally-incoherent.com/blog/2007/06/26/how-do-you-indent-your-code/#comment-4991

@Rob speaking of “precious vertical real estate”: I lately accidentaly ;) discovered that my LCD in the office allows rotation (instead of 4:3, it becomes 3:4). works great for coding, web browsing and writing documents. I also dislike 16:9 monitors, because menu and status bar waste even more space. in the 3:4 configuration, this effect is also diminished.

my home LCD does not allow this rotation (but the next one certainly will), so I could not try that in Linux. anybody?

Reply  |  Quote
]]>
By: Luke http://www.terminally-incoherent.com/blog/2007/06/26/how-do-you-indent-your-code/#comment-4979 Wed, 27 Jun 2007 06:29:07 +0000 http://www.terminally-incoherent.com/blog/2007/06/26/how-do-you-indent-your-code/#comment-4979

Ok ladies! I fixed the coding issue. Now you should be able to use blank spaces, and be free not to escape HTML characters – and you will get nice code hilighting.

Just don’t use the <code> tag – use <pre lang=”language”> where language is the name of the language you want to use (like java, php, perl, csharp and etc..)

I made the code button default to java. Here are some examples:

Java:

public class Foo
{
	// most awesome variable evar
	String bar;

	public Foo(String bar)
	{
		this.bar = bar;
	}

	public String getBar()
	{
		return bar;
	}

}

PHP:

< ?php 

	function foobar()
	{
		// do something awesome
		$foo = "bar";

		echo "the foobar: " . bar;
	}
?>

Lisp:

; fibonacci series
(defun fib (n)
	(cond
		((= n 0) 	0)
		((= n 1) 	1)
		((+ (fib (- n 1)) (fib (- n 2))))
	)
)

The supported languages are:

actionscript, ada, apache, applescript, asm, asp, autoit, bash, blitzbasic, bnf, c, c_mac, caddcl, cadlisp, cfdg, cfm, cpp-qt, cpp, csharp, css-gen, css, d, delphi, diff, div, dos, eiffel, fortran, freebasic, gml, groovy, html4strict, idl, ini, inno, io, java, java5, javascript, latex, lisp, lua, matlab, mirc, mpasm, mysql, nsis, objc, ocaml-brief, ocaml, oobas, oracle8, pascal, perl, php-brief, php, plsql, python, qbasic, rails, reg, robots, ruby, sas, scheme, sdlbasic, smalltalk, smarty, sql, tcl, text, thinbasic, tsql, vb, vbnet, vhdl, visualfoxpro, winbatch, xml, xpp, z80

Have fun. :)

Reply  |  Quote
]]>
By: Luke http://www.terminally-incoherent.com/blog/2007/06/26/how-do-you-indent-your-code/#comment-4976 Wed, 27 Jun 2007 01:18:43 +0000 http://www.terminally-incoherent.com/blog/2007/06/26/how-do-you-indent-your-code/#comment-4976

I didn’t know it was called that either, until I checked wikipedia. :P

Reply  |  Quote
]]>
By: Starhawk http://www.terminally-incoherent.com/blog/2007/06/26/how-do-you-indent-your-code/#comment-4975 Wed, 27 Jun 2007 01:15:19 +0000 http://www.terminally-incoherent.com/blog/2007/06/26/how-do-you-indent-your-code/#comment-4975

I use BSD/Allman despite a strong C background. It easier to read and makes more sense to me. BTW I never knew it was called “BSD/Allman” actually i never thought about calling it anything, it just works for me and is a habit now. haha

Reply  |  Quote
]]>
By: Luke http://www.terminally-incoherent.com/blog/2007/06/26/how-do-you-indent-your-code/#comment-4973 Wed, 27 Jun 2007 00:27:05 +0000 http://www.terminally-incoherent.com/blog/2007/06/26/how-do-you-indent-your-code/#comment-4973

[quote comment=”4968″]Yeah, that is how it is supposed to look except I don’t put the newline between the opening statement. Basically, just like your first BSD/Allman excerpt but no extra newline when opening the code block.[/quote]

Actually, that is the BSD/Allman – the extra newline is just an artifact of the pre-wrap CSS attribute.

Reply  |  Quote
]]>
By: Fr3d http://www.terminally-incoherent.com/blog/2007/06/26/how-do-you-indent-your-code/#comment-4971 Tue, 26 Jun 2007 23:16:56 +0000 http://www.terminally-incoherent.com/blog/2007/06/26/how-do-you-indent-your-code/#comment-4971

The indenting style I use depends on the language I’m writing.

For PHP:

if (condition) { 
	do_stuff();
} else {
	do_something_else();
}

C# or Java:

if (condition)
{
	do_stuff();
}
else
{
	do_something_else();
}
Reply  |  Quote
]]>
By: Luke http://www.terminally-incoherent.com/blog/2007/06/26/how-do-you-indent-your-code/#comment-4970 Tue, 26 Jun 2007 22:47:25 +0000 http://www.terminally-incoherent.com/blog/2007/06/26/how-do-you-indent-your-code/#comment-4970

Here is the CSS I use – can you fix it?

code {
	color: black;
	background-color: #f8f8f8;
	border-top: 1px solid #ddd;
	border-bottom: 1px solid #ddd;
	display: block;
	padding: 10px;
	font: 0.9em 'Courier New', Courier, Fixed, monospace;
	white-space: pre-wrap;
	white-space: -moz-pre-wrap;
	white-space: -o-pre-wrap;
}

The pre-wrap stuff seems necessary to enforce white space – like tabs to stick. If I remove it, the browser eats all the tabs. But the same attributes seem to add extra blank space around each line, and cause the block to break if there is a single blank line inside.

Reply  |  Quote
]]>
By: Luke http://www.terminally-incoherent.com/blog/2007/06/26/how-do-you-indent-your-code/#comment-4969 Tue, 26 Jun 2007 22:42:03 +0000 http://www.terminally-incoherent.com/blog/2007/06/26/how-do-you-indent-your-code/#comment-4969

Seriously – I think it’s just some strange side effect of the CSS I use to format my code blocks – for some reason, any blank spaces will suddenly “end” the block. Weird.

Reply  |  Quote
]]>