What Is Good Code?

Programmers are artisans—not scientists. Our code must work, yet good code is not only tested and functional; it is a pleasure to read. Good code is that which others can learn from and enjoy the most. It is beautiful. It oozes the care that went into each line, leaving only those with unassailable purpose. Good code is whole; lines cannot be removed without compromising one of any good program's essential qualities: functionality, readability, elegance.

Good code is as often ingenious as it appears to be obvious. Its elegance masks the programmer's labor, like a ballerina twirling on stage. Good code frequently makes comments unnecessary, yet they conveniently appear in complex passages to assist the reader. Good code reflects a programmer's agility in cycling between the macro and micro views of his code; better programmers are both astronomers and particle physicists. They are also artists.

Good code is equally usable by other coders and by users of the program. It is always the work of an optimist because it represents an investment for the future, a proud bet the coder's effort is worth it because his code will last. If it does, it will shine as good code does when it must be revisited by its author or someone else.

Like wine, good code sits in silence during its making. Aging code allows us to shape missing elements and recognize superfluous bits. Code reveals the intimate nature of its maker. It brings to light an author's thought processes and how he expresses them. Only good humans can write good code, people who care for their work, and for those who will use its result.

This is the code we used to create this chart:
//@author=LucF, for PineCoders
study("Good Code", "", true, scale = scale.none, max_labels_count = 500)

f_randomNumber(_range) =>   // [symbol=thx]Thx[/symbol] to Maestro (@RicardoSantos) for the initial code of this function.
    var _return = 1.0 + timenow
    _return := (3.14159 * _return % (bar_index + 1)) % _range

i_charsPerLine  = input(300, step = 50)
i_lines         = input(160, step = 50, maxval = 499)

t = array.new_string(8)
array.set(t, 0, "G")
array.set(t, 1, "o")
array.set(t, 2, "o")
array.set(t, 3, "d")
array.set(t, 4, "C")
array.set(t, 5, "o")
array.set(t, 6, "d")
array.set(t, 7, "e")

// Create i_lines strings of i_charsPerLine randomly selected characters from our array.
if barstate.islast
    // Cover the chart with random pattern of characters.
    for _i = 1 to i_lines
        textLine = ""
        for _j = 1 to i_charsPerLine
            textLine := textLine + array.get(t, int(f_randomNumber(TEXT_LENGTH)))[100], _i, textLine, style = label.style_none, size = size.normal)
    // Overprint the larger text in the middle a few times to gain density.[130], i_lines / 2, "Good Code", style = label.style_none, size = size.huge, textcolor =[130], i_lines / 2, "Good Code", style = label.style_none, size = size.huge, textcolor =[130], i_lines / 2, "Good Code", style = label.style_none, size = size.huge, textcolor =
Tools and ideas for all Pine coders:
Our Pine FAQ & Code:
Pine news broadcasts: or


+1 Reply
Love this post! Strongly agree with you.
Was this script made to demonstrate how a few lines of code create large/complicated plots?
PineCoders pitlordinvesting
@pitlordinvesting, Just some holiday fun to show "Good Code" written in a few different ways, and to have something else than a normal chart on the idea's cover. Unashamedly useless.
public static void main(String args){
System.out.println("Java is better ;) ");
Thanks for sharing your good code, description, and efforts with the community!
PineCoders allanster
@allanster, Thx for your gentle nudge inciting us to share this publicly. Looks like it was worth it.
"only goodhumans can create good code" interesting
PineCoders jsunthaoptionztradr
Home Stock Screener Forex Screener Crypto Screener Economic Calendar How It Works Chart Features Pricing Refer a friend House Rules Help Center Website & Broker Solutions Widgets Charting Solutions Lightweight Charting Library Blog & News Twitter
Profile Profile Settings Account and Billing Referred friends Coins My Support Tickets Help Center Ideas Published Followers Following Private Messages Chat Sign Out