Super scaling style

indenting for every purpose

Page 1 of 1

8 Replies - 798 Views - Last Post: 11 August 2009 - 02:50 PM

#1 Jaakuuta  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 163
  • Joined: 02-July 09

Super scaling style

Posted 10 August 2009 - 03:34 PM

I came up with a style recently and I wanted to see if it's used or if it seems a bit excessive. I like it because I think it improves program readability and debugging, but it may get a bit annoying as it tends to scatter code a bit...
here's an example (in java)

public class CodeSample
{
  public static void main
  (
	String[] args
  )
  {
	String s1 =
	new String
	(
	  "a string"
	);
	String s2 =
	new String
	(
	  "another string"
	);

	if
	(
	  s1.equals
	  (
		s2
	  )
	)
	{
	  System.out.println
	  (
		"s1 equals s2"
	  );
	}
	else
	{
	  System.out.println
	  (
		"s1 does not equal s2"
	  );
	}
  }
}



it seems that if you do things this way it would make it easier to modify individual parts of a program like parameter lists and would make debugging easier because the compiler could specify a particular line where a code is in error and would be more specific than if there was just one line with a bunch of different code in it...

This post has been edited by Jaakuuta: 10 August 2009 - 04:38 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Super scaling style

#2 gawdlike  Icon User is offline

  • you can't fix stupid.

Reputation: -7
  • View blog
  • Posts: 647
  • Joined: 16-November 08

Re: Super scaling style

Posted 10 August 2009 - 03:53 PM

Whatever floats your boat.

But yeah, to me, that is over the top.

This post has been edited by gawdlike: 10 August 2009 - 03:54 PM

Was This Post Helpful? 0
  • +
  • -

#3 AdaHacker  Icon User is offline

  • Resident Curmudgeon

Reputation: 452
  • View blog
  • Posts: 811
  • Joined: 17-June 08

Re: Super scaling style

Posted 10 August 2009 - 04:24 PM

Frankly, if you think that improves readability, you're completely out of your mind. You've taken what should be at most 20 lines of code (probably less) and padded it out to 40, adding a few levels of indentaiton in the process. You've at least doubled the time and cognitive effort required to comprehend a block of code. I can't even imagine trying to maintain a few thousand lines of that.
Was This Post Helpful? 0
  • +
  • -

#4 Jaakuuta  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 163
  • Joined: 02-July 09

Re: Super scaling style

Posted 10 August 2009 - 04:35 PM

that's okay, I'm sure I probably lost my mind a long time ago ;)
I like the idea because then once you've finished, you can go back and modify individual elements easily, so for example if you wanted to change one of the strings used or something like that, you could just go to the line where that particular call is made and change one element, by using the arrow keys you can get directly to that point in the code without having to search through the code to try to find one particular part you're trying to modify...

besides, I think something like this is more readable than using the { right after the call to something like

SomeClass {
  main() {
	someFunctionInMain() {
	}
  }
}



that kind of thing is really irritating for me and makes it harder to read imho...
besides that, it leaves scattered { that aren't aligned with the closing } which seems to promote asymmetry which makes the code look very cluttered...

This post has been edited by Jaakuuta: 10 August 2009 - 04:43 PM

Was This Post Helpful? 0
  • +
  • -

#5 gawdlike  Icon User is offline

  • you can't fix stupid.

Reputation: -7
  • View blog
  • Posts: 647
  • Joined: 16-November 08

Re: Super scaling style

Posted 11 August 2009 - 03:31 AM

As long as you are the only person reading your code, do whatever you want. But anybody else is probably going to find that a pain to read.
Was This Post Helpful? 0
  • +
  • -

#6 AdaHacker  Icon User is offline

  • Resident Curmudgeon

Reputation: 452
  • View blog
  • Posts: 811
  • Joined: 17-June 08

Re: Super scaling style

Posted 11 August 2009 - 09:34 AM

View PostJaakuuta, on 10 Aug, 2009 - 05:35 PM, said:

I like the idea because then once you've finished, you can go back and modify individual elements easily...

I honestly don't see why you think that. Changing parameters to a method call isn't hard by any stretch of the imagination. Maybe I'm just not getting what you mean, but it sounds to me like you're trying to solve a non-problem.

But hey, whatever floats your boat. As long as you're not doing this on a codebase I have to work with, I don't care.

Quote

besides, I think something like this is more readable than using the { right after the call

Well, there's no law that says you have to put the opening brace on the same line. You can always just put it on the next line by itself, so that the opening and closing braces line up. In fact, that style is actually very common. You certainly don't have to go as far as you have here for that.
Was This Post Helpful? 0
  • +
  • -

#7 NeoTifa  Icon User is online

  • Whorediot
  • member icon





Reputation: 2672
  • View blog
  • Posts: 15,718
  • Joined: 24-September 08

Re: Super scaling style

Posted 11 August 2009 - 11:35 AM

It makes me confuse () for {} :( :v:

public class CodeSample
{
  public static void main(String[] args) {

	String s1 =new String("a string");
	String s2 =new String("another string");

	if(s1.equals(s2)) {

	  System.out.println("s1 equals s2");

	}//End if

	else {

	  System.out.println("s1 does not equal s2");

	}//End else

  }//End main method

}//End CodeExample class



This is how I do it. ;) I put comments after every } because I get them mixed up. I also space a lot, but thats just extreme!
Was This Post Helpful? 0
  • +
  • -

#8 Tom9729  Icon User is offline

  • Segmentation fault
  • member icon

Reputation: 180
  • View blog
  • Posts: 2,641
  • Joined: 30-December 07

Re: Super scaling style

Posted 11 August 2009 - 01:38 PM

I think putting the opening brace on a new line improves readability.

If you do every function call like that though, you must not write very much code...
Was This Post Helpful? 0
  • +
  • -

#9 Jaakuuta  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 163
  • Joined: 02-July 09

Re: Super scaling style

Posted 11 August 2009 - 02:50 PM

I don't normally code like this, this is merely an experiment... I like trying new ways of doing things... I was saying it makes it easier to modify individual elements because rather than having to go up and go over into an argument list on a function call or something like that, the argument list is on a separate line, enabling you to just go immediately to it... plus I like the look of the zig-zagging effect
I don't get the () confused with the {} because it depends on what you're looking at... admittedly it is a bit much to do it for things that don't change a lot like the whole (String[] args) part and whatnot, or very small, rarely changing elements, but I think for printf statements and the like it makes it look very neat because you can make it so that every line that will print out is on a new line and every formatting argument is on a separate line after the main string, like so

System.out.printf
(
  "s1 = %s\n" +
  "s2 = %s\n" +
  "s3 = %s\n" +
  "s4 = %s\n\n",
  s1, s2, s3, s4
);



Anyway, I think a happy medium would be good, because next I'm going to experiment with just how much you can fit on a single line ;)

An example might be something like using a single line statement in a single statement, and making more complex statements into multiple lines


if(s1.equals(s2)) {...}

or

if
(
  s1.equals(s2)
  &&
  s2.equals(s1)
)
{...}

or if you have a bunch at the same time

if
(
  s1.equals(s2) &&
  s2.equals(s3) &&
  s3.equals(s4)
)

or if you had a complex mathematical equation

public static double sin(double x)
{
  double temp;
  for
  (
	int n = 0;
	n <= 80;
	n++
  )
  {
	temp +=
	(
	  Math.pow(-1, n)
	  *
	  (
		Math.pow( x, (2 * n + 1) )
		/
		fact( (2 * n + 1) )
	  )
	);
  }
  return temp;
}


This post has been edited by Jaakuuta: 11 August 2009 - 07:15 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1