The Joys Of Programming

Pages

So today, after 6+ years of PHP and ~2 years of C++ and 1+ year of vb6, I've started learning Python...

And I'm having a blast!

As someone that's recently spent time learning C# and ASP.net, it's really great to find the entry level door that everyone can fit through. Even if it is for a language that takes me back to the glory days of learning programming in Turbo Pascal on the 286's in high school. Actually, that's looking to be my preferred method now

Truly, it's amazing how a good book (that's free) can aid in the process. As a seasoned programmer, it's nice to work with simple programs to learn to use a language instead of trying to make sure I get through the tons of information about data types and all the other little details and just get into the meat of it.

Sure, this book might be aimed at people who haven't programmed before, but as someone that has done a lot of PHP and has spend enough time learning other languages, it's been a very liberating change.

Today is one of those days that has reminded me of how much fun programming can be. Sometimes, keeping it simple keeps it fun

So, if you had any desire to ever learn how to program, this is where I would usher you off to Invent With Python.com and tell you that you have absolutely no excuse.

And if you are a programmer, when was the last time you actually remember smiling while writing code? C'mon! Share!

I've been looking forward to the release of The Land of Lisp for more or less the same reasons. I've been (slowly) working my way through Practical Common Lisp, but the idea of learning the language with ridiculous examples seems more appealing.

Programming tends to stress me out. I think it's because most of the programming I've done was for classes I took in the past. However, I remember that awesome feeling when I figured something out/got something to work... such a good feeling.

6+ years of PHP

Well no wonder you weren't having any fun!

Most of my time recently is spent in Ruby, but Python is what I'm using when I'm not doing Ruby (or maintaining old PHP code). True believers of these two languages tend to pick nits at the other one, but I love them both.

I'm not a programmer, and the last time I ever wrote code was, of course, Turbo Pascal (on 386s!) in high school. And it was always a blast, we spent so much time in the computer labs (I know, can you believe it?) trying to come up with our own derivatives of Smaug or Toril (ours were SUDs though, we didn't know how to do multiplayer), or SNES-type RPG experiments when we learned how to program with actual graphics with PCX images made in NeoPaint.

I installed Unity when it became free to try and re-visit that fun, but petered out in the tutorial.

trueheart78 wrote:

So, if you had any desire to ever learn how to program, this is where I would usher you off to Invent With Python.com and tell you that you have absolutely no excuse.

Indeed. Okay, long weekend project: play less Minecraft, and learn some Python.

I love Python but use Ruby a lot at work now. I'm trying to pick up another programming language and for that, I've started to Learn You a Haskell for Great Good!!!

I program in python all day at work and I love the language.

It just has so much stuff built in.

It reminds me of this: http://xkcd.com/353/

I work mostly in Python, too -- after using a mix of PHP/Perl/the new hotness/whatever for various projects, I decided that we should standardise as a company on Python and Java, and it improved things here immeasurably. Our projects come together more quickly and are easier to maintain, both due to the natural strengths of those languages and the fact that we can (and do) reuse quite a bit of code now, and because of all that, coding is much more enjoyable.

The downside to such an environment is that you don't often get that excitement that comes when you start creating something cool from scratch in a new language. I did have some fun doing that the other month at home, though, with something totally different: SuperCollider. There's something very cool about hearing, rather than seeing, the results of your coding.

I only dabble in python, just little test apps to black box test my proper C++ apps. I'm still at the annoyance stage, I'm afraid. White space as scope was a boneheaded idea. were braces really such an anathema? I also find it hard to maintain since the terse structure and loose typing makes it harder for me to see what's going on. I guess I'll like it the more I use it.

DudleySmith wrote:

I only dabble in python, just little test apps to black box test my proper C++ apps. I'm still at the annoyance stage, I'm afraid. White space as scope was a boneheaded idea. were braces really such an anathema? I also find it hard to maintain since the terse structure and loose typing makes it harder for me to see what's going on. I guess I'll like it the more I use it.

Whitespace: brilliant idea, but needs some getting used to for sure. The idea, though, is to reduce noise and friction while developing. Same thing with gratuitous use of parens. Protip: make sure you convert tabs to spaces in your editor, otherwise you are asking for trouble - lesson learned the hard way.

