Jump to content




Why Is It Usefull To Use Spaces In Front Of Code?


  • You cannot reply to this topic
9 replies to this topic

#1 Zambonie

  • Members
  • 477 posts
  • LocationSpring Hill, Fl

Posted 24 January 2013 - 01:28 PM

Most of the "famouse programer"(Like people who made an good os or something(like NFD-OS))Always use spaces in front of code.What is it used for?

#2 Henness

  • Members
  • 189 posts

Posted 24 January 2013 - 01:32 PM

Its so you can easily see were a section of code starts and ends, it's a standard in programing. You can easily get lost in your code when its thousands of lines long

#3 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 24 January 2013 - 01:33 PM

whitespace actually has no functional use in modern day programming languages as the compiler just ignores it. however I ask you this, which of the following is easier to read

No whitespace:
Spoiler

With whitespace:
Spoiler

EDIT: It also makes it easier to tell when you have forgot to put an end for a block.

Edited by TheOriginalBIT, 24 January 2013 - 01:35 PM.


#4 Zambonie

  • Members
  • 477 posts
  • LocationSpring Hill, Fl

Posted 24 January 2013 - 01:36 PM

Is there a specific way to use whitespace or everyone has there own way of using it?

#5 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 24 January 2013 - 01:37 PM

everyone normally varies... some use 2 space tabs, some use 4 space tabs, etc.

also there are some languages, such as Python that require correct indenting to delimit functions

but convention says that indentation is done in a block, i.e. if, while, repeats, functions etc

read this http://lua-users.org...i/LuaStyleGuide

#6 Zambonie

  • Members
  • 477 posts
  • LocationSpring Hill, Fl

Posted 24 January 2013 - 01:50 PM

So is this maybe a good example?: (Im using my death o meter in my sign.)
print("Is P4 awsome?")
  local input = read()
    if input == "Yes." then
	  print("Well good!Ill give you a diamond out of that dispenser!")
	    sleep(1.5)
		  redstone.setOutput("right", true)
		    sleep(1)
			  redstone.setOutput("right", false)
			    else
				  print("Well,Il atleast give you something..")
				    sleep(3)
					  print("LAAAAAAAAAAVAAAAAAAA!!!!")
					    redstone.setOutput("top", true)
						  sleep(7)
						    redstone.setOutput("top", false)
					   end
						 sleep(10)
						   term.clear()
							 term.setCursorPos(1,1)
							  print("Thank you for using P4's Death-O-Meter!")


#7 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 24 January 2013 - 02:30 PM

I'll be honest, that's probably worse. The general rule in tabbing is to tab after an if/for/while/repeat statement, and remove a tab on an end.

if condition then
  while condition do
    for i=1, 19 do
      repeat
        stuff()
      until condition
    end
  end
end

More information on commonly accepted tabbing styles (the Formatting section): http://lua-users.org...i/LuaStyleGuide

#8 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 24 January 2013 - 02:32 PM

View PostP4isHere., on 24 January 2013 - 01:50 PM, said:

snip

*SCREAMS*

#9 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 24 January 2013 - 02:48 PM

View PostKingdaro, on 24 January 2013 - 02:30 PM, said:

More information on commonly accepted tabbing styles (the Formatting section): http://lua-users.org...i/LuaStyleGuide
Haha same link I suggested :P


View PostCloudy, on 24 January 2013 - 02:32 PM, said:

View PostP4isHere., on 24 January 2013 - 01:50 PM, said:

snip

*SCREAMS*
Couldn't agree more!

#10 dissy

  • Members
  • 181 posts

Posted 24 January 2013 - 03:59 PM

P4isHere:

Great example!
I took your program and its spacing, and copy/pasted it 10 times.
Here it is: http://pastebin.com/wahjfhj0

I've changed one "end" command in just one of those 10 copies. It should take you no more than 5 seconds to find it.

Reply back with which "end" line number I changed, and how long it took you to find it. Remember, it should take no more than 5 seconds to do this!
Every second and minute longer than the first 5 seconds is the answer to your question "why is it useful" :}





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users