PhotoDune

What is clean code?

4511 posts
  • Exclusive Author
  • Author had a File in an Envato Bundle
  • Elite Author
  • Has been a member for 4-5 years
  • Sold between 100 000 and 250 000 dollars
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • India
+4 more
VF says

I would like to get answer from experienced CC authors and particularly about JavaScript. Here and there I hear the mention “clean code” on blogs or forums but couldn’t grasp exactly what criteria it points.

I am not much familiar with js fundamentals but only managed to make things without bugs (...and not sure), so understand about where I am. :D

Common sense says 1.Minimal variables, 2.Re-usage with functions, 3. Keeping it less etc but sometimes complexity of project seems to force sacrificing the “coding aesthetics” (readability).

For example the costly DOM operation optimization and wider browser support (micro finishings) can lead to double / tripple the amount of variables and conditions used and finally the confusion arises “Is that finished in a minimum possible manner?”

I would like to get advice / light on this subject :)

355 posts
  • Envato Staff
  • Reviewer
  • Sold between 10 000 and 50 000 dollars
  • Has been a member for 4-5 years
  • Bought between 50 and 99 items
  • Contributed a Tutorial to a Tuts+ Site
  • Beta Tester
+4 more
Philo01 staff says
This should help you get started ;) Although the article examples are written in PHP , the structure applies to almost every language. http://net.tutsplus.com/tutorials/html-css-techniques/top-15-best-practices-for-writing-super-readable-code/
5008 posts The Dude Abides
  • United States
  • Elite Author
  • Has been a member for 4-5 years
  • Exclusive Author
  • Sold between 50 000 and 100 000 dollars
  • Contributed a Tutorial to a Tuts+ Site
  • Author had a Free File of the Month
+4 more
CodingJack says

I could probably take some tips from that article, but one thing I try to do to keep things clean is to make good use of line breaks. For me, this is the #1 way to keep code readable, and I hate viewing code that doesn’t use them.

4511 posts
  • Exclusive Author
  • Author had a File in an Envato Bundle
  • Elite Author
  • Has been a member for 4-5 years
  • Sold between 100 000 and 250 000 dollars
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • India
+4 more
VF says

Thanks Philo, some of the tips from that article really helped. Just found that I do write code horizontally (lengthy lines) and it needs breakdown vertically for quick readability. Also deep nesting has good alternatives.

318 posts
  • Author had a File in an Envato Bundle
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Sold between 1 000 and 5 000 dollars
  • United States
jwmcpeak says
5008 posts The Dude Abides
  • United States
  • Elite Author
  • Has been a member for 4-5 years
  • Exclusive Author
  • Sold between 50 000 and 100 000 dollars
  • Contributed a Tutorial to a Tuts+ Site
  • Author had a Free File of the Month
+4 more
CodingJack says

Some good stuff at https://github.com/rwldrn/idiomatic.js/

great resource. The one thing that bugs me is the parentheses spacing though. In school we learn to write like this:

(x + 2) * (y + 2)

so it feels awkward when spacing the parentheses

if ( x ) ...

But I support no spacing for parentheses only, as no spacing at all drives me nuts

(x+2)*(y+2) :crying:

318 posts
  • Author had a File in an Envato Bundle
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Sold between 1 000 and 5 000 dollars
  • United States
jwmcpeak says

I agree. I prefer (x + 2) as opposed to ( x + 2 ). Too much white spaces can be just as bad as not enough.

4126 posts
  • Bought between 1 and 9 items
  • Brazil
  • Community Superstar
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 5 000 and 10 000 dollars
tsafi says

If you ask me is just a term, there are so many coders out there each one carry his on scratch.

Most imported is code structure since it’s the start key for optimizing your sheets in performance which is major issue with js but its super forgiven semantic platform anyway.

I am a big fun of shorts vars` shorts function short everything (most coders go this way) ,but that’s just horrible way of doing things on the evnato market from buyer point view .

I’ll tell you this if you see the term clean code just imagine your handwriting look like crap but the end resolute is the same vs those girly beautiful handwriting :P .

But since you need to work inside the scoop function with js anyway it will never look clean code to me .

better this way for me

(insane) ? nop() : yes();

go girl power this way :P .
if (insane) 
    {      
      nop();  

    } else {

      yes(); 
    } 
2079 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Community Moderator
  • Bought between 10 and 49 items
  • Referred between 200 and 499 users
  • Has been a member for 4-5 years
  • Won a Competition
+10 more
mpc moderator says

I personally would also love to read some stuff on how to keep your php + html + js code clean because combining those three technologies can make a lot of mess in our code ;O

349 posts
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Most Wanted Bounty Winner
  • Bought between 10 and 49 items
  • Exclusive Author
  • Referred between 10 and 49 users
  • Has been a member for 2-3 years
+1 more
LCweb says

This should help you get started ;) Although the article examples are written in PHP , the structure applies to almost every language. http://net.tutsplus.com/tutorials/html-css-techniques/top-15-best-practices-for-writing-super-readable-code/

Those are for sure great “clean-code” rules. I’ve always followed some of them and try to follow the remaining :D

by
by
by
by
by