Software Development

Seven ideas for learning how to program

When you want to learn to program, taking classes and reading texts are useful exercises, but Chad Perrin says it's not enough. To really learn programming, you need to start writing programs.

Ancient Chinese philosopher Confucius is credited with saying a lot of things, from trite fortune cookie messages to patently ridiculous jokes like "Man who stand on toilet is high on pot." One statement attributed to Confucius that is relevant to people learning to program is:

I hear and I forget.

I see and I remember.

I do and I understand.

Sitting in a classroom is far from the ideal way to learn to program for most people. Reading about the programming concepts at the same time might help, but it does not compare for practical skill acquisition with the effectiveness of reading and thinking about others' source code until you understand it.

Nothing really cements programming skills in the mind like writing programs of your own, however. Read a little, get taught a little, and start programming a lot. Find things you wish were easier, and make them easier by writing some code to automate them.

Unfortunately, figuring out what to do can sometimes be the most difficult part of learning to program. The key, based on personal experience, seems to be to wish you could do something in one step instead of seven or eight, and to have a sudden epiphany where you realize you have an idea how to write a program to solve the problem.

Because starting programmers typically have very limited knowledge on which to draw when looking for that kind of epiphany, it helps to stack the deck in your favor. Doing so, at least at first, involves figuring out what parts of your daily computer use routine most lend themselves to easy scripting. Once you have that sorted out, focus your early learning on programming skills that are particularly useful in those circumstances. To the extent such opportunities are lacking, you may want to make changes to your computing environment that will provide such opportunities.

The most important thing to do is to find a way to motivate yourself to write code. Here are suggestions on how to learn programming by taking action.

1. DBMSes

Major, industrial strength DBMSes such as PostgreSQL, Oracle, Microsoft SQL Server, and Informix offer scripting capabilities via stored procedures or stored functions. Probably the most widely recognized language options are TransactSQL, used by Microsoft SQL Server and Sybase, and PL/SQL, which is used by Oracle. PostgreSQL offers a PL/SQL-like procedural extension to SQL called PL/pgSQL, but it also provides a range of other language options such as PL/Perl, PL/Python, PL/Ruby, and PL/Tcl.

Such opportunities for programming are limited to a particular set of problem domains, but could prove very useful if you are a DBA or if your job involves developing database reports.

2. Plugins

Many new computer games offer the ability to write and load plugins. World of Warcraft, for instance, offers a plugin system that uses the Lua scripting language. Modern Web browsers also tend to offer flexible plugin systems, with Firefox being the most famous and widely used; in the simplest case, Firefox plugins are written using JavaScript. Open source browsers tend to attract more plugin development than closed source browsers, and among browsers Chromium's plugin system is likely to become at least the second most-targeted by plugin developers because of its high-profile marketing as Google Chrome as well as its permissive licensing.

