Skip to: Site menu | Main content


Welcome to PSP-Programming.com, a place for developers to get together.

Welcome to the forums. Here you can find other user tutorials as well as homebrew releases and the source code repository. You can also ask for help with your code here and post your own homebrew!

PSP-Programming.com Forums
February 11, 2012, 01:17:25 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

News: Welcome to PSP-Programming.com
Home Help Search Shop Login Register
Digg This!
Pages: [1]
Print
Author Topic: The 5 Bits of Style  (Read 3551 times)
nathan42100
Give miinaturvat Points!
Administrator
Hero Member
*

Karma: +32/-2
Offline Offline

Posts: 1161
934.18 points

View Inventory
Send Money to nathan42100


View Profile WWW
« on: September 25, 2006, 04:14:21 PM »

Style is a crucial component of professionalism in software development. Clean code that follows stylistic conventions is easier to read, maintain, and share with colleagues. Programmers who code in good style are less likely to have silly bugs and will actually spend less time developing and debugging their code. Finally, good style in programs is a concern because for us, humans, style and aesthetics are a concern in everything we do.

Following stylistic conventions is easy, and, after a litter practice, becomes second nature. Occasionally, an especially independent-minded student resists all conventions, arguing, "But it works!" To this person, we can point out two things. First, a programmer's product is not an executable program, but its source code. In the current environment, the life expectancy of a "working" program is just a few months, sometimes weeks. On the other hand, source code, updated periodically, can live for years; to be of any use, it must be readable to others. Second, bad or unconventional style is uncool. It immediately gives away an amateur, a kind of social misfit in the software developers' culture. As nerdy as this culture might be, it has its own sense of aesthetic pride.

In programming, style has a deeper meaning: it is that elusive quality which makes on person's code elegant and easy to follow than another person's convoluted and obscure although in line with all the superficial stylistic conventions. The mystery is not as wide open in writing code as in creative writing: there are many firm design principals, and "a person who thinks clearly" usually is able to code clearly. Still, some mystery remains. Here we discuss only the superficial stylistic conventions, leaving the deeper meaning alone.

Bit 0.
Quote
At the top of each Lua file, put a comment that states the purpose of the file, its author, date of completion, and other pertinent info, such as a copyright message, special instructions on how to run the program, data files that your program reads or creates, and a history of revisions.


Bit 1.
Quote
Place all dofile() functions at the top of your Lua file. Start with standard libraries/files (such as netlib) followed by your own files.


Bit 2.
Quote
Separate different functions in a file with blank lines and  separator comment lines. Split your code into "paragraphs" that represent meaningful steps or actions in your program by inserting blank lines, and, if necessary, comment lines


Bit 3.
Quote
Place each statement on a separate line. Indent

Lua code is usually indented by a tab or 3 spaces in the body of the function or under if, else, switch, and for and while loops


Bit 4.
Quote
Use spaces liberally. Do not cram things together.

There are no clear-cut rules on where to add spaces -- different people have different tasted. We use spaces on both sides of the assignment operator and other binary operators: Arithmetic, logical, relational. For example:
Code:
taxAmount=saleAmount*taxRate

less readable then
Code:
taxAmount = saleAmount * taxRate


Adapted from Java Methods Textbook
Logged

All of my work is released under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 License.
dn ʎɐʍ sıɥʇ
Help support my computer projects!



Sleepy
C/C++ Developer
Full Member
*

Karma: +98/-55
Offline Offline

Posts: 192
0.00 points

View Inventory
Send Money to Sleepy


View Profile WWW
« Reply #1 on: January 12, 2007, 02:54:01 PM »

Good post. Most people are so busy with completing/contuinuing with their project that they make it unreadable, which is extremely annoying, especially when trying to find an error. People usually say I space too much, but I say I space just enough.
Logged

Creator and programmer of funcLib
[funcLib Home]
AssassinXCV
Give miinaturvat Points!
Newbie
*

Karma: +0/-6
Offline Offline

Posts: 36
592.92 points

View Inventory
Send Money to AssassinXCV

View Profile
« Reply #2 on: October 03, 2008, 04:30:08 PM »

Good post. Most people are so busy with completing/contuinuing with their project that they make it unreadable, which is extremely annoying, especially when trying to find an error. People usually say I space too much, but I say I space just enough.

Ya, a very helpful post, i always make a blank line in between my different functions and other things. Plus i usually put comment lines in so even I can remember what each section does
Logged
Pages: [1]
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.276 seconds with 27 queries.
Sister Sites: Guitar Hero 4   BrokeniTouch.com