"Loose" typing: you gotta trust the language, which is a hard thing to give up when you are first learning. Also, trust duck typing and embrace "It's better to ask for forgiveness than ask for permission". But again, dynamic typing reduces friction and allows you to concentrate on programming rather than mucking with semantics.

I've been using Python since the mid-90s (1.4 I think), I still enjoy using it more than any other programming language I know (which includes Ruby and most mainstream statically-typed languages). Every new job I make it a point to "infect" the place with Python because it just makes it so easy to get stuff done. My one problem with the language (actually it's with the Python community) is how darn slow the switch-over to Python 3 has been.

I work mostly in C#, but I've absolutely loved working with Ruby and Python. I'm nearly done rewriting my secrets site (see my sig) in Django, after having originally written it to learn Ruby on Rails.

Spent the last day or so writing "Secret Stan", which I figured would be a huge ordeal, but wound up only being 28 lines of Python, most of which is whitespace and test data.

ASP.NET MVC has made me smile recently, combining most of the ease of Rails with C# and Visual Studio. Not to mention it includes jQuery, which is another favorite source of awesomeness.

Great Online Books:

Why's (Poignant) Guide to Ruby (mirror since idiots drove why offline)
Learn You a Haskell For Great Good! (I'm about halfway through this)

Bonus_Eruptus wrote:

ASP.NET MVC has made me smile recently, combining most of the ease of Rails with C# and Visual Studio. Not to mention it includes jQuery, which is another favorite source of awesomeness.

For sure. MVC is a lot more intuitive coming from Codeigniter and PHP than plain webforms.

I'd love to get into some Python, it's just a matter of finding time. At work I'm slowly switching over to ASP.NET MVC from PHP. While ASP.NET has it's fair share of issues (ie, absolutely broken http response codes), it's a very refreshing change from PHP. MVC 3 looks awesome too.

At home, it's more C# and XNA. It's only been about 6 months since I rewrote my web page though, and that's old...

Edit: woot, web host has Django preinstalled even.

Nightmare wrote:

Whitespace: brilliant idea, but needs some getting used to for sure. The idea, though, is to reduce noise and friction while developing. Same thing with gratuitous use of parens. Protip: make sure you convert tabs to spaces in your editor, otherwise you are asking for trouble - lesson learned the hard way.

Tabs as spaces was industry mandated when I started 15 years ago. I'm very against the school of thought that says that "The program which works with the minimal number of lines is the best program". I'm forever having to bash this into the heads of maths or physics graduates who regard it as simplifying an equation. Clarity is all when you're having to maintain someone else's code written at midnight under a deadline 5 years ago, and getting the compiler to find silly bugs for you is a bonus, not a drawback.

You keep talking about, "reducing friction", and I'm not sure what you mean by that.

Nightmare wrote:

"Loose" typing: you gotta trust the language, which is a hard thing to give up when you are first learning. Also, trust duck typing and embrace "It's better to ask for forgiveness than ask for permission". But again, dynamic typing reduces friction and allows you to concentrate on programming rather than mucking with semantics.

Ah yes, well I have trust issues working in the embedded domain. Even Java not letting me have unsigned variables makes my fists itch. It's just a mindset thing I know.

Clarity is all when you're having to maintain someone else's code written at midnight under a deadline 5 years ago, and getting the compiler to find silly bugs for you is a bonus, not a drawback.

Professional developers spend the overwhelming majority of their time reading code. Hobbyist and academic developers don't understand this, because they get to throw away code when it becomes inconvenient for them. When you finally make that connection between being a professional and having to read code for understanding, it fundamentally changes how you write software (for the better, IMO).

PyromanFO wrote:
Clarity is all when you're having to maintain someone else's code written at midnight under a deadline 5 years ago, and getting the compiler to find silly bugs for you is a bonus, not a drawback.

Professional developers spend the overwhelming majority of their time reading code. Hobbyist and academic developers don't understand this, because they get to throw away code when it becomes inconvenient for them. When you finally make that connection between being a professional and having to read code for understanding, it fundamentally changes how you write software (for the better, IMO).

QFT

I think the easiest change you can make regarding how you program is using properly named variables and functions so that it actually makes sense when you read it. Then you can use commenting to state the intent of the code.

I mean, what's a few extra characters between variables? (That is, if you're not trying to milk every bit of memory and performance out of the system)