Many other applications have plugin and extension systems that can provide ample opportunities to build your burgeoning coding skills, including even some terminal emulators (see TechRepublic contributing writer Sterling Camden's urlpicker for rxvt-unicode for an example) and console-based text editors like Vim. (In the interests of full disclosure: I have contributed a little bit of code to the urlpicker project.)

3. Practice problems

You can try to solve the problems offered by a generic list of coding tasks designed expressly for the purpose of providing programmer practice opportunities. One of the more popular, regardless of the programming language, is Project Euler, which is "a series of challenging mathematical/computer programming problems". The problems are generally arranged from easiest to most difficult, and there are literally hundreds of problems in the Project Euler collection, so this can keep you busy for a long time.

Other examples include RubyQuiz, which has been a popular attraction of the ruby-talk mailing list for years, and CodeKata, a somewhat smaller and shorter-lived project of Dave Thomas, one of the co-authors of The Pragmatic Programmer.

These options are not as conducive to self-motivated exploratory learning as tasks that actually scratch your own itches, but if you find them interesting, they can serve the purpose of educational programming practice as well as anything else.

4. Smartphones

The biggest new craze in application development is smartphone applications. Such devices typically require the developer to use a specific language to their full capabilities as application platforms, at least to do so in an officially sanctioned manner.

A burgeoning industry of smartphone development frameworks that allow developers to write their code in languages other than the "native" languages of smartphone platforms, that then translate the applications into those "native" languages, is on the rise. Web applications are also gaining traction as a means of writing smartphone applications that do not require learning the official application development language of any particular smartphone platform. Another option for using the language of your choice rather than of the platform's is to use a device like the Nokia N900, which runs a Linux distribution derived from Debian and can run a wide range of software -- including a lot of software that was not originally designed for smartphones at all.

Books and online tutorials focused on myriad methodologies for developing smartphone applications are appearing in droves, particularly for Android and iPhone devices. Some third-party frameworks will "compile" code written in everything from HTML+JavaScript to Ruby or Python into "native" applications for multiple platforms, sometimes including not only smartphone platforms, but also desktop systems. Perhaps most exciting about this situation is that these frameworks and their associated IDEs do not tend to try to solve all programming problems equally well the way major frameworks and IDEs such as Visual Studio and the .NET Framework do. This makes it possible to simplify the development process significantly by narrowing options to an easily managed set of problem domains. The result is a style of software development that can be extremely approachable for beginners.

The downside is that writing new smartphone applications is hardly something you are likely to do every single day while learning how to program. If your smartphone's OS is a Unix-like system (like the N900), however, the same small tool development projects can be useful on workstations and servers.

5. Spreadsheets

If you use spreadsheet programs with a robust macro system, you have a quick way to read code someone (or something) else wrote and write your own code. First, record a macro for a task you perform a lot and that normally takes several tedious steps. Next, look at the macro source code, and edit it to make it better suited to general use. This is an extremely limited approach that will not take you very far, but it might help get you started on the road to feeling like simple scripting is second nature for you.

The most common spreadsheet program for this kind of scripting is probably Microsoft Excel. Excel uses VBA, which is a miserable language, but if your daily work involves heavy use of Excel, this is probably a skill you should have anyway. OpenOffice.org uses a similar macro system that can be used in much the same way, as does its non-Oracle fork LibreOffice, that provides the same opportunities for early learning-oriented coding as Microsoft Office.

In every case, there is a slightly greater barrier to entry for writing code than when writing simple command line shell scripts because of the menu options and buttons that need to be clicked to get started. The overhead for getting started is similar to that of starting a new project in one of the major IDEs on the market, but for significantly smaller "projects". It would be a good idea to ensure this is not the only kind of simple scripting opportunity in your daily development environment, even if making use of it can be helpful.

6. Unix

If you use some kind of Unix-like system regularly, you have a huge advantage in finding ways to exercise your nascent programming skills. Unix provides more opportunity for simple scripting automation than any other general purpose operating system family, thanks to the extreme flexibility of admin scripting on the platform. In the least sophisticated case, an admin script might be nothing more than a series of shell commands saved in a file. Opportunities can be extended from there with simple looping and conditional constructs, input and output handling, file reading and writing, and scheduled tasks.

After getting comfortable with simple shell scripting, it is worth any Unix sysadmin's while to learn how to write admin scripts in Perl, Python, and Ruby. Key skills for such languages in a Unix environment involve accepting text streams via Unix pipes and redirects, processing command line options, reading and writing files, and searching and operating on text with regular expressions. An admin will also want to know the common basics of programming like producing output, looping (or recursing in some cases), and using conditional constructs for programs that make decisions based on well-defined criteria.

Writing command line tools for Unix is fertile ground for opportunities to write programs that make use of a lot of the capabilities of a scripting language. Because of the flexibility and minimalistic requirements of admin script development, writing such utilities can range from the simplest examples of useful tools to robust server processes, and even massively parallel task automation, load balancing, heuristic filtering, and other interesting problem-solving jobs that intrigue some of the world's best programmers.

While some admin scripting capabilities are available in just about any general purpose OS, and quite a few that are more narrowly purposed, some OSes are more equal than others. Unix stands head and shoulders above the norm in terms of its suitability for admin scripting, and because Unix-like systems such as the major Linux distributions and BSD Unix systems share the same basic operating environment design, they all benefit from this richness of opportunity for admin scripting and portability of script between platforms -- as long as you write them to be portable (such as by using sh or Perl instead of bash, and choosing standard sysctl values instead of the proc filesystem for data sources).

This works for languages other than very high level, dynamic, interpreted languages as well. C, C++, Haskell, Objective-C, Objective Caml, and a plethora of other options fit neatly into the task of writing various types of simple Unix utilities. For many of these languages, a more extensive set of skills must be learned to tackle projects even as simple as small admin tools than for languages like Perl, Ruby, and the Bourne shell, but such tasks are still much less daunting to a beginning programmer using these languages than GUI application development, systems programming, and other tasks for which they are often used, especially on other platforms.

In fact, given what the Unix philosophy has provided over the years in terms of a plethora of common utilities that each do exactly one thing (for the most part) and do it well, part of the value of Unix-like environments for the novice programmer is that leveraging the power of the Unix command line environment encourages the user to think more like a programmer than an audience.

7. Web pages

A dangerous recommendation to make is to learn programming by playing with JavaScript. This is not because JavaScript is a bad language, but rather because the Web is already cluttered with myriad abuses of JavaScript for a dynamic user experience, and unleashing an incautious new programmer on the Web might be considered irresponsible. There are positive uses for JavaScript on the Web, and the growing interest in the idea of writing what amount to desktop applications that run in the browser is giving us plenty of reasons to start learning JavaScript early in our programming careers.

The fact that JavaScript's single most common use is for client-side Web scripting also means that JavaScript may be the easiest language to learn by reading others' code. Find any Web page that has client-side dynamic elements, then right click and select the option to view the page's source, and you will likely find it littered with small snippets of JavaScript here and there. For more sophisticated dynamic pages, the (X)HTML page may even reference a separate .js file full of code.

Be careful about the code you write before uploading it to a publicly accessible Web server; make sure it is good before you subject the public to what you have wrought. If you wish to start more locally with scripting that you find useful, browser extensions exist that allow you to apply arbitrary scripts to pages you view -- and that apply only to your personal browsing experience. Greasemonkey for Firefox is one example.

Solicit feedback about your code

Another great way to improve your programming skills is to solicit feedback from people who know more about the subject than yourself, and to learn from the wisdom they share with you. They may not always agree with each other, but if they are worth your respect as good programmers, what they have to say should at least prompt you to think about new ideas and to think about old ideas in new ways.

There are many ways to solicit feedback. These are three possibilities:

  • Start working in a language that has a strong, helpful community, such as the ruby-talk mailing list for the Ruby programming language or the PerlMonks website for the Perl programming language. Join one of these communities (or something like one of them), and learn the culture, the best practices for the language, and how to get the most out of asking for help.
  • Pair with another programmer. Pair programming is a fashionable practice that has gained respectability through the rise of the agile software development methodology. Two people get together to work on a project, but often only one of them is actually writing code at any given time. The pair of programmers switches off who is sitting in front of the keyboard, ensuring that both of them get substantial coding time, while the other basically reads over the coder's shoulder. An ongoing dialog about the code can help ensure that the best way to approach a given problem comes to light and ends up being used. Anyone who has had an epiphany while trying to explain a problem to another person should recognize the potential value in pair programming.
  • Get a mentor. Mentors can be found in language communities, among friends or co-workers, in open source software development projects, and at conferences and conventions with a heavy technological subject focus. School may be another good place to find mentors, in the form of tutors, instructors who take a shine to you, dorm roommates, and even study groups for a less traditional and more give-and-take mentoring relationship. Sometimes, a one-on-one relationship with a mentor can prove to be the single most valuable way to get feedback early in the process of learning to program. If you are lucky enough to get a good mentor, you should take advantage of that resource, and never take it for granted.
  • Create a project on a code hosting site such as Bitbucket or GitHub. Tell your programmer friends, post about it to your Weblog or Twitter account, and generally encourage others to have a look at your code and offer feedback. Make sure that the issue tracker is turned on so that people can submit bugs or propose enhancements through the code hosting site's interface.

Between practicing your craft and getting feedback from people who have insights to offer, you should be able to get well on your way to learning the basics of programming and gaining practical, useful experience at it. Now go forth and code.

Related TechRepublic resources

About

Chad Perrin is an IT consultant, developer, and freelance professional writer. He holds both Microsoft and CompTIA certifications and is a graduate of two IT industry trade schools.

127 comments
jaba8
jaba8

am new to programming please send me programing tips. this is my email kiseka8@yahoo.com please help me

AnsuGisalas
AnsuGisalas

BTW: The following is not spam. I do not suggest you buy anything, nor do you need to. It's just an exercise. This is the CAT-tool I use in my professional work. CAT is Computer Assisted Translation, it's not machine translation, although Wordfast can do that too. So, anyway, the tool is free to download and use, you don't have to get the paid version for what I have in mind: Now, the tool is a MS-Word template. You have to open it in word and follow the instructions to install it. What it does is, it takes your source text, cuts it up into segments of one line, then proffers each segment and a target line to match. You, the translator, then provide a translation for the source segment, and the tool fuzzies the matches. After a while it starts suggesting translations for things you've already translated... if the text repeats itself. It also saves the fuzzies to a TM, a translation memory, which can be used when translating the same language combination later. It saves a lot of time sometimes, and at the very least, prevents one's eye from wandering. So, what I had in mind; you could take something you've written in one programming language, and use the CAT-tool in translating it into another language, (just assign arbitrary national languages to the programming languages in question while setting up the TM, but remember which is which!). It should highlight the differences between programming languages (hint, you can alter the order of the segments (as well as split and combine segments (lines)) as long as you do it when it's not the current to-be-translated segment: you may find you need to backpedal, I often do too). Let me know what you think.

nonimportantname
nonimportantname

the program you hope to create. You're going to get a heck of a lot more gratitude knowing that you created something of moderate to immense value...especially if others feel the same way. Confidence and imagination are the real keys here.

whitland
whitland

I have bought books on the subject (Visual Basic) and even went on a classroom based course a few years ago but I still cannot program and that is mainly because I can never think of a project. There are many sites on the web devoted to VB and generally very instructive. What I would like to see are some projects that the BEGINNER could use to create his/her first programs. Any pointers to such sites would be most welcome. Thing is, beginners are just that and need simple to start with!

Duke E Love
Duke E Love

First start small. Baby steps... nothing will kill a side project like feature creep. Creating a shopping cart will snow ball into something that will take forever. Pick something that you are interested in to begin with. That will keep you wanting to work on it and, well, keep you from losing interest. Build something that you will use and/or make your life easier. My side projects, while excuses to learn something new, generally involve creating a tool that I will use. EX: I am interested in code generation so I created a code generator to take the grunt work out of creating databases CRUDs. This has lead me to learn all sorts of (seemingly) unrelated technologies/skills. It started small with creating basic queries and views from database tables to creating full on applications based on application frameworks. Over the years each new version allowed me to learn something new. I learned about database metadata, SQL dialects and dataypes, jQuery, OOP, complex data structures, data and form validation, MVC, encapsulation, inheritance vs composition, application frameworks, web services, AJAX, ORM etc. etc. And it all started with me wanting a tool to take the drudgery out of writing SQL.

BruceAndShelly
BruceAndShelly

Don't exclude the fun, graphical programming environments intended mainly for children but are more complete programming experiences than most think. You can learn a lot from the fast experimentation and rapid feedback from free sites such as http://scratch.mit.edu . It's the basis for my own teaching in technology. Scratch even has add-ons that let you design your own statements for custom types of iteration, recursion and whatever you might imagine. ( http://wiki.scratch.mit.edu/wiki/Build_Your_Own_Blocks_(BYOB)_(Scratch_Modification) ). Not many "real" programming languages let you modify the language itself!

Vladas Saulis
Vladas Saulis

You cannot BECOME a programmer, unless you already ARE a programmer.

Sterling chip Camden
Sterling chip Camden

Thanks for the linkage! This post resonates strongly with my own learning experience. There is no substitute for getting your hands dirty. When you do, you often hit a road block early on. If you don't give up, it's often surprising just how easy it is to overcome.

AnsuGisalas
AnsuGisalas

Seeing as how my programming experience is at best characterizable as extremely rote... having written (counting language parser writing), what I guess to be less than 500 lines of code, I would like to hear more about more advanced languages... For example, how complex can a line's syntax be? What are the "word classes" of programming languages?

Tony Hopkinson
Tony Hopkinson

tips are only sometimes useful, once you have got your head round the fundamentals.

TobiF
TobiF

1. Delete your email address from the post, unless you're happy to receive tons of spam. 2. Check the internet. There are many sites about programming.

apotheon
apotheon

Are you saying that something like that should be used to translate between programming languages, or that something like that should be written as a stand-alone tool rather than a Word template?

Tony Hopkinson
Tony Hopkinson

If you don't have that desire to automate, or produce small utilities, thne all I can suggest is you pick something something that interests you and evolve it. One of the biggest things I did off my own bat early on was an arithmetic trainers for my kids. Started off as pick a couple of random numbers , display and ask for the sum, ended up as a step by step on screen interactive break down of the working out including multiplication of numbers with decimal parts and long division. as in 1234 x 346 = 1234 x 346 _____ ?00 (3 x 4 = 12 making ? 2 and carrying 1 Ended up being a lot more interesting and challenging than I' originally thought. I got as much out of learning how to do it as they did from learning from it.

TobiF
TobiF

If there's operation you'll need to do more than once, then you should have a script for it. Rephrased: Try to find any repetitive things you do on your computer, and see if you can make them more automated. - Sorting emails - Checking lottery tickets against results - Collecting information from 4 different reports into one aggregated document, then sending it to 10 people via email and 2 people by fax, etc.

CharlieSpencer
CharlieSpencer

I remember being in some seminar (possibly a Novell road show for Suse) and the presenter saying, "And we all know what everyone's first program is: 'Hello World'" I'd never heard of it until then. My very first BASIC class went straight to a gas mileage program - accept variables of miles traveled and gallons used, calculate the mileage, display it as output. My first loop was to repeat the above.

Tony Hopkinson
Tony Hopkinson

produce simple typed classes or structs from a set of tables... :D All programs are automation is something people keep losing sight of.

apotheon
apotheon

You are an excellent example of the kind of "start small, practice often" approach encouraged in the article.

apotheon
apotheon

This is one of the things I like about Ruby (and it is true of Common Lisp and Smalltalk as well): you can modify the language at runtime. I have not played with it enough to be certain, but I'm pretty sure that is especially true of Ruby when using the Rubinius implementation -- a Ruby virtual machine that is written in Ruby. There's an online Ruby REPL called Try Ruby!, and a downloadable Ruby learning environment called Hackety Hack!, too. You might want to give them a look. I'm still partial to Logo as an early introduction to programming for youngsters, though -- particularly the UCBLogo implementation, which is more than just a toy; it's a full-strength high level dynamic programming language. It just has a very friendly syntax and comes with a TurtleGraphics library. Part of the reason I like it so much is that it is a LISP derivative, and teaches prefix notation functional programming syntax while you're at it. It even has a macro system (in the somewhat-Lispy sense of "macro") for metaprogramming goodness.

CharlieSpencer
CharlieSpencer

For a first post, it was well worth the wait. Speak up more often; this is quality stuff.

Tony Hopkinson
Tony Hopkinson

Programming is a skill, like any other it has to be exercised and honed. The basic advice was do and learn, learn and do. Whether you have the gift or not, you'll get better at it, and on that basis the advice on how was reasonable. I mean he didnlt have anything daft in there like take a CS course, or a programming cert.

Tony Hopkinson
Tony Hopkinson

but it's more in terms of abstracts and patterns than semantic freight. If we're talking OO and I use the word class, we are probably (could be a poor assumption) talking about the same thing. Classroom, middle class, has some class, school class, class of 69.... Human language is very ambiguous, english / american is even worse. "HAL, Get me a list of people with perl" Pearl what? Whose people? How do you want the list presented?

AnsuGisalas
AnsuGisalas

Hehehe... sure, that'd be good. But seriously; I was suggesting that people could use it as a game when learning a new programming language; try to duplicate in the new what they already made in another. I have no idea whether the TM would be of use, after a while it should allow for auto-translate of the kinds of segments it already knows... which again might save keystrokes. And since the segments are provided side-by-side (actually bottom by top), it's pretty easy to go through it to check if something's off. Anyway, just thought it might be fun to try, dunno how well it might work, as I don't know enough about enough programming languages.

jfuller05
jfuller05

our JavaScript book had the first project be a hello world project. Yeah, that was exciting. :| Later on, we learned more interesting programs, e.g., calculations, banner ads, and eventually it all led to building a website for a car dealership.

Tony Hopkinson
Tony Hopkinson

I got bored at Hello on a 7 segment LED display in 6502 machine code... :D I think my first basic (with line numbers) program was Calculate how many days since you were born. Generally I just read the example now to get the scaffolding.

AnsuGisalas
AnsuGisalas

was a parser to parse sentences in danish... very limitedly at first, no loops, no crossing descent.

apotheon
apotheon

I'm pretty sure that what Vladas is trying to say is that one cannot really become a competent programmer without first being prone to thinking like a programmer. The skill must be practiced to be developed, but perhaps a certain aptitude -- typically manifest in other areas of a person's life -- is necessary for that skill development process to be productive. I don't know how much I agree with that sentiment, though I know there is at least some truth in it. My significant other has a co-worker who is, frankly, completely without the bare minimum capability for abstract, logical thinking to be able to ever be a competent programmer at any level. This co-worker actually deals with SQL daily, and screws it up regularly. She has difficulty with the most basic concepts, such as the order of nested operations, after something like 18 months on the job. My significant other gets to clean up after her incompetent co-worker -- and it's clear, after all this time, that the co-worker is not only incompetent, but incompetent to learn. On the other hand, someone with the bare minimum aptitude can eventually learn, given enough time and dedication. Aptitude just determines the ease of skill acquisition, as long as you mean minimum requirements, I guess.

AnsuGisalas
AnsuGisalas

Remember that language is subject to evolutionary pressures too, it wouldn't be ambiguous if we didn't need exactly that. Descriptive power on the other hand is a difficult concept to port between computers and human language... I'd say that what I've seen of programming doesn't so much describe as it defines. If you're describing someone, you're painting their picture with words, or a picture of their behaviour patterns or the like. In programming, according to my very limited experience, the closest we get is a set of properties (absolute or relative to absolutes : , =), and all objects to match the set are then included in the identification. When I think of linguistic descriptive power, I think of the ability to perform large amounts of communicative gestures using few or small means. What's OO? Something to do with Objects? With word class I mean the different [i]kinds[/i] of items you can place in the syntax. Like Run(v) and Bake(v) are both verbs, they are members of the V-class. Run (n) and Bake (n) are nouns, they're part of the N-class. Is that related to what you mean by OO?

AnsuGisalas
AnsuGisalas

Whether the intent of "the words what are coming out of my mouth next" or that of "the code what is coming out of my keyboard next", mapping the intent seems to be, in present fact, impossible. At least in such a way that it can serve as a seed for interlingual representation (or metalingual, or translingual). Would be a very cool thing to explore though. I think, if I were to undertake such an exploration, I'd use something formed on the basis of Chinese graphemes; there are enough of them for getting started, and they have the benefit of being individually unique (even when derived from each other).

apotheon
apotheon

You could do something like that. There are at least two problems with this, however: 1. As TobiF points out, you'd lose all the little naming convention hints and so on that makes code readable by compiling and decompiling (to a different language) the code. 2. Perhaps worse, you'd get what amounts to an automated writer of atrocious code, because the resulting code would not be idiomatic of the target language, because the abstractions used tend to be so thoroughly different for different high-level languages. For instance, the block-argument form for iterators in Ruby is substantially different from the recursion typically used in Scheme. Translating from Ruby to Scheme via an intermediate language (which would more likely be C than machine language or even assembly language) would likely result in a Scheme program written with clumsy iterations scattered around rather than elegant recursive routines. Even going the other way would not likely result in use of Ruby's powerful iterators being used; instead, you'd get a lot of for and while loops. Sure, you could learn about the most basic, simplistic syntactic elements of each language by translating code that way, but you wouldn't learn much about the language as a whole, or how to write good code in that language. It is said sometimes that someone who has not adapted to the idioms of (for instance) Ruby "writes Perl in Ruby" or "writes C in Ruby" (or whatever, depending on the particular failures to adapt). This is not a good thing.

apotheon
apotheon

I think these days it would be UML, since that's what people tend to use in place of flowcharts now. That, or pseudocode. Of course, sometimes people use a "prototyping language" instead of UML or even pseudocode, especially in cases where they feel the language in question looks sufficiently like pseudocode. What people more specifically mean by "prototyping language" tends to depend upon their biases.

apotheon
apotheon

Well . . . if I understand you correctly now, you're saying that someone could rewrite ("by hand") programs they have written before in a new language when learning the new language. A lot of people do this sort of thing, actually. For instance, I know that fellow TechRepublic contributor Sterling Camden does this with a game called Rat Race. He has written a Django version and a Rails version for the most recent examples of which I'm aware, but has been doing this for decades. As for writing a program to do it for you -- that's basically how most compiled languages are actually "compiled". A compiler is something that translates higher-level code into lower-level code. It is common for a new compiler implementation of some language to compile to C code, which would then be compiled to assembly language code by an already existing C compiler; this, in turn, would then be assembled (they don't call it compilation at this step) into an executable binary by an assembler. Translating from one very high-level language to another, however, tends to be fraught with peril.

AnsuGisalas
AnsuGisalas

Machine mAchine maChine macHine machIne machiNe machinE Can't you just dump them untouched - like machine translation does with unrecognized parts. Leave them sitting amidst the code as they were... maybe one would need some kind of "skip this..." "...to here" tag? EDIT:Oh wait, I see why that won't do what you had in mind. You'd need a syntax evaluation to see the "roles" of the various parts, and then tag them as such for reinsert into the translation.

TobiF
TobiF

Or you'll lose all comments and variable names...

AnsuGisalas
AnsuGisalas

You can reveal it by sending a text through strange language pairs and see how strange english-language bits are suddenly regurgitated and later reabsorbed, even though english was neither source nor target. But I didn't suggest machine translation of code to code; CAT is human translation with fuzzy-driven auto-filling. But, ahem, how about machine code as your glue?

TobiF
TobiF

In some multilingual machine translation systems, Esperanto or some other synthetic language may be used as the central hub, describing "the essence" of the text. Now, what could serve as such a "combining glue", which would be able to describe "the idea"? In the old time it would be some kind of flowchart, but with all objects and classes flying around I don't know anymore...

Tony Hopkinson
Tony Hopkinson

when I did this, programmable ones weren't invented. (1975) My physics teacher built a computer (as in soldered together), and interested a few of us in computing. The program scrolled Hello across the LEDS, using ROM code he'd written himself. Had to learn a bit more about computers to do it than you do for a modern hello world, and this nut carried it to extremes, like multivibrator circuits. Guy was a genius, though.

Glenn from Iowa
Glenn from Iowa

Yeah, my first program was on an HP Programmable calculator, circa 1978. It did have an LED display capable of displaying alphabetic characters, but I highly doubt I would have even thought to program "Hello world." Interestingly, Wikipedia claims the first published use of a Hello World program was in Kernighan and Ritchie's C book in 1978 (although it apparently came from a internal Bell Labs memo in 1974). I didn't even hear of Kernighan and Ritchie until I started learning C over a decade later, so yeah, I'm fairly sure my first program was not "Hello World!"

Tony Hopkinson
Tony Hopkinson

can be taught program competently. It won't come natural and they may not enjoy the doing, but they are as likely to achieve an acceptable result as us born types when hampered by business exingencies. In fact probably more likely. :( It just came across as if you aren't one or even don't believe you are one, just give up. Set my teeth on edge because there's only one way to find out if you have the knack...

Justin James
Justin James

@gskur - You are right about having to deal with the Excel OM. It's a dog. The sad thing is, the Excel OM is *still* less bad than Word's or even worse, Outlook's. A while back, I was working with Mappoint as a COM control, and it was a bad case of "99% there" much of the time... for example, I could do everything I wanted except to get a high quality image of the map on the screen, which involved printing it to the XPS printer and passing a file name to it... ugly! J.Ja

apotheon
apotheon

I usually try to avoid being this harsh, but the fact of the matter is that you're a petulant child who takes it entirely too personally when someone criticizes VBA, gskur. There's evidently no hope of having an actual discussion with you about the subject. Good luck with that narrow mind of yours.

gskur
gskur

Of course you should know, writing on this topic, that NO MATTER WHAT YOU DO you end up dealing with Excel Object Model, VISTO or anything else... so you get different programming UIs--big deal--still the same as VBA; and, besides, code is cheap anyways: one line or 10 lines--it matters how it runs when it is compiled. Also, you really need to understand the Object Model to be effective and efficient--and this is what most "experts" lack and, as a result, throw their hand up in frustration and blame it all on VBA. Shame, this is... Grow up, kids.

Justin James
Justin James

@SinisterSlay - Actually, you *can* load the Excel DLLs and program against them. It's just a really bad idea in many scenarios. The biggest problem is with server side stuff... do you really want to shove Excel into memory anytime someone hits that page (especially if it's a common page)? And there have been all sorts of performance problems. For example, running it as a server app forces Windows to load a desktop session, but each desktop session never gets exited, and each request creates a new desktop session, causing a memory leak. @gskur - I understand where you are coming from about VBA being the "only" tool for automatic Excel. Except, that's incorrect. If you are talking about pure, in app automation, it's right. But there are plenty of ways to manipulate Office applications. You can use the Visual Studio Tools for Office (VSTO) package, for example. There are a number of libraries to manipulate Office documents without starting the associated application. You can have a small VBA application bootstrap another application to do the real work. In other words, there is no mandate at all to use VBA. It sounds like we all agree that it's not a good language, and in a lot of scenarios, using it makes sense despite it's issues (I made my living like that for a while). But it's not the only way to work with Office, thankfully. J.Ja

nwallette
nwallette

He said it's NOT IMpossible. :-) Though, honestly, rather than trying to set up a whole .NET-based stack of crap, I would just use VBA and get on with it. Simple stuff is still fairly easy in VB-based languages. It's just difficult to go beyond trivial uses. The language's limits start to show, badly. If you're such a "programmer" that you can't comprehend scripting languages, you're just as bad as a scripter that can't (but tries to) program. (

Slayer_
Slayer_

Forgive my lack of knowledge of other languages, but can you not reference the excel DLL's and use their API to control Excel. I do it all the time from VB6 and VB.Net. Cannot non-Microsoft languages do it?

apotheon
apotheon

SinisterSlay Nope. I wasn't talking to you. Nope. I wouldn't suggest making a whole class out of a method like that. Sorry about your employment conditions. It sounds like the situation sucks. gksur Nope. It's not impossible to programmatically automate Excel with a language other than VBA -- not since .NET came along. .NET offers APIs for Excel that allow any and all .NET languages to interact with it, including IronRuby. Nope. "Needing" to cram a lot of automation into Excel is not a good excuse to use VBA, even if VBA was the only language that could do it. When you start "needing" to cram a lot of automation into Excel, that's not a sign that VBA is needed; it's a sign that Excel is the wrong tool for the job. It actually is worth mentioning that VBA sucks, if only to warn new programmers away from deciding that VBA is representative of programming in a more general sense in some way -- which is quite central to the point of the article in this case. In fact, people who want to actually learn to program should be encouraged to use something else as quickly as possible, so that they do not end up permanently brain damaged by using VBA as the only example language for their programming practice.

gskur
gskur

I never said VBA did not suck majorly, for it does (but not necessarily quite the way you think/say it does)... Anyways, try your beloved Ruby, or C(any flavor), or Java... or even VB.Net (for that matter) to automate complex Excel tasks/procedures and you are... where? That's right, man... There are thousands of companies and millions of people that use Excel, and quite a few use it at a level that absolutely needs "programmed" automation (not the stupid "macros") to become a viable app. You, if you have this job, is stuck with VBA. THERE IS NO ALTERNATIVE, to the best of my knowledge. Bashing VBA, therefore, is just as pointless as praising it. Using VBA for anything else is TOTALLY IDIOTIC!

Slayer_
Slayer_

Please know I meant no disrespect. In VB, if you wanted something that always had a new instance of the current date formated a certain way, you would write a function. I suspect that solution would work in nearly all languages. I suppose if you wanted to be OO overboarded, you could make a slash_date class and keep creating new instances of it. But this is why the same programs over the years, require more and more memory and CPU, to do th eexact same things. I miss working in a language that has constructors.... its extremely difficult to make black box code when classes need public prop's set before they can be used. A constructor solves this issue by requiring you to fill these needed variables. If only our company wasn't stuck so far back in the past.

Tony Hopkinson
Tony Hopkinson

current_date = date (you get 11/11/2010, if you do it today); No you don't that's Format(current_Date,"dd/MM/yyyy") or possibly Format(current_Date,"MM/dd/yyyy") This is even simpler than Ruby; or try this current_date = format(date, "mm/dd/yy") (you get 11/11/10, also today); Nope that's "11/11/10" or this current_date = format(date, "mmmm/dd/yyyy") (you get November 11, 2010, yes, still today) Nope, wrong again, that's "November 11, 2010" A string is not a date. Some strings can be converted into dates, if they follow a known and unambiguous format. Thanks for reminding me about one of the reasons why I thought VB sucked. Rule one, never ever ever rely on implicit type conversions.

apotheon
apotheon

OOP knowledge Anyone with any reasonable level of experience with object oriented programming should have some basic knowledge of concepts like initialization methods (in this case, Time.new) and chained methods (tacking .strftime onto Time.new to operate on the output of the new method). Being ignorant of languages with which you are not familiar does not make you dumb, and I never said it did. On the other hand, toying around with exactly one language (or closely related language family, such as VB/VBA/VBS) does not really qualify as real practical experience with programming in a general sense. It just means you're a single-language coder, whose knowledge of programming is extremely limited, and who is in no position to effectively argue against claims to the effect that your one and only language is kind of a crappy language. VBA date formatting > try this, o the ignorant one Sure, you can simplify it if you don't want something reusable. My intent was to offer an object-oriented approach that is trivially turned into something reusable, that with minor additions can produce new values as needed. For instance, doing so in Ruby might involve this: def slash_date Time.new.strftime("%m/%d/%y") end You can then call slash_date as often as you like, getting an appropriately formatted current date string over and over again, using nothing more than this: slash_date Note that both the method definition and calling it are extremely minimal, yet extremely clear and highly flexible. To create a version of that same method that can actually accept different format strings, use a default value: def slash_date(form="%m/%d/%y") Time.new.strftime(form) end You can still call it with the default value in exactly the same way, and it's all object oriented. With only the most minor alterations, slash_date can be attached to any class you create, any subclass of Time, or to the Time class itself. Meanwhile, with VBA, your options are either incredible, ugly complexity, or non-OOP approaches that lack the kind of modular code architecture for which OOP is the only mechanism in VBA -- a language that lacks alternative encapsulation mechanisms such as lexical closures, module namespaces, and so on. The only ways to modularize your code in VBA, as far as I'm aware, are classes and methods with obscenely complex syntax, simplistic functions, and crap like Excel spreadsheet cells. If your argument is "Well, you could do it with VBA functions instead of objects and methods," then yes, you need to say more. It's not much of an argument.

gskur
gskur

current_date = date (you get 11/11/2010, if you do it today); This is even simpler than Ruby; or try this current_date = format(date, "mm/dd/yy") (you get 11/11/10, also today); or this current_date = format(date, "mmmm/dd/yyyy") (you get November 11, 2010, yes, still today) So that's why VBA sucks? Need I say more?

Slayer_
Slayer_

Though, in VBA, it would have been much easier to do this cells("1","A")=format(now, "MMMM d, yyyy")

nwallette
nwallette

> Are you saying that it looks like I'm > assigning nothing to a variable? If so, I > think you simply lack any practical > programming knowledge. I dunno, but at first glance (not knowing the language your example was written in) it looked to me like you were formatting a date, but hadn't specified a date to format. I know Perl allows you to leave out all kinds of "crucial" detail, and it will supply its own from whatever it thinks is best in that situation (like using the $_ variable, or the current time, or what-have-you), so I assumed that's what your one-liner did as well. But someone coming from less DWIM languages would see the crash test with no dummy. Doesn't make HIM the dummy. :-) Or it makes me a dummy too, maybe. Which could be. It would explain the yellow and black triangles on my temples.

