Entries Tagged 'General Programming' ↓

Controllers in programming - why?

What is the point of a controller? I’ve never had a good explanation of that; and code I’ve seen for them seems to be something that could have been rolled into a different file, and mostly didn’t need a separate class to do either.

Apart from seeing them around on the web (all these files called SomeLongStringController.jsp) I first came across them mentioned on the “SitePoint forums”:http://www.sitepointforums.com/[1] and then in “Booby”:http://www.nauta.be/booby/

So, can anyone explain? Or is it a fashionable way to overdesign your program, to keep in with the latest Java OO crowd (and those who think Java has to be best and PHP should be programmed like it)? Is it suited to data-centric modelling (not totally sure of that term’s definition, but I believe that’s what I drift towards)?

fn1. I can never decide if people there know what they’re talking about, or have a little knowledge and he who talks loudest/can be bothered to post gets set up as an expert - as I don’t see many active in mainstream PHP projects. Which is why when they start using Controllers I’m a little suspicious :)

Time for a scripting compiler (or why traditional languages look so tempting)

I’ve been playing with Python a little to build GUI programs. Why I chose Python I don’t know - I have a fully licensed copy of Visual Studio.Net on my hard drive (at least for the next 2 years), which would have been more practical to learn (I’ve decide I do like visual GUI builders). Something about not using Microsoft I guess, deep-ingrained in my dislike of their pricing structure (even though I have VS.Net for free).

Anyhow, my experiments (very basic though they have been) led to a small application for my Father to use to process newspaper articles for Grandad’s text-to-speech converter. All fine and well; it didn’t take long to write using “PythonCard”:http://www.pythoncard.org/ and works reasonably well (although the textarea provided by PythonCard cannot cope with long articles, and cuts them off, which has annoying consequences if Dad doesn’t spot this).

And so I’ve enountered the problem that has I believe held up the adoption of scripting langauges in “serious” application development: there’s no neat way to distribute the finished product.

I had set up Python/Pythoncard/WxWindows on the computer at home before leaving so Dad could run the application. A couple of weeks ago I got an email saying “I took the program file into the office but it won’t run on the computers here. Why?”. One email later and I’d elicited the fact that he took the @.rsc.py@ and the @.py@ file into the office but hadn’t installed Python.

While it wouldn’t have been difficult to walk him through the installation of Python et al, he didn’t have the time to spend getting it set up (as well as an impending computer move), and so cannot use the program at work.

I know that people have developed packaging systems for python (such as “py2exe”:http://py2exe.sourceforge.net/ and “pyco”:http://www.pythonapocrypha.com/projects/pyco/) and I could use those, but for such a tiny program it seemed like too much effort (to learn to use one of them would have taken longer than writing the program - OK, I’m lazy!) they still produce larger files than an executable version would. Not particularly important in this case, but the increase in size would be very noticable. Plus, the script stores its settings in a file, and from a quick look at the packagers there’s no way to allow the user to edit one of the files in the package in a text editor.

Laziness is something I could overcome (I guess :)) but for other uses of Python that I’m planning, such as physics simulations/teaching material, size does become a much more important issue. As does performance obviously, but for teaching the ease of use of the “VPython”:http://www.vpython.org library outweighs the drawbacks (even if its graphics are pretty horrible, at least it works!).

Traditional (compiled, statically typed) langauges are starting to look more and more attractive. Sure, they’re harder to develop, and slower (unless you’re well-versed in them) but the tools available are more advanced, and distribution (for one platform at least) is much easier.

What would really set scripting languages centre-stage is an efficient compiler/packager. I’d love to get the equivalent of a Delphi single-executable program out of my Python code.

Build the compiler/packager into an IDE, complete with GUI builder equivalent to Borland’s Delphi (or Visual Studio) and think what a potent tool you have for attracting developers. Fast development (as Python always provides) coupled with the comforts and benefits of a traditional language. Oh, and to have a cross-platform IDE with the ability to package for any platform (not Just MS Windows) would be excellent.

Think I’m misguided, or plain wrong? Then leave a comment. I’m happy to be corrected :-)

C compilation: who wants a challenge?

Will any kind soul compile a program for me?

