// replace findThis string from stringIn with replaceWith, repeat number of times
//repeat must be >=1, anything else it will do 1 repeat anyway
// if the string doesn't occur nothing will happen
public static function replaceString(stringIn:String, findThis:String, replaceWith:String, repeat:Number):String {
var stringOut:String = '';
var tempArr:Array;
tempArr = stringIn.split(findThis); //spilt the string into an array based on the occurrences of the target string
stringOut = tempArr[0]; //get the first split item
for (var i=1;i < tempArr.length;i++){
if (i < repeat+1){
stringOut = stringOut + replaceWith + tempArr[i];// replace the next occurrence and add the next split item
}
else {
stringOut = stringOut + findThis + tempArr[i];// restore the rest of the string as it was
}
}
trace("String in: " + stringIn + " String out: " + stringOut);
return stringOut;
}
This is not a blog. So sue me!
Crikey, things are looking up!
Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts
Wednesday, October 15, 2008
ActionScript 2; replace string any number of times
The cheeseparing number of useful String class methods released by Adobe leaves something for the programmer to do. Here is a replace function that will replace a substring within another string any number of times. It starts at the first occurrence.
Friday, May 30, 2008
Putting your heart into it
It's been said that Life is like a sewer; you largely get out of it what you put into it. However you can be seriously messed up by other people.
There was a time, long ago, when I participated in a big way on Usenet newsgroups - only to be driven out by the volume of spam, trolls and flaming nasties. This happens. The teenage males (of all ages and several sexes) that do this kind of thing are getting their jollies by the net equivalent of graffitti and muggings.
Now there's the world of blogs. Nasty things happen to, basically, good people; Kathy Sierra is the one that springs to mind. Threatening such a fine human being is wrong, and deeply stupid.
Then we have stuff like this dumb-as-a-post attack on the credibility of Jeff Attwood.
I may disagree with some things Jeff writes but he's always worth reading. It's thought-provoking stuff. Only very occasionally MEGO. Judging by his writing, he's a smart, thoughtful person with opinions on a variety of subjects. I like the phrase strong opinions, weakly held. Generalists are to be encouraged in this world of narrow-minded specialists.
I do admire his courage in exposing himself to criticism. That's what happens to popular blogs. I don't care if he's right or wrong, I can judge that for myself. What matters is that he has something to say. I do care when carping and non-constructive criticism try to discourage genuine debate.
The basis of the attack seemed to be that "someone was wrong on the Internet", and that Jeff had said that he didn't think that learning the C language was necessary. In my opinion it actually doesn't matter if one "learns C" or not. Since I graduated in 1980 I have never "learned" a programming language systematically - it's all been learning by doing and learning by example then discovering the more esoteric stuff. Most of my collection of several hundred books about programming have only been partly read by me. Sometimes skimmed through, sometimes dropped after 100 pages.
(And, incidentally, when did the freaking programming books get to be 700-900 pages instead of a couple of hundred? About 5-10 years ago. My bookshelves are groaning with paper...switching to a tablet device and electronic books might work...it's showing promise so far. Anyhoo, authors are too ready to write immense tomes which really should be a long technical article or blogpost. Where the heck are the editors? I have been buying used books for a while now and encourage others to do the same (ABE books can get almost anything) - in the hope that in some small way it discourages the longer format - silly, I know. A small book giving the essentials backed up with a website containing the long examples and downloadable stuff would be so much better.)
It is arguable that I am a better maintenance programmer because I do not study a language deeply before working in it. This is now called "refactoring" and has become respectable again. I can certainly grok code as fast or faster than anyone I know. I think that I can pick up at least a superficial grasp of new tools, languages and techniques quickly because I am not plugged deeply into the massive amount of library code that most languages develop over time. At least enough to know whether I want to go further. That is not to say that it isn't painful sometimes (I have had some struggles especially with the more organic mutations of, say, ActionScript. I mean why does it have to have four ways of doing the same thing? lol, it's almost as if it was a human language!)
There is a role for the generic "programmer" as a smart person with an idea, or who is open to the ideas of others, or even more importantly, finds an idea and popularizes it.
Programming is ultimately about communication and ideas, isn't it? We are communicating with the machine and to those that follow us. And most great programmers are not sheep who just follow one path. They are usually people who have multiple other interests - such as gaming, sailing, music, mathematics, physics, psychology, art, athletics - and as such, real people bring insight into the largely hermetic world of the coder.
I have lived in the world of software long enough to know lame when I see it. And the self-declared iconoclast who derides the credibility of someone who puts his heart into his writing... well, get over it fella. You can earn your own credibility with your own work. Life is not a zero-sum game.
There was a time, long ago, when I participated in a big way on Usenet newsgroups - only to be driven out by the volume of spam, trolls and flaming nasties. This happens. The teenage males (of all ages and several sexes) that do this kind of thing are getting their jollies by the net equivalent of graffitti and muggings.
Now there's the world of blogs. Nasty things happen to, basically, good people; Kathy Sierra is the one that springs to mind. Threatening such a fine human being is wrong, and deeply stupid.
Then we have stuff like this dumb-as-a-post attack on the credibility of Jeff Attwood.
I may disagree with some things Jeff writes but he's always worth reading. It's thought-provoking stuff. Only very occasionally MEGO. Judging by his writing, he's a smart, thoughtful person with opinions on a variety of subjects. I like the phrase strong opinions, weakly held. Generalists are to be encouraged in this world of narrow-minded specialists.
I do admire his courage in exposing himself to criticism. That's what happens to popular blogs. I don't care if he's right or wrong, I can judge that for myself. What matters is that he has something to say. I do care when carping and non-constructive criticism try to discourage genuine debate.
The basis of the attack seemed to be that "someone was wrong on the Internet", and that Jeff had said that he didn't think that learning the C language was necessary. In my opinion it actually doesn't matter if one "learns C" or not. Since I graduated in 1980 I have never "learned" a programming language systematically - it's all been learning by doing and learning by example then discovering the more esoteric stuff. Most of my collection of several hundred books about programming have only been partly read by me. Sometimes skimmed through, sometimes dropped after 100 pages.
(And, incidentally, when did the freaking programming books get to be 700-900 pages instead of a couple of hundred? About 5-10 years ago. My bookshelves are groaning with paper...switching to a tablet device and electronic books might work...it's showing promise so far. Anyhoo, authors are too ready to write immense tomes which really should be a long technical article or blogpost. Where the heck are the editors? I have been buying used books for a while now and encourage others to do the same (ABE books can get almost anything) - in the hope that in some small way it discourages the longer format - silly, I know. A small book giving the essentials backed up with a website containing the long examples and downloadable stuff would be so much better.)
It is arguable that I am a better maintenance programmer because I do not study a language deeply before working in it. This is now called "refactoring" and has become respectable again. I can certainly grok code as fast or faster than anyone I know. I think that I can pick up at least a superficial grasp of new tools, languages and techniques quickly because I am not plugged deeply into the massive amount of library code that most languages develop over time. At least enough to know whether I want to go further. That is not to say that it isn't painful sometimes (I have had some struggles especially with the more organic mutations of, say, ActionScript. I mean why does it have to have four ways of doing the same thing? lol, it's almost as if it was a human language!)
There is a role for the generic "programmer" as a smart person with an idea, or who is open to the ideas of others, or even more importantly, finds an idea and popularizes it.
Programming is ultimately about communication and ideas, isn't it? We are communicating with the machine and to those that follow us. And most great programmers are not sheep who just follow one path. They are usually people who have multiple other interests - such as gaming, sailing, music, mathematics, physics, psychology, art, athletics - and as such, real people bring insight into the largely hermetic world of the coder.
I have lived in the world of software long enough to know lame when I see it. And the self-declared iconoclast who derides the credibility of someone who puts his heart into his writing... well, get over it fella. You can earn your own credibility with your own work. Life is not a zero-sum game.
Thursday, February 14, 2008
Pair programming: an experience
As with many of the Agile techniques, pair programming may be counter-intuitive when you first hear about it. Having worked like this for about 6 months now, I think I can say that it can be very successful.
This particular experience has been productive, fun and a very effective way to transfer knowledge. I was, prior to this, a Java/JSP developer for a couple of years. I consider myself a professional programmer. My oppo, Derek, was a very experienced Flash designer/web programmer. Two totally different domains with practically no intersection.
Our mission was to pick up the pieces of the ASK Flash client apps (the previous incumbents having departed 3 and 12 months previously) and to develop the first of the oral reading training activities for students using the red5 media server for recording/playback.
These previous apps had been under development for about 5 years and in that time server-client traffic had become a bottleneck. The apps needed to hold the server's hand when they did anything. The Flash apps are pretty and intelligent and could do a lot more of the heavy lifting. So we also had to implement a new way for the apps to function in the system.
Working together, often at the same computer, I found that I learned a huge amount about Flash apps, and, of course the programming language AS2. I am now quite proficient. I am still a beginner at the design side of Flash, although I can follow what Derek does - this is truly an alien way of thinking for a text-based worker like me.
Derek for his part was not an object-oriented programmer before this, but is now a pretty fair coder.
Together we have made 3 major apps, now working on the 4th, each of them is better than the last in both design and code. It has been very effective for us to actually work at one desk for a lot of the time, especially when coding and building the logic of the apps. It's also been a lot of fun. This has been perhaps the only drawback - I've heard a manager grumble about "splitting us up", as if we were just being social - lol.
Interestingly, almost but not quite the same degree of collaboration can also be achieved remotely from our homes about 80 km apart, VPN'ing in to the company network. We use IM and Skype to talk and run local dev environments as well as Remote Desktop to our office machines.
One major consideration is code quality; we catch a lot more errors earlier than I would alone. Also I think that talking through the logic really makes it more robust.
Another advantage is that the two of us really understand the apps and code in considerable depth. I trust that Derek can make code changes, and I think he'd let me make mods to the Flash apps.
All considered, I'd definitely recommend pair programming in the case where two experienced developers can complement one another's skills.
This particular experience has been productive, fun and a very effective way to transfer knowledge. I was, prior to this, a Java/JSP developer for a couple of years. I consider myself a professional programmer. My oppo, Derek, was a very experienced Flash designer/web programmer. Two totally different domains with practically no intersection.
Our mission was to pick up the pieces of the ASK Flash client apps (the previous incumbents having departed 3 and 12 months previously) and to develop the first of the oral reading training activities for students using the red5 media server for recording/playback.
These previous apps had been under development for about 5 years and in that time server-client traffic had become a bottleneck. The apps needed to hold the server's hand when they did anything. The Flash apps are pretty and intelligent and could do a lot more of the heavy lifting. So we also had to implement a new way for the apps to function in the system.
Working together, often at the same computer, I found that I learned a huge amount about Flash apps, and, of course the programming language AS2. I am now quite proficient. I am still a beginner at the design side of Flash, although I can follow what Derek does - this is truly an alien way of thinking for a text-based worker like me.
Derek for his part was not an object-oriented programmer before this, but is now a pretty fair coder.
Together we have made 3 major apps, now working on the 4th, each of them is better than the last in both design and code. It has been very effective for us to actually work at one desk for a lot of the time, especially when coding and building the logic of the apps. It's also been a lot of fun. This has been perhaps the only drawback - I've heard a manager grumble about "splitting us up", as if we were just being social - lol.
Interestingly, almost but not quite the same degree of collaboration can also be achieved remotely from our homes about 80 km apart, VPN'ing in to the company network. We use IM and Skype to talk and run local dev environments as well as Remote Desktop to our office machines.
One major consideration is code quality; we catch a lot more errors earlier than I would alone. Also I think that talking through the logic really makes it more robust.
Another advantage is that the two of us really understand the apps and code in considerable depth. I trust that Derek can make code changes, and I think he'd let me make mods to the Flash apps.
All considered, I'd definitely recommend pair programming in the case where two experienced developers can complement one another's skills.
Tuesday, November 27, 2007
Two types of programmers
iBanjo's post and Jeff's about the 80-20 rule when it comes to indifferent-excellent programmers are a bit harsh IMO. It's an exaggeration to make a point I guess. I'm sometimes in the 20%, sometimes in the 80% - depends on what applications, environment, level of expertise, and interest.
However, it brings up something very interesting, which is programmer productivity. I do strive to improve my personal productivity, and tell colleagues about useful tools. As the tools get more and more capable, people get more productive - as long as they can be arsed.
For text, computers allow people to produce more than typewriters which were more efficient than fountains pens which were better than quills. At each step the productivity mapping against the cost of a skilled worker, was to the benefit of everyone (well...perhaps that is arguable; imagine the ink well-fillers laid off when the fountain pen was introduced. :-)
With programmers, a higher degree is not necessary to be able to write a program. We no longer have to enter every character in a form for a data-entry clerk to type in. Or use a card punch. We do our own typing and the systems give us far more leverage than they used to. At the same time, we are encouraged to become lazy with things like memory allocation or cleaning up comments (yes, children, there were systems that only allowed 1000 lines of code, comments included. You have never seen such a sad girl as when I had to strip out all my lovely comments to get that darn thing to take the rest of the code :)
So we are all the more productive, in theory, and there are a lot more of us, and we're producing more...but...a heck of a lot of it is ending up being thrown away. All these startups, perhaps one in a hundred is still going after 5 years*. Perhaps one in a thousand is flourishing**. Most code that is written is being discarded without earning a real penny (I don't count IPOs and other stock market artifacts, I mean real profit for code). I think my most long-lived code was for a hydroelectric plant...embedded in the display panels representing a switch yard, it will probably live longer than I will, but the company I worked for took a big loss on the project.
I am not sure what can be done, apart from contributing to open source projects. That does seem to be a way to give the useful parts of a project to some kind of posterity.
* - unsupported assertion
** - unlikely
However, it brings up something very interesting, which is programmer productivity. I do strive to improve my personal productivity, and tell colleagues about useful tools. As the tools get more and more capable, people get more productive - as long as they can be arsed.
For text, computers allow people to produce more than typewriters which were more efficient than fountains pens which were better than quills. At each step the productivity mapping against the cost of a skilled worker, was to the benefit of everyone (well...perhaps that is arguable; imagine the ink well-fillers laid off when the fountain pen was introduced. :-)
With programmers, a higher degree is not necessary to be able to write a program. We no longer have to enter every character in a form for a data-entry clerk to type in. Or use a card punch. We do our own typing and the systems give us far more leverage than they used to. At the same time, we are encouraged to become lazy with things like memory allocation or cleaning up comments (yes, children, there were systems that only allowed 1000 lines of code, comments included. You have never seen such a sad girl as when I had to strip out all my lovely comments to get that darn thing to take the rest of the code :)
So we are all the more productive, in theory, and there are a lot more of us, and we're producing more...but...a heck of a lot of it is ending up being thrown away. All these startups, perhaps one in a hundred is still going after 5 years*. Perhaps one in a thousand is flourishing**. Most code that is written is being discarded without earning a real penny (I don't count IPOs and other stock market artifacts, I mean real profit for code). I think my most long-lived code was for a hydroelectric plant...embedded in the display panels representing a switch yard, it will probably live longer than I will, but the company I worked for took a big loss on the project.
I am not sure what can be done, apart from contributing to open source projects. That does seem to be a way to give the useful parts of a project to some kind of posterity.
* - unsupported assertion
** - unlikely
Subscribe to:
Posts (Atom)
Labels
- Funny
- spam sucks
- rant
- stolen joke alert
- boaters
- reviews
- self-indulgence
- health
- links
- sailing
- actionscript 2
- movies
- music
- programming
- sex
- silly songs
- Windows command line
- Windows desktop
- cats
- code
- computers
- flash
- photos
- politics
- rowing
- writers'
- Flash CS3
- age
- books
- browsers
- cooking
- government
- management
- user interface
- webapps
- Eclipse
- IDEs
- Subversion
- amazing
- anchoring
- batch files
- blogging
- color
- cremation
- fonts
- html
- java
- jsp
- language
- olpc
- pets
- philosophy
- photography
- quotes
- safety
- sales
- santa
- sociology
- special characters
- tools
St Lawrence Rowing
Test content from SLRC