apotheon
apotheon

SinisterSlay I do not know what you mean by this: > You're making a date? Of what? In both cases you appear to be doing a variable assignment of nothing. Are you saying that it looks like I'm assigning nothing to a variable? If so, I think you simply lack any practical programming knowledge. For example, I can fire up rbx (the Rubinius VM) interactively and feed it my Ruby example code: :~> rbx irb(main):001:0> current_date = Time.new.strftime("%m/%d/%y") => "11/09/10" irb(main):002:0> puts current_date 11/09/10 => nil Does that make it any clearer to you? Everybody, re: Collections What Justin means by "collection" is also known in various contexts as a "hash", "dictionary", or "associative array". An example of creating a hash (Ruby term for a collection), then checking for the existence of some key-value pair in the hash, checking by key name, might look like this: foo = {:one => 1, :two => 2, :three => 3} if foo.include? :two puts foo[:two] end In this case, it will output the value of foo[:two] only if it exists, and will otherwise not even try. You can use the Hash.include? method to handle default values, too: unless foo.include? :two foo[:two] = 2 end In that case, it will assign the value 2 to foo[:two] only if foo[:two] does not already have a value. You can do the same thing when checking for values as for keys, using the Hash.has_value? method. The Array.include? method in Ruby tells you whether the specified value is in a numerically indexed array, too -- so you can check for things by value, and not just by index, in arrays in Ruby. Some languages, alas, cannot do some (or any) of this stuff without some ugly work-arounds. Hopefully that helps clear up some of the confusion here.

