Learn to Program

Difference between version 64 and 65 - Previous - Next
|[Tcl Quoting%|%previous : Tcl Quoting]|[Contents%|%up: Contents]|[Tcl Commands%|%next : Tcl Commands]|

'''Learn to Program''' is a '''[Contents]''' page for topics that are related
to the art of programming in general.

** See Also **

   [Beginning Tcl]:   The specifics of [Tcl]

   [Casual Programming - Amateurs, beginners et al]:   

   [BOOK Structure and Interpretation of Computer Programs]:   Formerly used as the textbook of the MIT introductory programming class; widely considered a classic text in computer science.

   [BOOK Concepts, Techniques, and Models of Computer Programming]:   

   [How to be a Programmer: A Short, Comprehensive, and Personal Summary, Robert L. Read, 2002]:   

   [Tips for writing quality software]:   

   [How one learns to write better code]:   

   [What are some general programming recommendations independent of Tcl]?:   

   [http://www.tug.org/TUGboat/tb10-4/tb26knut.pdf%|%Notes on the Errors of][TeX], by [Donald E. Knuth]:   ''"I decided that the presentation of a true-to-life list of errors might be the best way to help other people learn the lessons that my experiences with [TeX] have taught me."''

   [What non-Tcl specific books do developers find they reference or recommend]:   
   [http://www.t3x.org/reload/index.html%|%Practical Compiler Construction: A Non-nonsense Tour Through a C Compiler]:   An advanced programming textbook and a compiler-writing primer. Some programming skills are required, but no prior knowledge in the field of compiler construction is necessary.

   [http://www.t3x.org/index.html%|%Sketchy Scheme, 4.5th Edition]:   A beginner-friendly introduction to functional programming in Scheme. This is a step-by-step guide to problem-solving in the functional way. The book contains lots of example, from trivial to advanced, as well as Scheme definitions of many standard procedures, an informal explanation of continuations, and a digression dealing with lambda calculus. Got stuck with SICP? Try this one! 

   [http://www.amazon.com/How-Design-Programs-Introduction-Programming/dp/0262062186%|%How to Design Programs: An Introduction to Programming and Computing] ([http://www.ccs.neu.edu/home/matthias/HtDP2e/index.html%|%second edition draft]), by Matthias Felleisen, Robert Bruce Findler, Matthew Flatt, Shriram Krishnamurthi:   The goal of our book is to introduce readers of all ages and backgrounds to the craft of designing programs systematically. We assume few prerequisites: arithmetic, a tiny bit of middle school algebra, and the willingness to think through issues. We promise that the travails will pay off not just for future programmers but for anyone who has to follow a process or create one for others.

** Description **

Writing programs is about knowing what you want to do, and finding a way to do
it.  Reading programs is about understanding what it does, and figuring out
what the author wanted it to do.  Any author worth their salt is almost
certainly also a voracious reader.  Make sure to take time to read programs
written by others.  Lots of them.

There are, of course, many resources out there in the world that teach
beginners the art of computer programming.  One of the more well-known is
''[BOOK Structure and Interpretation of Computer Programs%|%The Structure and
Interpretation of Computer Programs]'', but it uses [LISP] rather than Tcl.
Tcl is a fantastic first language for someone interested in getting into
computer programming, and this page introduces Tcl obliquely by introducing the
general art of programming, using Tcl as a resource to illustrate the concepts.

** Primitives **

At the hardware level, which is the domain of [assembly language%|%assembly
languages], the primitives of a program are '''values''', '''storage''',
'''instructions'''.  One layer of abstraction up, the primitives for '''data'''
are '''values''', '''sequences''', and '''mappings''', and the primitives for
'''routine''' are '''assignment''' and '''function'''.  Some languages
abstract some primitives away, but internally they are still there somewhere,
in some form, composing the higher-level abstractions.

Primitives that exist at higher levels, e.g. '''classes''' and '''objects'''
in [object orientation%|%object oriented programming], are implemented in terms
of the primitives at lower levels.

Here is how the primitives are used in Tcl: 

%|category|primitive |Tcl                    |%
|data     |
|         |value     |[EIAS%|%any string]    |
|         |sequence  |[list]                 |
|         |mapping   |[dict]                 |
|routine  |
|         |function  |[proc], [apply]        |
|         |assignment|[set], [variable], etc.|

At lower levels, the primitives are, well, more primitive.  In assembly
languages, for example, storage locations are just storage locations, and the
programmer keeps track of how those locations should be operated on.  There is
no specific syntax for sequences of values, but clearly, they can be created,
and in more ways than one.  For example, one might manipulate adjacent storage
locations to form a sequence that can be iterated efficiently, or one might
form a chain of values that are not sitting adjacent to each other by
[https://en.wikipedia.org/wiki/Linked_list%|%storing a value together with the
address of the next value].  In [C], which introduces [type%|%typed] values, the
elements of a sequence must be of the same type so that storage can be
efficiently allocated.  Moving to a higher layer of abstraction, the Tcl take
on a sequence, the [list], discards this constraint, but loses some efficiency
in the process.

Each [programming language] gets its distinct flavour by combining these
primitives in novel ways.  In Tcl, there is only one type of value, [EIAS%|%the
string].  Curiously, in Tcl both [list%|%lists] and [dict%|%dictionaries] are just strings that
conform to a [list%|%certain format], so the seqence and mapping primitives
only exist as
a set of commands that manipulate correctly-formatted values as lists or
mappings.  [JSON], which has become popular lately, provides for the
succinct expression of the data primitives.

The use of each primitive affects storage in some way, and one of the primary
concerns in writing a quality program is the effective management of that
storage.  Thus, whatever level of abstraction one is working at, mastery of the
storage aspects is critical.  Even things that are considered more related to
performance, such as the overhead of variable lookups or function calls, are
still very much about how storage is managed and used.  In Tcl, [copy-on-write]
is one of the key features related to storage, and a good understanding of it
has the power to change the way one writes Tcl programs.

** The Art **

   [https://www.youtube.com/watch?v=lgZ7Cxt5uIU%|%Can Great Programmers Be Taught?], video, [John Ousterhout], 2021-06-21:   Articulates a list of "the secrets". 

[97 Things Every Programmer Should Know], book, by Kevlin Henney, 2010: A collection of short essays on general techniques.
** Values and side effects ** Some commands return useful values, some have side effects, and some do both. The value of `[puts]` is invariant. It always returns the empty string, so it's never useful: ====== set a [puts hello] ====== Therefore, `[puts]` has a side effect, but no useful value. `[set]` has a side effect. It creates a new variable and assigns a value to it. `[set]` also returns the value that it assigned to the variable, which can be useful sometimes. To set two variables to the same value, one could write: ====== set b [set a hello] ====== Therefore, `[set]` has a side effect and also has a useful value. `[string length]` is an example of a command that doesn't have any side effects but does have a useful value. It changes nothing in the world of a Tcl script. It doesn't create or delete any commands or variables, and it doesn't write any data to any channels. However, it returns a value that tells us something we might want to know: ====== string length hello ====== The last category is commands that have no side effect and no value. There are none of these! ** [Computer Architecture] ** [byte]: : [A real problem]: Why real numbers may not work the way you expect them to in a computer program. See also [Computers and real numbers]. ** Fundamental Concepts ** [Automaton]: [Binary representation of numbers%|%binary representation]: [Halting Problem]: [homoiconic%|%homoiconicity]: [scope]: [syntax]: ** Data Types ** [Abstract Data Types]: [Reference%|%References]: ** [data structure%|%Data Structures] ** [data structure%|%Data Structures]: ** Logic ** [Combinatory Logic]: [predicate logic]: ** Functions ** [curry]: [lambda]: [Function mapping]: [Functional composition%|%composition]: ** Program Structure ** [control structure%|%Control Structures]: [proc%|%Procedures]: [Closures]: [continuation%|%Continuations]: [coroutine%|%Coroutines]: [Concurrency concepts%|%Concurrency]: [Generator%|%Generators]: [iterators%|%Iterators]: [recursion]: ** State ** [Static Variables]: [Constants]: ** [Persistence] ** ** Calculation ** ** Processing ** [distributed computation]: [multitasking]: [parsing]: [serializing%|%serialization]: [Data analysis with Tcl%|%data analysis]: [signal processing]: ** [program architecture%|%Design] ** See [Program Architecture]. ** Paradigm ** [ContexTcl: Playing with Context-oriented Programming%|%context-oriented programming]: [dataflow programming]: the next step in a program is determined by the output of the previous step [flow-based programming]: like dataflow programming, but articulates the connections as channels and the inputs/outputs as messages [functional Programming]: program behavior is described as a mathematical function [little language]: purpose-built languages for specific problem domains [object orientation]: encapsulation of data and functionality into a discrete operational entity with a defined interface [Relation Oriented Programming with Raloo%|%relation orientation]: Related terms includeand ''[http://en.wikipedia.org/wiki/Subject-oriented_programming%|%subject-oriented programming]'' and ''[Aspect Oriented Programming]''. ** Communication ** [ipc]: [network programming]: ** Memory Management ** [Garbage collection]: ** Technique ** [Code Generation]: [data is code]: [declarative programming]: [multitasking]: Getting multiple things done at once. [debugging]: [domain-specific language]: [factoring code%|%factoring]: [imperative programming]: [Literate programming]: [Logic programming]: [Profiling Tcl%|%profiling]: [testing]: [Genetic Programming]: ** Methodology ** [Extreme Programming]: [programming by exception]: [test-driven development]: [Zero-Defect Software Development]: ''Not to be taken as meaning "bug-free," Zero-Defect Software Development (ZDSD) is a practice of developing software that is maintained in the highest quality state throughout the entire development process'' ** Security ** [Injection Attack]: [Secure by design]: [Tcl is immune to many "format string vulnerabilities"]: [http://web.archive.org/web/20050410143900/http://m.bacarella.com/papers/secsoft/html/index.html%|%The Peon's Guide To Secure System Development]: ** The Role of Scripting Languages ** [Why adding Tcl calls to a C/C++ application is a bad idea]: ** Topical Guide ** [artificial intelligence]: [algorithm%|%algorithms]: [encryption]: [Graphics with Tcl%|%graphics]: ** More Theory ** The following pages introduce various computer science topics, but don't yet have any other place to live in this table of contents [Scripted Compiler]: [http://cstheory.stackexchange.com/%|%theoretical computer science]: a forum ** The Art ** [The Strange World of Programming]: A foray into ideas, wisdom, and general principles of developing programs and the programmer. [Tips for writing quality software]: [http://www.linusakesson.net/programming/gcr-decoding/index.php%|%GCR decoding on the fly], Linus Åkesson, 2013-03-31: in which Linus solves a longstanding problem by looking at it from a novel angle, and employing trickter and clever code in a very concise manner ** Do's and Dont's ** '''Don't''' [http://thejh.net/misc/website-terminal-copy-paste%|%copy and paste from a webpage to a terminal]: A malicious website might run arbitrary commands on your system. ** Exercises ** [Project Euler]: A series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. ** Bookshelf: Freely-Available ** [http://aosabook.org/en/index.html%|%The Architecture of Open Source Applications]: Some great essays on designing programs. The essay on [http://aosabook.org/en/bdb.html%|%The essay on Berkeley DB] is one good one. [http://programmer.97things.oreilly.com/wiki/index.php/Contributions_Appearing_in_the_Book%|%97 Things Every Programmer Should Know]: A collection of short essays by experienced programmers. Light on code examples, and usually not explanatory enough, but serves well as an index of concepts to read up on. [https://www.infoq.com/presentations/Value-Values%|%The Value of Values] (video), by Rich Hickey, 2012-08-14: A presentation on the role of data and how it's treated in [object orientation%|%object-oriented] and [functional programming%|%functional] approaches. [http://idke.ruc.edu.cn/seminars/phd/2007/11.07/What%20Goes%20Around%20Comes%20Around.pdf%|%What Goes Around Comes Around], Michael Stonebraker and Joey Hellerstein: Provides a summary of 35 years of data model proposals, grouped into 9 different eras. [https://github.com/kdeldycke/awesome-falsehood%|%Awesome Falsehood]: A curated list of awesome falsehoods programmers believe in. !!!!!! |[Tcl Quoting%|%previous : Tcl Quoting]|[Contents%|%up: Contents]|[Tcl Commands%|%next : Tcl Commands]| !!!!!! <<categories>> Tutorial