I won't belabor the point, but I totally agree. Along those lines, I've become interested in not what do various languages let you do, how naturally they let you say it.

As for some times in my coding career that's made me smile:
1) Writing various AI stuff in Clojure. Love the language, and the amazing absence of friction to express yourself. (BTW, I'll be at Clojure Conj if any other GWJ'ers will be there).
2) Writing my own compiler (using lex and yacc), and then writing a ruby program to analyze the source and automatically produce inputs that would exercise the grammar.
3) Writing my first iOS program and seeing in run on that device. Amazing considering most of the abstractions were consistent from all the Mac OS X Cocoa programming I had done.

The last time I was looking at Python, I wanted to write some network-facing apps that would then write into the local filesystem, and I found it very difficult to be sure I wasn't doing something wrong.

I wanted, for instance, to be absolutely certain that I was opening a filename with a string value, and that that value had only correct characters in it. In general, I found that making sure that things were the correct type, and then writing test cases to be sure that they caught the errors, ended up consuming a ridiculous amount of time.

I guess I'm used to the protections in static variable types, and I feel very naked without them. I want to be able to say 'this is a string, this is only a string, and it will forever be a string', and Python just won't do that. So I ended up spending so much time making sure I was being safe that I couldn't get much real code written.

Frustrating.

Malor, PHP tends to be the same way, so I completely get what you're saying.

Sigh, you guys are trying to sweet talk me back into programming aren't you? I used to love programming in C/C++ back in my school days, though I was the jerk that always had the assignment done before it was assigned (our teacher often used incremental upgrades to the program based upon what had been taught that week, I'd often integrated the lesson into the program before it was even assigned as our work, it was the matter of 30 minutes or less for me, so not a huge deal, often I had it finished in class (on paper that is) just needing to be entered into the computer and compiled after class)...

now I want to get around to writing that Sudoku solving program again... grr... mI never did decide between a single run brute forcing the solutions, and just using that list as a comparision chart or actually solving the puzzle as it is given. In the short term the actual solving of the puzzle would seem to be the most intellectually honest of the two methods, but for large numbers of solutions needed the brute force method has a much higher up front processing cost, but from there it is just database matching.

I've read somewhere that you can just represent a Sudoku square as a series of equations, and then just solve them all simultaneously. Brute-force would work, but it's not the elegant solution.

I've been using python for a while now (with the django framework for web apps) and I keep meaning to write something for Pygame. I've tried in the past, but never gotten much further than implementing the basics. I think they run competitions to produce games in 48 hours using Python, if you're looking to get into programming, and like the feel of Python, this might be the sort of thing to spur your interest (rather than the run-of-the-mill programming examples and challenges).

I'm still enjoying Python, and I never realized it can be used with web apps as well. So after seeing how wonderful Django can be to create web apps with, I do believe I've just booked my next in-depth programming language.

If only I could find Apache support for Python 3.1...

Malor wrote:

I've read somewhere that you can just represent a Sudoku square as a series of equations, and then just solve them all simultaneously. Brute-force would work, but it's not the elegant solution.

Peter Norvig has a good article on solving every sudoku puzzle in Python. Good read.

Hah, I love the end of that article:

Why did I do this? As computer security expert Ben Laurie has stated, Sudoku is "a denial of service attack on human intellect".
Malor wrote:

Hah, I love the end of that article:

Why did I do this? As computer security expert Ben Laurie has stated, Sudoku is "a denial of service attack on human intellect".

As someone else who enjoys them, I find his reasoning intellectually bankrupt. It's like saying that any logic puzzle which can be solved through brute force is pointless.

Derail aside, I love seeing people discuss their love of code. I spent my first 6 and a half years in the USAF as a programmer, and after spending 6 months in a shop with no coding mission, my love of coding was pretty much destroyed. See, I spent all 6 months inputting delivery CDs from a contractor into our config management tool(Think CVS, but not). That was my job for 6 months, took me about 20 minutes every *month*. I have a friend who spent 3 years in that shop who completed a bachelor's in business management from SCRATCH, doing nearly all of his classwork at the office.