Justin James
Justin James

That's actually NOT what I'm talking about. I'm taking about a collection, where the "index" is a string value, not a number. For example: customers["Steve"] = 5 As such, you can't just say, "gee, I'm trying to access the 10th item and the array is only 5 big". You *need* to know if there is an item in the collection with the key "Steve". Trying to access that item if it doesn't exist will blow up. Every other language on the planet lets you say something like: if (collection.exists("Steve")) ... But not VBA. Instead, you need to do: found = false foreach key in collection.keys if key = "Steve" then found = true exit loop end if next if found = true ... Talk about limited and miserable! Or you can try to access "Steve" and catch the error, but that doesn't necessarily tell you if "Steve" exists... J.Ja

Slayer_
Slayer_

Though you can declare an empty array, as my example showed, and check it, how you check it is just plain stupid. Checking the "length" makes much more sense. However, I have yet to need to check if an array has not really been created yet in practical code. Most of the arrays I use hold a fixed number of values. And dynamics usually end up being collections of objects such as looping through files, or open sheets. Also, I remember reading that you should use the Copymemory API to copy an array quickly or resize an array. I have never actually tried this though.

nwallette
nwallette

OK, so you obviously have some familiarity. ;-) I know about redim preserve.. but that's not the point. Take, for example this Perl statement: my @array = (); In Scalar context, Perl will return the length of the array (# of items). In this case, that would be 0. The equivalent in VB is: Dim array(0) as String This gives you an array with one element (index 0). There's no way, AFAIK, to define an empty array. So in Perl, I know my list has 0 entries. I can use it as a condition in a While loop, or quickly check and report on its contents. In VB, I know my array has one item, but I don't know if that's because it's still "virgin", or if the first entry is just = "". I didn't know about the double-negative trick there to check if it's a valid variable. If I ever have to touch VB again, that may be handy. Do you get my point though? VB is just so damn clumsy. Everything is so much harder than it should be, and you're constantly fighting the language to get it to do what you want.