I spent yesterday evening trying to compile the CVS version of “rtf2latex2e”:http://sourceforge.net/projects/rtf2latex2e/ on Windows XP - firstly trying the supplied Visual Studio project, then using “Dev-Cpp”:http://www.bloodshed.net and trying to hack it myself. Ended up with a whole pile of linker errors about undefined constants; I’d show you the exact messages only I’m now getting compilation errors…

Now granted, I know virtually nothing about C (other than that taught in a 1 semester course) and absolutely nothing about compiling it/creating projects/using gcc (none of this was taught - everything was single file so compilation was straightforward ‘hit button with exclamation mark’). Which makes me think I’m probably doing something very stupid :-)
Anyone fancy the challenge of building it on Windows? I’d thank you for doing so! In case you’re wondering; the obsession with such a wierd program is because I’m doing the 2nd year “professional” lab write-up (a precursor to the 3rd year dissertation and 4th year project report) which is supposed to look like it has been published in a Journal (i.e. lots of theory and the text should make sense - unlike the normal writeups which are blagged and written up during labs). Not wanting to be locked into “LyX”:http://www.lyx.org from the start in case it didn’t work I used Microsoft Word, but the final document looks _horrible_ compared with LaTeX produced work (there is something about decent typesetting…).

The 3 year old Windows binary of “rtf2latex2e”:http://sourceforge.net/projects/rtf2latex2e/ works OK, but every converted equation has a new line inserted before it, and I’m fed up of taking them out by hand; so I want to try the CVS version to see if that fixes the problem.

Thanks to anyone who can offer help :-)

Build changelog from CVS?

Can someone tell me how (or what tool to use) to go through a Sourceforge CVS tree and build a changlog of modifications in the last month (or since I last tagged it, which I should do more often)? I’m sick of building the changelog for “sendcard”:http://www.sendcard.org by hand, and want to automate it.

Maybe iterators are useful in PHP

Well, “this article”:http://www.phpbuilder.com/columns/bosanac20030225.php3?page=2&print_mode=1 at PHPBuilder.com is the first one ever to make me think _”Hmm, maybe iterators could be useful”_.

Following on from “Harry’s comments”:http://peter.mapledesign.co.uk/weblog/archives/using_classes_in_php.html#comments I’ve started to think about the design of the system I’m going to use for my RSS aggregator more. Originally I thought what he’d written in the comments was over-engineered, over-designed, put-in-an-object-cause-its-trendy. But now I’m not so sure. I’ve gone back to reading Bertrand Meyer’s book “Object Oriented Software Construction”:http://www.amazon.com/exec/obidos/tg/detail/-/0136291554/peterswebpage04 (available cheaply in the *UK* from “Computer Manuals”:http://www.compman.co.uk/cgi-win/browse.exe?ref=278755) now to learn how to design OO systems - something I’ve been meaning to read since Easter, but never got the enthusiasm for (after all, isn’t this just overdesign, jumping on the bandwagon????)

We’ll see where it leads. I’m getting frustrated because I want to get on and have a working script to do what I need (and in my mind I can see exactly how it’ll work; how the interface will look etc) yet I’m not going anywhere because I want to get the design right. Which if I’m not careful may mean I never get anywhere, as the design’s never right ;-)
Here’s a couple more resources:

* “Eclipse Library documentation”:http://www.students.cs.uu.nl/people/voostind/eclipse/api/Iterator.html on their Iterator class.
* “Harry’s page”:http://www.phppatterns.com/index.php/article/articleview/50/1/1/ on the subject
* “A forum posting”:http://www.devnetwork.net/forums/viewtopic.php?t=8532 suggesting an alternative to Harry’s approach. I liked this quote: ??it doesn’t take into account the fact that PHP is a very dynamic language, and doesn’t need to rely on methods built for languages like C++ and Java (strongly typed languages).??

Finally, in the same vein as the quote above, a quote from “PHP Everywhere”:http://php.weblogs.com

bq. Here’s an example of something that is very hard to implement in VB.NET or C# or Java: PHP can dynamically recompile itself; the famous Smarty template compiler being just the tip of the iceberg. There is a world of PHP innovation out there beyond cloning PHPNuke or J2EE, just waiting to be discovered!