It's kind of sad to me, since I absolutely loved my college courses(the real ones, not the masquerade that was tech school and my continuation training). They were challenging, engaging and made us think in different ways, plan things out and be critical of design. That I miss like I don't know what.

I always write a Sodoku solver to learn a new language. As a cryptic crossword enthusiast, I regard this as the only way to get an interesting intellectual challenge out of a Sudoku.

It always has a GUI front end with the 9x9 squares, but the numbers 1-9 in smaller squares in each smaller square. Left clicks selects and right clicks remove options from each square. As you select a number, other possibles are removed. I add a "solve" button at the top.

I usually just brute force the solution. I store the puzzle SodokuState object, which as a 3x3 array of LargeSquare objects, each of which has a 3x3 array of :

struct SmallSquare
{
typedef std::set Possibles;
bool m_solved;
uint8 m_solvedValue;
Possibles m_possibles;
};

or the equivalents in whatever language I'm learning.

When you select a number for a given, you set the m_solved and m_solvedValue members of that square, and remove it from the m_possibles set for the squares in its large square, column and row. Then to solve:

(1) Look for sets with only one entry
(2) For each digit, see if it's only in one square in a LargeSquare
(3) For each digit see if it's only in one SmallSquare in the row
(4) For each digit see if it's only in one SmallSquare in the column

After each check, you go through all the small squares and solve ones with only one set. I also do an integrity check to find inconsistencies. I tend to do it as a check, though I see I could do a set union of all the squares I'm checking and just count each number within it to home in on the one to try faster.

This will get rid of most of them. If you come to a point you can't proceed, then you can do a tree search since you can take a copy of the SodokuState object (Shallow default copy constructors work OK because I'm avoiding the heap), and find a SmallSquare with only two options, and try each one to see if you get a solution. If you get an inconsistency, then you can prune that branch and get to the solution. Even the ones marked "very hard" only have one branch point I've found.

I haven't looked to see if there's a better solution than this, but it seems to work OK for me. I haven't done this yet for python. That would be a worthwhile endeavour. Whilst I complain about python and think it's risky for production code, I can very much see how fast and powerful it is for test apps, stubs, and data simulators etc.

Any time a thread like this pops up I get the urge to try learn to code, then I realise I just don't have enough time in the day for the stuff I already know how to do. Never mind learn a new skill.

On a side note, has anyone ever computed the nominal number of solutions for a standard Sudoku? I say nominal because you can swap number set out and still have the same pattern, just with a differen number sequence (i.e. every 5 is replaced by a 9, and every square that was a 9 before is now 5. Puzzle still works)

edit: 5,472,730,538 according to Wikipedia

Mmmmmm... ASP.NET MVC + JQuery. It makes my job so easy.

We're looking at moving our website to Drupal, so I'mma dive back into PHP soon. I want a good framework. .NET hath spoiled me.

Suggestions?

Lex Cayman wrote:

Mmmmmm... ASP.NET MVC + JQuery. It makes my job so easy.

We're looking at moving our website to Drupal, so I'mma dive back into PHP soon. I want a good framework. .NET hath spoiled me.

Suggestions?

Zend Framework looks pretty solid, CakePHP is decent, and CodeIgniter ain't bad itself.

Personally, I'd rather just find something other than Drupal for your website to be hosted in. Might check out Expression Engine and see how it compares (not free though, but commercially supported)

trueheart78 wrote:

I'm still enjoying Python, and I never realized it can be used with web apps as well. So after seeing how wonderful Django can be to create web apps with, I do believe I've just booked my next in-depth programming language.

If only I could find Apache support for Python 3.1... :(

I've built apps with Django, though I mainly work with Ruby (Rails and Sinatra). Django is a really nice framework. It only runs on Python 2.x right now, so no need to worry about Python 3 and Apache for the time being. Use WSGI (not mod_python) for Django on Apache. Also look to Pip, Virtualenv, Virtualenvwrapper, and Django debug toolbar for a nice dev environment setup. Github is your friend for finding a lot of good apps for Django. If you do any development with Ruby or Python, Github is a good place to explore. Besides Git rocks

Pages