Tony Hopkinson
Tony Hopkinson

of an array is expensive in any language. Allocate a new bigger block of ram, initialise it and then copt the current one into it. redim et al is an optimistaion trade off, well in languages that provide other constructs... They should be extremely infrequent, that way the redim cost is subsumed by the access speed by writing to a contiguous block of memory with essentially a bit of pointer arithmetic.

Slayer_
Slayer_

Unsure I still dont understand with collections, can't you just check if they are empty? As for dynamic arrays in VB, they require a bit of obscure code. To check if an array has every been Dim'd propery Dim sTest() As String If (Not (Not sTest) = True) Then 'good array Else 'bad array End If And to dynamically size an array, just enter it like a normal declaration, but in your code body. ReDim sTest(1 to 10) as string If you need to expand or shrink an array without loosing the data, use the preserve keyword. This is VERY slow to process. ReDim Preserve sTest(1 to 100) as string

nwallette
nwallette

Are you familiar with arrays? Basically, any group of like objects (integers, strings, "objects", whatever) that can be individually referenced by an 'index' number, like: number_two = my_array[2]; (Forgiving that most arrays start at index 0, of course.) Anyway... I don't have much experience with VBA, but I have programmed in VB proper. Same story there. I'll give you my example of how much this brand of arrays sucks. In most languages, you can define an empty array. It has no indices, i.e., contains 0 items. You can check this by some built-in function to return the number of items (or length), which will probably say "0". In VB, you have to define the size upfront. (Not in and of itself a sin, as this is common in many languages to allocate the necessary memory.) But you can't define an empty array, so even an array with no items still has a size of 1. So, how do know if it's empty? You can skip index 0 and start counting at 1 (which will throw everyone for a loop because programmers are used to counting from 0); You can check if the 0th index contains anything. But what if it contains something that happens to be nothing? (A blank entry, if you will.) Then, there's ambiguity about whether it hasn't been initialized yet, or if it purposefully contains "nothing". What these guys are complaining about is slightly different, but a similar irk. When you have a series of objects in a "collection" (an array), and you want to examine their contents, there will be times when there's nothing there to examine. (An empty set ... like a list enumerating installed modems, for example, in a computer with no modems installed.) This is not a big deal. We expect to find empty lists. But the way to deal with them in VB (etc.) is to try and access it anyway. This will fail. So you have to set up an error-trap to catch the failure. Most languages make this a little less tedious by providing a function that tells you whether there's anybody home without the required brute force of taking a blind leap of faith.