Some things are good to copy, some things aren’t. Some patterns are good for PHP, some aren’t. In 20 years time I’m sure we’ll all know which; at the moment we’re still developing the best approaches to take with dynamically typed languages.

PHP/Python Programming IDEs

I’m thinking about buying an IDE for PHP/Python programming. I’ve revised my opinion on debugging tools since using the one in PythonWin to understand where one of my scripts is going wrong, and I figure I might find on useful in PHP.

Are there any decent IDEs suitable for both languages? Or do I have to buy one for each? I’m more interested in one for PHP - PythonWin currently does all I need for Python.

I’ve used “PHPEdit”:http://www.phpedit.net now for a few years, but I want something more _finished_ with decent project management features. I trialled “Zend Studio 3″:http://www.zend.com/ and thought it OK, but I prefer a natural Windows interface (although if I move to FreeBSD this would be a plus-point) and I couldn’t get the debugging to work properly.

What do you use, and would you recommend it?

I’m in a little bit of a hurry, as if I decide to go for Zend I can get 22% off the Plus version until the end of the month ;-)

Passing data on the command line

I’ve been trying to get a PHP script to execute a Python script today using PHP’s @exec@ call. This worked fine, until I entered a long amount of data on the command line (this is using Windows XP by the way)…

I need to pass the body of my blog entries to the Python script. As I can’t find a RSS parser I like written in Python, and am not skilful in Python, I wanted to do most of the work in PHP. I’m calling the python script from PHP like:

@exec(”c:/code/RSS_Manager/test.py ” . $item['description'], $output, $ret);@

This worked fine until I encounterd an entry *3560* characters in length. Then Windows threw the error:

bq. Windows cannot access the specified device, path, or file. You may not have the appropriate permissions to access the item.

I know it’s not the script at fault, as I commented out the contents. Can anyone suggest a different way to pass this data to the python script? I’ve thought of using temp. files, but I’m hoping there’s another way to do it instead.

The command that caused Windows problems is in the extended entry. And I did try escaping quotes etc - made no difference :-( Continue reading →

Javascript Resources

# Cross-Browser.com : CBE is a Cross-Browser DHTML API for IE, Gecko, Opera, Netscape, Konqueror, AOL and similar browsers
# “Peter-Paul Koch’s Javascript section”:http://www.xs4all.nl/~ppk/js/index.html

When open source loses the shine

Sterling Hughes has an “interesting post”:http://www.edwardbear.org/blog/archives/000214.html on how open source can become less fun:

bq. Then let’s say you end up creating something really cool. Businesses and corporations start to rely heavily on this stuff: It is used by millions of applications. Now when you break backwards compatibility it becomes a huge issue. If you goof up; if your code isn’t up to snuff when committed, people with children to feed suffer. You have angry messages on Slashdot, users who whine and complain. Heck, sometimes the sky even falls on your head. You’ve essentially become an unpaid business. You start using terms like “the users,” and “the enterprise.” You start talking about evangelism. You start making bonds, pacts, deadlines and compromises. You stop thinking about the most innovative solution, and start thinking about the most acceptable solution.

bq. You stop doing things because they are cool. You make the prudent choices. You ride the wave and become a technological gem. More effort is focused on QA, and so the quality and reliability go up. You start standardizing processes and whitespace guidelines. You create release versioning schemas, and you dictate to developer’s how they should code, and where they should put their code. You deal with licensing issues. [...] You start looking at opportunity costs, and how to maximize your time. Your fanclub becomes a business and the result is that the exhuberance that you once had becomes drudgery.==

“sendcard”:http://www.sendcard.org/ has become like this. Do I always want to answer support questions? Nope, but it’s an established script and people expect it. When a bug’s found, do I want to drop everything else and fix it? Nope again, but unless I do people complain.

Now, I can’t kid myself that sendcard is as popular as the kind of program -Starling- Sterling is talking about, but it does give an idea as to how un-fun a larger project could be.

PHPTriad was a good example of a successful project that was closed because it became too much like work for the author. Matt Rosenberger pointed out the “Linux Router Project”:http://www.linuxrouter.org/#news as another project with a similar end.

So, what is the future of open source projects? How can we put the fun back into them? I guess making them exclusively for geeks would help so you don’t have to do any hand holding…!