Slayer_
Slayer_

Can you explain that more to me? I am not sure I understand.

Slayer_
Slayer_

You're making a date? Of what? In both cases you appear to be doing a variable assignment of nothing.

Sterling chip Camden
Sterling chip Camden

... is what more recent languages have been trying to achieve -- although Lisp does a pretty good job of it already, especially for a language that's more than 50 years old. In functional programming languages, functions (actions, verbs if you will) can be passed around as objects (nouns), and the result of a function can be another function. OOP allows a group of these functions to be gathered around an instance of the data on which it operates -- or to put it another way, an object represents a set of shared states for a group of functions. The pitfall of languages like Java that require you to always start from a class of object is that you end up creating objects just to encapsulate functions (methods), so you end up with "-er" or factory classes -- a useless breed of objects whose only raison d'etre is to call one function. On the other hand, languages that have no concept of instances of objects make it difficult to maintain independent sets of states, or encapsulation of those states, where more than one function needs to access them. The key is always to use the right tool for the purpose, of course. So when functions need to share state, that makes a good candidate for a class of object. Where classes only call one function or don't require independent state, they're unnecessary complexity.

Tony Hopkinson
Tony Hopkinson

Iterate through a collection and if there are no items you get a File Not Found exception. No count, no exists, all you can do is catch it. Pathetic drivel.

Tony Hopkinson
Tony Hopkinson

Yep you can certainly do that in OO. It can be a very useful way of describing a behaviour 'common' to different groups of things. You have choices dependant on intent though. You could have a class Noun with an instance of Run which implements say IPlural which is a thing Nouns have. You could have a Class Verb with an instance Of Run which implements Iing (e.g. Running :p ) Or you could have a class Word with an instance of Run which Implements INoun and IVerb. Or you could have Class Characters, which implements IWord, IVerb, INoun, etc making it clear that not all sequences or characters are valid words. This is descriptive power, you can describe what you want the compiler to do, without making your intent ambiguous to those who use your code.

Tony Hopkinson
Tony Hopkinson

Though it certainly would have had an accessor, so you're technically correct that it's a method. It was off the cuff, in fact it contains a really glaring error, no check that there is a child called "Peter" An error I try very hard not to make in a real design. :p I've been doing a lot of stuff with on the fly structures and hash tables recently and I think it fell out of that. Four systems all with a thing called event, where after some furking about I discovered that the only theing they had usefully in common was the name event. I'd reached for my OO hammer and treated them all as one thing, very irritating..

Justin James
Justin James

... are even more exemplified by the inability to check for existence in a collection. Trying to work with an object in a collection that doesn't exist will result in a null reference error (as it should) but the only way to see if the object is actually there is to iterate through the collection's keys and see if what you want is there. That's bloody pathetic. J.Ja

AnsuGisalas
AnsuGisalas

It took me a while to digest those ;) Did I understand correctly that the object contains both [i]what[/i] it's supposed to deal with, and [i]how[/i] it's to be dealt with? The "word class" term I used apparently has given rise to confusion... the classes you describe sound to me like sentence types (i.e. declarative, interrogative, imperative etc.) if we allow for a very large amount of substitution of parts within the exemplifiers of the classes. Did I get that completely wrong? With word class I referred just to the different kinds of recurring parts of language, and I meant to ask what kinds of recurring parts of programming languages are there? What I remember of programming, there were data arrays, functions, variables and calls and the like. So I was thinking about how in natural languages we can transform a word into a word of a different type... sometimes creatively (i.e. with no call to a previously agreed-upon derived word). That's what I was wondering about, how much of that kind of mobility is possible in programming. I remember coding stuff very clumsily, if I wanted to perform a function on the product of another function I'd have to write out the code producing and naming the product, then write the code performing the desired function on that product, calling it by name. Of course, that was probably Fortran or Comal 80 or something. But what I remember wanting to be able to do was a parallel to the sentence "Take the cake out of the oven when it's done [baking]"... which convolutes a number of actions. It's baking, watch it/keep track of time, evaluate it's doneness, act when it's done. That was probably poorly worded ;)

AnsuGisalas
AnsuGisalas

Programming isn't done with human language, which is one of many reasons why speech recognition will never replace the keyboard. But what I was thinking about was more along the lines of how much of what we can do with words has been transferred into programming. Like, would there be a point in having derivation for programming? As an example, in language X; you can take a noun, slap on an ending -xa, and get from that a verb-class word that has a meaning to do with the use of the item referred to by the noun. Similar means in other languages form nouns from verbs, (which could refer, for instance, to an instance of performing the action referred to by the verb; e.g. to present > a presentation). Is this already in use? From what Chad wrote in his reply to me above I think maybe it is... but I don't know how widely something like that is available.

apotheon
apotheon

Is it just me, or is making "Child" a method of "Mother" just a monumentally bad idea? This is staring to look like the Kingdom of Nouns. Sorry -- I guess I should be so critical of off-the-cuff examples like this. I just find that particular manner of composing an object oriented system pretty unwieldy and fugly.

Tony Hopkinson
Tony Hopkinson

Code has effectively two audiences the compiler / interpreter and the coder. A bit off of OO Mother.Child["Peter"].Age = 16; Now you an me we could take a wild guess at the intent of this code given a context the application it's in. We know Peter is name, we could take a gues at gender and might assume 16 is his age, or perhaps shoe size. The compiler how ever doesn't give a stuff. A.B[Foo(16)].a = 2^4; would have done it just as well as would Father.Son[0].Number = 16; Descriptive power in programming is about communicating intent to the coder. The compiler gets it's intent from the definitions of Father, Son, Number, String and Int... Any guesses and asumptions are those of the the ople who defined the programming language and implemented the compiler, and I can tell you from bitter experince you want that to be as close to none as possible. This is a pascal classic. If Condition1 Then If Condition2 Then DoOp1 Else DoOp2; The delphi compiler assumed the else was for Condition2, but indented wich is a communication to the coder it was written. If Condition1 Then ...If Condition2 Then ....DoOp1 Else ...DoOp2; Incomprehensibility / assumptions cost when coding. Always and without exception. Human language programming would require an AI, and it would still get it wrong for the same reasons we do when discussing requirements.

Tony Hopkinson
Tony Hopkinson

Loose thinking bumping in to strong typing would have sorted that one out. Well spotted sir.

AnsuGisalas
AnsuGisalas

Ambiguity allows us to describe an unlimited experience space with a limited set of variables. We let the individual signs affect the interpretation of the coocurrent signs, so, that instead of having to nail down every possible variable we can just make the desired interpretation the most likely one. We can say "he's a piece of work" and that single, almost non-informative sentence (given that there isn't a single meaning for any of it's parts), provides an amount of information and judgements that it would take a whole page to write out explicitly. We never speak in un-connected noun phrases, which indeed would be hard to decipher; there's always context, and our output is designed to bounce off that context for a specific effect on it's journey to being interpreted by our intended audience. This will hit A, come into conflict with B, leading to a tilt towards C, which will raise an associative shortcut to D...

apotheon
apotheon

I think Scooby would be an instance of Great Dane, not its class.

apotheon
apotheon

I think people talking about how "everything in Linux is an object" are: 1. kind of stretching things a bit for the sake of a mediocre metaphor 2. probably so thoroughly buried in the world of OOP that they wouldn't notice the benefits of other programming paradigms if they drew blood OOP is actually an extremely useful and, in some respects, "powerful" way to model the solutions to problems when programming -- as long as it isn't treated as the hammer for which everything else is a nail. Sometimes, other paradigms are a better fit. Java is an example of what happens when enthusiasm for OOP is taken a bit to far in somewhat the wrong direction. Another extremely useful and "powerful" programming paradigm is FP, or functional programming. Anyone serious about learning to program ignores the benefits of FP at his or her own peril. Sadly, most people who avoid FP never know how much that hurts them. Another is declarative programming, which is in fact basically what one does with SQL. It has its uses, but from what I have seen thus far it is slightly overused in some ways. VBA is a language that imposes a lot of boilerplate and complexity overhead for very little return on the investment of effort, resulting in something very difficult-to-read for any nontrivial block of code. It inherits this from Visual Basic, of course, which is a similar but somewhat differently miserable language. Another problem is that VBA is so exceedingly limited in its capabilities that it imposes even more ugly code because painful work-arounds must be employed to approximate the capabilities of other languages at times, including even Visual Basic. Here's a simple comparison for you -- a means of producing a date in the format MM/DD/YY, first in VBA: Selection.InsertDateTime DateTimeFormat:="dd-MM-yy", _ InsertAsField:=False, DateLanguage:=wdEnglishAUS, _ CalendarType:=wdCalendarWestern, InsertAsFullWidth:=False Note that in VBA the underscore character allows a single "line" of code to wrap lines so it will all fit on the screen. Now, let's look at Ruby: current_date = Time.new.strftime("%m/%d/%y") That's it. Note that these do not do exactly the same thing, because the VBA example is operating within an Excel spreadsheet, while the Ruby version is operating within, well, whatever program needs it. I added a variable assignment to the actual date generation code for purposes of giving it some assumption of practical context, but really only what follows the equals sign (the assignment operator) is relevant to generating a date. As far as I'm aware, assigning the output of your date generation in VBA is inseparable from actually generating the date, so the variable assignment seemed to be "only fair" -- except for the fact that Ruby's date generator is much more flexible in that you can do any number of things, and not just assign it to a variable (or equivalent).

CharlieSpencer
CharlieSpencer

All of my training is B-OOP (Before Object Oriented Programming), and I almost no concept what OOP involves, even after your 30,000' overview. Or, just barely possibly, it's what I was doing all along but without the formal terminology attached. I'm so far out of touch I wouldn't know bad code if I saw it. I wonder if that's why I don't get it when people tell me everything in Linux is an object? Oh, before I forget: Chad, what don't you like about VBA?

Tony Hopkinson
Tony Hopkinson

Bear as in craps in the woods or Bear as in a cross easy to sort out Good as in... Right as in... Moral as in... Descriptive power in OO run the verb would be a method on an instance of say the class Horse, which itself might be a descendant of a class Equine... Equally it could simply be a property. PerambulatoryMode {stationary,crawl, walk, jog,run} Descriptive power in programming languages is about being able to say what you mean easily without ambiguity. Older languages relied on nested complexity or huge unwieldy constructs. Verbs and nouns could be classes, or members, or types, or interfaces, depends on how best to describe what you are after. But class in OO terms is a concrete description of a thing which you use to create instances of it. ie Fido and Scooby are instances of the class Dog. Scooby being a class of GreatDane which is a descendant of Dog is irrelevvent a class is the thing you create instances of an object from.

apotheon
apotheon

He was speaking of "Object Oriented" programming, often abbreviated as either OO or OOP. A "class" in OOP jargon is a programming construct that acts essentially as a template or recipe from which a particular type of other programming construct is created. For instance, in a program I have written (and am still writing; like art, software is rarely finished -- only abandoned), I have defined a Dstruct class (pun intended). Using that class, I can parse the contents of a file that uses a particular format to produce an in-memory complex data structure that conforms to specific criteria, and generates an "object" (another term of art for the OOP paradigm of programming). That object, then, consists of both that data structure and a set of routines that operate on that data. Those routines are essentially "function" in the sense used by procedural programmers, but because they are attached to a data structure within an object, they are called "methods" (more jargon). Thus, an object is (at least in practice) a set of methods attached to some data. If I create an object of the Dstruct class called d_list, I might access some part of its contents with the method find_missing_keys, which checks the list of top-level datums in the data structure d_list contains against all references to such keys within any sub-structure of the data structure; if there is a key indicated in one of those substructures that is not a top-level key, it adds that key name to the output of the method. Calling this method would look like this: d_list.find_missing_keys Object oriented programming is a programming paradigm (or methodology, to be more prosaic about it) wherein objects and methods are central to the practice of modeling the operations a given program is meant to perform. The inventor of the term (Alan Kay), after having seen heaping monstrosities of OOP languages like Java, and software written in a style that focuses on the objects themselves too much, has lamented that a lot of people get the idea of OOP wrong, and things might have gone better if he had called it method-oriented programming or message-oriented programming. By the way, "message" is a term related to "method" in OOP. The method is the "function" attached to the data inside an object. The message is the code you write that requests the object run that method. I suppose you might say that messages are verbs, objects are nouns, and classes are Platonic forms or archetypes. Basically, Kay was saying that what we should be doing is verb-oriented programming with nouns, not noun-oriented programming with verbs. I hope that helps clarify the issue of what is meant by "class", and some related terms, for you.