PHP command line scripting

ykgoh

Master Member
Joined
Jan 1, 2000
Messages
2,782
Reaction score
0
I know it's kind of uncommon to use PHP for command line scripts, unlike Perl or Python. But it seems to be one option for simple scripting. Many common functions are available in a single call e.g. base64, string manipulation, simple file I/O, and strong third party modules/extensions support e.g. image processing through ImageMagick and cryptography using mcrypt.

Back in the early days, Perl was the general purpose jack-of-all-trade scripting language, but more of a procedural programming style. But Python had a more object-oriented feel to it, for a more structured and extensible software design. PHP was a "template engine" for the web as an alternative to CGI. But they have more or less converged in later years (2005-2010), so the differences are no longer so stark.

Btw, just to declare that I have done Perl, PHP and Python scripting, but not Ruby. Wondering if there's any value in learning Ruby anyway since the rest probably can do what Ruby can offer.

One common weakness of all these scripting languages is handling of binary data which C/Java/.NET do better. I'm guessing they're all highly influenced by or follow Perl-style of packing and unpacking, which looks like an ugly hack to me. It looks like a C-style printf format string and regular expression for binary data. :s22:

Any Perl or Python expert who would like to share his/her thoughts about the strengths and weaknesses of Perl/Python/PHP? Which one is a clear choice for certain specific task?

I know there are many more programming languages out there today like JavaScript wth Node.js and Google Go. Far too many to learn and master.
 
Last edited:

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,550
Reaction score
1,302
I know it's kind of uncommon to use PHP for command line scripts, unlike Perl or Python. But it seems to be one option for simple scripting. Many common functions are available in a single call e.g. base64, string manipulation, simple file I/O, and strong third party modules/extensions support e.g. image processing through ImageMagick and cryptography using mcrypt.

Back in the early days, Perl was the general purpose jack-of-all-trade scripting language, but more of a procedural programming style. But Python had a more object-oriented feel to it, for a more structured and extensible software design. PHP was a "template engine" for the web as an alternative to CGI. But they have more or less converged in later years (2005-2010), so the differences are no longer so stark.

Btw, just to declare that I have done Perl, PHP and Python scripting, but not Ruby. Wondering if there's any value in learning Ruby anyway since the rest probably can do what Ruby can offer.

One common weakness of all these scripting languages is handling of binary data which C/Java/.NET do better. I'm guessing they're all highly influenced by or follow Perl-style of packing and unpacking, which looks like an ugly hack to me. It looks like a C-style printf format string and regular expression for binary data. :s22:

Any Perl or Python expert who would like to share his/her thoughts about the strengths and weaknesses of Perl/Python/PHP? Which one is a clear choice for certain specific task?

I know there are many more programming languages out there today like JavaScript wth Node.js and Google Go. Far too many to learn and master.

Let me set my stage right. Often when having discussion of such matters, it can get pretty hairy of ending up in a flame war. For my perspective into this topic, my stand is often at the high level. Don't dwell too much into the language itself on which is better or worse. That perspective often look at things in a micro manner which doesn't hit any objective in real life at all.

Often when we ask question like which programming language is better, I would like to suspect it is about performance, efficiency and productivity. If we are not answering any of these matters, it is better that we don't even start talking about it. If we do get started, then we certainly have to look at it from a high level manner on how the features of the programming language matters to what we are doing, who are the developers we can easily find to run the project and continue in the project, the interoperability between projects, business continuation, availability of existing projects written in which language, and more.

Assuming programming language X is the best language, but it is so arcane to learn and not many developers around, naturally these developers are going to cost a lot and there will be less developers of good skill in it, what it translate to is higher cost for the project, higher risk in fear these developers will move away and harder to get another to replace. If most of the open source components or other projects are written in programming language Y and cannot be easily couple with the new project that is to be written in programming language X, it ends up the project cost more because it needs to be largely written from scratch, recreating some components that are well written in another language.

That's why when we measure things, we can't just read into one component itself and measure it. The measurement is useless on the higher level and misleading from a business perspective. It can only serve as a reference from a technical perspective which very often is not applicable to real life situation.

As such, my advise to developers is be jack of multiple languages and master of a few. I would consider myself a very experience developer in Perl, PHP and Java, but over the years things changes a lot in the languages and as times goes, I can only be good in them and not a master in them anymore, since I have pretty much moved up the chain and got myself involved more in solutions rather than writing the codes myself.

I have slightly less than 10 years worth of experience in Perl. A few years of intensive usage of it developing a mail system across various parts of the Linux system. For the web, I have used ModPerl which is slightly different in managing variable scoping from CGI Perl, used Perl in all parts of the system scripts, even using it to modify one of the antispam engine running it in. Used it to create SMTP servers that run within the server. I also used CGI Perl in other projects serving integration with Facebook, Twitter and Instagram. Merging it with Java to run a High Available Server, hence half Perl half Java.

The main advantage of Perl is her expressive language and powerful (Not)Regular Expression Engine. Perl is one of those languages that fully integrated RE into its syntax. The implicitness of the language makes writing in it terse. While it looks arcane to novice developers, it certainly feels privileged to be able to weld it nicely, like a poet. Having that it is highly integrated in the Unix environment makes it the highly recommended tool for developers. You can't yourself a unix developer if you don't know Perl.

In addition, Perl has a large supportive community and tons of modules available via the CPAN. If you want absolute performance, you can always write your own C module and integrate it into Perl. Then you will have the best of both worlds. I can't emphasize how powerful RE is in Perl. The only way is for the audience to go read up the book found at Mastering Regular Expressions, 3rd Edition - O'Reilly Media

Perl does have OOP, but it is not first class OOP. It comes as an after thought in the language, using modules as the way to create classes. It does not enforce strict OOP the way how some other languages like Java did it.

Coming to PHP, it is my first language to web development. I knew about Perl, but it didn't dawn on me until I encounter it during working. I practice PHP while in the university. With it very much C like syntax, it is not at all difficult to use it. Even today I use PHP in both web development and also command line tools. Since I am very proficient in PHP, I use it to create the backup tool uses in AWS having that AWS offers PHP SDK. So you can see that I'm not affixed with programming language. Use the right tool for the right job. It's just a tool. If you need to work with systems that are already written in PHP, such as most open sourced CMS written in PHP, why go against the flow and create yet another language ? Do so if you are really that good in creating one and have a good reason to do so.

I think other than C/C++/Pascal, and some 3rd gen language or before, I don't think there are other programming languages handling binary the way C/C++ does it. Objective-C is a superset of C and hence benefited from it too. Java doesn't do binary that well, there is quite a fair bit of conversion under the hood. C basically map using union and structures over the binary data as-is and work on those data directly. pack and unpack of most interpreted languages are the way adopted to convert between managed data and raw data. Even if we don't see it, there is a lot of conversion handling underneath the language covered by sugar syntax.

Should you pick up yet another programming language XYZ ? My answer is always YES. Programming langauge is not like human languages, it's not all that arcane in comparison. In human language, using English for example, "A school of fish". Why not "fishes" ? The context of fish as claimed by the langauge is uncountable and hence uses "fish" an implied plural. These kind of behaviour is not so with most programming languages. Therefore it is often quite easy to pick up a new programming language as oppose to a human language.

When you travel to China, would you have chosen to speak in Mandarin instead of anything else, like English ? Likewise, when it comes to working with technology, there is always the need to be able to handle different languages for the sake of embracing more technologies in the process. Learning Ruby will therefore make you able to integrate with systems running on Ruby and also using variants of it such as JRuby. Using JRuby, you can interoperate between Ruby and Java in the JVM. You benefit from both programming languages and be more productive on certain tasks easier to write in Ruby than with Java, yet you can still use all the available Java libraries on the same JVM.

Make some time, learn new programming languages as they becomes mature and make them your arsenal of tools to execute your work. That's what I think of programming languages.
 

ykgoh

Master Member
Joined
Jan 1, 2000
Messages
2,782
Reaction score
0
Let me set my stage right. Often when having discussion of such matters, it can get pretty hairy of ending up in a flame war. For my perspective into this topic, my stand is often at the high level. Don't dwell too much into the language itself on which is better or worse. That perspective often look at things in a micro manner which doesn't hit any objective in real life at all.

Not my intention to start a flame war. I believe every language has its own fans and they'll defend it bitterly that it is the best and only language everyone needs or need to learn.

It stems more from a paradox of choice. As mentioned, I am OK with programming in Perl, Python and PHP, and for a given requirement, I can probably implement 3 exact same versions of it in each language. Just that I was wondering if they are different in some way that makes them easier for certain situation or requirements.

For example, if you want to do task A, use language X. For task B, use language Y. Language Z is designed for C. And so on.

Often when we ask question like which programming language is better, I would like to suspect it is about performance, efficiency and productivity. If we are not answering any of these matters, it is better that we don't even start talking about it. If we do get started, then we certainly have to look at it from a high level manner on how the features of the programming language matters to what we are doing, who are the developers we can easily find to run the project and continue in the project, the interoperability between projects, business continuation, availability of existing projects written in which language, and more.

Assuming programming language X is the best language, but it is so arcane to learn and not many developers around, naturally these developers are going to cost a lot and there will be less developers of good skill in it, what it translate to is higher cost for the project, higher risk in fear these developers will move away and harder to get another to replace. If most of the open source components or other projects are written in programming language Y and cannot be easily couple with the new project that is to be written in programming language X, it ends up the project cost more because it needs to be largely written from scratch, recreating some components that are well written in another language.

That's why when we measure things, we can't just read into one component itself and measure it. The measurement is useless on the higher level and misleading from a business perspective. It can only serve as a reference from a technical perspective which very often is not applicable to real life situation.

At a commercial project level yes, these considerations are important. For personal projects, we have more leeways.

My personal (biased) preference has always been convenience with its platform having tons of common built-in functions provided, without having to hunt around for third party extensions, packages and modules.

I remember Java didn't have a Base64 encoder/decoder built-in. :s8: But at least it provided decent basic networking and cryptographic functions.

The main advantage of Perl is her expressive language and powerful (Not)Regular Expression Engine. Perl is one of those languages that fully integrated RE into its syntax. The implicitness of the language makes writing in it terse. While it looks arcane to novice developers, it certainly feels privileged to be able to weld it nicely, like a poet. Having that it is highly integrated in the Unix environment makes it the highly recommended tool for developers. You can't yourself a unix developer if you don't know Perl.

In addition, Perl has a large supportive community and tons of modules available via the CPAN. If you want absolute performance, you can always write your own C module and integrate it into Perl. Then you will have the best of both worlds. I can't emphasize how powerful RE is in Perl. The only way is for the audience to go read up the book found at Mastering Regular Expressions, 3rd Edition*-*O'Reilly Media

I started playing with Perl in 1996 or 1997. At first, I didn't find it too bad actually, having learnt programming in C. Later on, I started to dislike it for the way special variables are used and the implicitness of their meanings based on context for example the omniscient $_ sprinkled everywhere. I prefer things to be clearly labelled, but it's a personal opinion and preference.

Perl does have OOP, but it is not first class OOP. It comes as an after thought in the language, using modules as the way to create classes. It does not enforce strict OOP the way how some other languages like Java did it.

Well, Perl 6 is taking a long time to come with proper OOP while they rewrote everything under Parrot engine I believe. Perl 5 introduced a hacky form of OO like JavaScript and used bless to link an associative array to a class when it is actually a package with some functions. It looks like heresy to me. :s13:

It didn't feel too bad, until I went to Java and saw OO that is clean, straightforward and pristine. Python shows similar characteristics. If it's OO, it has to be real OO. Not something that looks like OO. Again my personal preference.

But when it comes to parsing lines of text files and matching patterns using regular expressions, Perl is godlike by making it trivial. Python and Java probably need more lines of codes and formatting to do the same thing.

Coming to PHP, it is my first language to web development. I knew about Perl, but it didn't dawn on me until I encounter it during working. I practice PHP while in the university. With it very much C like syntax, it is not at all difficult to use it. Even today I use PHP in both web development and also command line tools. Since I am very proficient in PHP, I use it to create the backup tool uses in AWS having that AWS offers PHP SDK. So you can see that I'm not affixed with programming language. Use the right tool for the right job. It's just a tool. If you need to work with systems that are already written in PHP, such as most open sourced CMS written in PHP, why go against the flow and create yet another language ? Do so if you are really that good in creating one and have a good reason to do so.

So I have found someone who has written command line scripts in PHP. :) I thought in real life nobody uses PHP this way though it has always been there. 99% uses PHP for web applications.

I think other than C/C++/Pascal, and some 3rd gen language or before, I don't think there are other programming languages handling binary the way C/C++ does it. Objective-C is a superset of C and hence benefited from it too. Java doesn't do binary that well, there is quite a fair bit of conversion under the hood. C basically map using union and structures over the binary data as-is and work on those data directly. pack and unpack of most interpreted languages are the way adopted to convert between managed data and raw data. Even if we don't see it, there is a lot of conversion handling underneath the language covered by sugar syntax.

That's why when dealing with binary data and files, I still prefer to write it in C/C++/Java/C#. But I think I should just learn to stomach pack and unpack format syntax. :(
 

ykgoh

Master Member
Joined
Jan 1, 2000
Messages
2,782
Reaction score
0
-snip-
Well, Perl 6 is taking a long time to come with proper OOP while they rewrote everything under Parrot engine I believe. Perl 5 introduced a hacky form of OO like JavaScript and used bless to link an associative array to a class when it is actually a package with some functions. It looks like heresy to me. :s13:

It didn't feel too bad, until I went to Java and saw OO that is clean, straightforward and pristine. Python shows similar characteristics. If it's OO, it has to be real OO. Not something that looks like OO. Again my personal preference.
-snip-

OK, on hindsight and after further research, I think I'm just being anal being this OO style. Too influenced by my biased perspective of what constitutes "proper" OO in C++ and Java, known as the class-based_programming style of OO and static type systems.

Perl and many interpreted languages' style of OO is based on prototype-based programming and dynamic type systems.

End of the day, it's personal preferences.
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,550
Reaction score
1,302
Not my intention to start a flame war. I believe every language has its own fans and they'll defend it bitterly that it is the best and only language everyone needs or need to learn.

It stems more from a paradox of choice. As mentioned, I am OK with programming in Perl, Python and PHP, and for a given requirement, I can probably implement 3 exact same versions of it in each language. Just that I was wondering if they are different in some way that makes them easier for certain situation or requirements.

For example, if you want to do task A, use language X. For task B, use language Y. Language Z is designed for C. And so on.

The answer is always YES. Creators of the languages often come from certain background in their own field. Like most of us, they are master of some and jacks of the rest. Their envision to their own programming languages will definitely have certain biased towards doing well in some areas but not in the rest. Some of these decisions are conflicting in nature, like if you want dynamic metadata to the language, there will be runtime information during execution. More memory will be required to accomodate the dynamics and hence data are not as compact, more dereferencing are required during variables access. If a programming language can accomodate infinite recursion then stack space must be dynamic in nature and therefore more performance lost. As such each programming language will have its pro and cons, resulting in them performing better in some specific cases that uses those features.

Years back when I'm doing an overseas project, I used 3 programming languages across the whole solution, namely Java, Groovy and Perl. Java for the main system, Groovy for cron where it requires Oracle JDBC drivers but I want the dynamic nature of the language and Perl for other system administration scripts.

Any wise developers will want to choose the right tool for the right job. Bulldozing their way using just one programming language when you know there is a better one out there is a limitation one inflict upon oneself.

That is why a developer need to be versatile to know as much programming languages as possible to release these limitation. It take time to learn any programming language, to know how to make use of the features properly and understand the penalty or cost in using specific features. You don't decide last minute to use a programming language. Over time you identify the feature of each programming language by experimenting with it, like using it for less important tasks in a project as a trial. As you discover more about the programming language, you can then choose to introduce them into more important areas of future projects. That's how one can eventually pick up more skills along the way.

At a commercial project level yes, these considerations are important. For personal projects, we have more leeways.

My personal (biased) preference has always been convenience with its platform having tons of common built-in functions provided, without having to hunt around for third party extensions, packages and modules.

I remember Java didn't have a Base64 encoder/decoder built-in. :s8: But at least it provided decent basic networking and cryptographic functions.

To answer your doubt on Java, yes there is a built in Base64 encoder/decoder
Code:
import sun.misc.BASE64Encoder;
import sun.misc.BASE64Decoder;

But as the namespace indicate, these are not public API and hence not recommended for use. However over the years, there are so many projects that I have come across uses them.

Well you can have your biased, it's your growth into software development. For me, I don't care if it's built in or not. When I assess a programming language, I assess the ecosystem as a whole. Setting yourself the limitation is not wise in my opinion. An example of the Base64 component you required has been part of the Apache Commons Library for a long time, so I don't feel affected by whether it's built in or not. Java has been a very easy programming language and extremely easy to drop in any Java libraries due to the extremely well defined inheritance model. You will find it is a lot more difficult and confusing when working with C++ packages since there is no single root inheritance model for C++. Java enforce the root to be Object class and interface, which makes adding any packages into a system as simple as mounting a new filesystem into any part of the filesystem.

Managed memory model not only provides highly secure development platform, but also consistent memory management across packages. For C/C++, all these are not consistent across packages you get from various owners. Some expect the caller to allocate the memory, some expect the callee to allocate the memory. In Java, no such nonsense since references is all that matters, not one exclusively own it.

I started playing with Perl in 1996 or 1997. At first, I didn't find it too bad actually, having learnt programming in C. Later on, I started to dislike it for the way special variables are used and the implicitness of their meanings based on context for example the omniscient $_ sprinkled everywhere. I prefer things to be clearly labelled, but it's a personal opinion and preference.

There are good practices on how one can code in Perl. I code in both manners depending on situation. When I am creating a proper system using Perl, I don't use implicit $_ unless it is necessary. I will use
Code:
use strict;
use warnings;

to ensure no sloppy coding. I will use plentiful of comments through out the program and proper indentation too. For example the if..else statement
Code:
if (...) { # reason
} else { # reason
}

When using RE, I will assign the output instead of let it assigned to $_. Even if the output is $_, I will first assign it to a variable for later use instead of working on the $_ repeatedly. For example this regular expression capturing group
Code:
# concise manner
my($digits,$alpha) = $expr =~ /([0-9]+)([A-Za-z]+)/;

# sloppy manner
$expr =~ /([0-9]+)([A-Za-z]+)/;
# Using $1 for $digits and $2 for $alpha

# while loop manner
while ($expr =~ /...../sg) {
  my $match = $_;
  # work with $match instead of $_
}

If I'm coding perl as part of a shell script, I can afford to be sloppy as such
Code:
#!/usr/bin/bash

OUTPUT=`ls | perl -ne 'tr/[a-z]/[A-Z]/; print'`;

When dealing with any programming languages, good developers don't let the syntax enforce the discipline. They should enforce discipline in their pattern of development. In this way, whichever programming language it is, it makes little difference. It's like know various dialects of Tamil, each different in specific way, but not all that different from each other.

Well, Perl 6 is taking a long time to come with proper OOP while they rewrote everything under Parrot engine I believe. Perl 5 introduced a hacky form of OO like JavaScript and used bless to link an associative array to a class when it is actually a package with some functions. It looks like heresy to me. :s13:

It didn't feel too bad, until I went to Java and saw OO that is clean, straightforward and pristine. Python shows similar characteristics. If it's OO, it has to be real OO. Not something that looks like OO. Again my personal preference.

Well indeed Larry and his gang has been taking a long time to push out Perl 6. Larry introduced something I don't know if we wanna consider it neat, but Perl 6 can be parsed using Perl 6. My last review of the language also know it is going to break a lot of Perl 5 programs. So I will believe it will take awhile before Perl 6 will be on track.

Don't be too anal about how things works. Important is they work. I think I have long forgiven such eccentricity in programming languages, so it doesn't bother me like it did years back.

But when it comes to parsing lines of text files and matching patterns using regular expressions, Perl is godlike by making it trivial. Python and Java probably need more lines of codes and formatting to do the same thing.

So far no programming languages that I came across matches up to Perl for RE. Ruby has it close enough, but Perl has features that makes RE not-RE, such as code embedded inside the expression.

So I have found someone who has written command line scripts in PHP. :) I thought in real life nobody uses PHP this way though it has always been there. 99% uses PHP for web applications.

Well a tool is just a tool. Why limit yourself to what it can do. I have written shell script and C programs for Web CGI too. For PHP, all you need to do is install the PHP CLI package.

That's why when dealing with binary data and files, I still prefer to write it in C/C++/Java/C#. But I think I should just learn to stomach pack and unpack format syntax. :(

I don't know what is your take to pack and unpack, but it seems alright to me. If it is about performance, I find it often much over-rated in discussion. Realistic optimization is to optimise 80% for 20% of the code. As long as 20% of the code where bottleneck are discovered and the speed gain is 80%, one will already see great improvement in the overall application. As time goes, newer revision of the same application may gain better performance from a new architecture.

If you find pack and unpack a performance issue, then you should consider changing the data format, or changing that portion of code to be written using something else. If it is a OCD thing, then probably there is no solution to it, perhaps to pop a few pills :)
 
Last edited:

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,550
Reaction score
1,302
OK, on hindsight and after further research, I think I'm just being anal being this OO style. Too influenced by my biased perspective of what constitutes "proper" OO in C++ and Java, known as the class-based_programming style of OO and static type systems.

Perl and many interpreted languages' style of OO is based on prototype-based programming and dynamic type systems.

End of the day, it's personal preferences.

Just a note, Perl is not prototype-based. Javascript is one popular prototype-based OO. Perl is very much class based except you don't use the class keyword in the syntax, you use package to start your class declaration.

You may refer to the wiki information you have provided, I quote
Many prototype-based systems encourage the alteration of prototypes during run-time, whereas only very few class-based object-oriented systems (such as the dynamic object-oriented system, Common Lisp, Dylan, Smalltalk, Objective-C, Python, Perl, or Ruby) allow classes to be altered during the execution of a program.

Both prototype and class-based OO are proper. It's just a design.
 

ykgoh

Master Member
Joined
Jan 1, 2000
Messages
2,782
Reaction score
0
To answer your doubt on Java, yes there is a built in Base64 encoder/decoder
Code:
import sun.misc.BASE64Encoder;
import sun.misc.BASE64Decoder;

But as the namespace indicate, these are not public API and hence not recommended for use. However over the years, there are so many projects that I have come across uses them.

Well you can have your biased, it's your growth into software development. For me, I don't care if it's built in or not. When I assess a programming language, I assess the ecosystem as a whole. Setting yourself the limitation is not wise in my opinion. An example of the Base64 component you required has been part of the Apache Commons Library for a long time, so I don't feel affected by whether it's built in or not. Java has been a very easy programming language and extremely easy to drop in any Java libraries due to the extremely well defined inheritance model. You will find it is a lot more difficult and confusing when working with C++ packages since there is no single root inheritance model for C++. Java enforce the root to be Object class and interface, which makes adding any packages into a system as simple as mounting a new filesystem into any part of the filesystem.

That's the issue I pointed out. sun.misc.BASE64Encoder and sun.misc.BASE64Decoder are Sun's internal classes for internal use. We never know which version of Java will take it out or shift to another package. So I relied on the Apache's version instead previously.

When dealing with any programming languages, good developers don't let the syntax enforce the discipline. They should enforce discipline in their pattern of development. In this way, whichever programming language it is, it makes little difference. It's like know various dialects of Tamil, each different in specific way, but not all that different from each other.

I agree that for a one-man project, a conscientious developer can choose to enforce his own discipline when it comes to coding.

Problem arises when it is coded by a team, with little or no coding guidelines or supervision. I have worked in such companies and project teams before where I inherited a ZIP file stuffed with sloppy half-working source codes and scripts with zero comments, hidden undocumented hacks and zero build automation system (e.g. no makefile, ant build.xml or maven even a text file describing how to build a project) because someone quitted his job.

So a programming language that enforces some discipline and consistency as a rule (e.g. indentation convention in Python) is a great plus, instead of hoping the programmer would be a conscientious professional.

I know this is applying a technical solution to a management problem.

I don't know what is your take to pack and unpack, but it seems alright to me. If it is about performance, I find it often much over-rated in discussion. Realistic optimization is to optimise 80% for 20% of the code. As long as 20% of the code where bottleneck are discovered and the speed gain is 80%, one will already see great improvement in the overall application. As time goes, newer revision of the same application may gain better performance from a new architecture.

If you find pack and unpack a performance issue, then you should consider changing the data format, or changing that portion of code to be written using something else. If it is a OCD thing, then probably there is no solution to it, perhaps to pop a few pills :)

Not a performance concern. Anyone looking for high performance and tight memory usage to squeeze the last ounce out of bare metal should be prepared to write in C/C++ or x86 assembly imo.

:D

I think pack and unpack is OK, if I can just treat it like those %s and %d in printf or sscanf format string. Concept is similar and expressing the data structure looks short and direct. In C, I would have to write a structure. Perl looks more like mapping the associative array fields. Looks OK to me now, not too bad at all.
 
Last edited:

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,550
Reaction score
1,302
That's the issue I pointed out. sun.misc.BASE64Encoder and sun.misc.BASE64Decoder are Sun's internal classes for internal use. We never know which version of Java will take it out or shift to another package. So I relied on the Apache's version instead previously.

The whole point is there is absolutely no disadvantage to rely on a 3rd party library since at some point in any development regardless of PHP or Perl or C or C++, you will need to use 3rd party libraries. So up to this point, I really don't see where it's going.

I agree that for a one-man project, a conscientious developer can choose to enforce his own discipline when it comes to coding.

Problem arises when it is coded by a team, with little or no coding guidelines or supervision. I have worked in such companies and project teams before where I inherited a ZIP file stuffed with sloppy half-working source codes and scripts with zero comments, hidden undocumented hacks and zero build automation system (e.g. no makefile, ant build.xml or maven even a text file describing how to build a project) because someone quitted his job.

So a programming language that enforces some discipline and consistency as a rule (e.g. indentation convention in Python) is a great plus, instead of hoping the programmer would be a conscientious professional.

I know this is applying a technical solution to a management problem.

I think you have pretty much answer the issue yourself. I don't think the problem is worthy to be resolved at the technical level becuase it will enforce too much restriction to creativity and no one must comply to the same standard on how they would like to make codes readable. Some like to use curly braces on seaparate like, some like to use camel case naming convention while others prefer the classic C naming convention. Beyond the scope of a beginner in Python, I personally don't find Python approach to indentation as part of the language itself exciting to me. I often have my own way to make codes readable for others.

I think at the end of the day, it is human we are dealing with and it's better we manage it from a more human perspective. Things like missing comments, no build framework and no testing framework is not easily solved from a technical perspective, so there is no need to try. That makes the having of good project management essential.

We don't hope, we train.

Not a performance concern. Anyone looking for high performance and tight memory usage to squeeze the last ounce out of bare metal should be prepared to write in C/C++ or x86 assembly imo.

:D

I think pack and unpack is OK, if I can just treat it like those %s and %d in printf or sscanf format string. Concept is similar and expressing the data structure looks short and direct. In C, I would have to write a structure. Perl looks more like mapping the associative array fields. Looks OK to me now, not too bad at all.

I won't want to think pack and unpack really that important in the overall discussion. You trade something for another, as simple as that. You want reliable memory management, some things need to go, no pointers, just references. You want low level management, then you better be good in memory management which is hard to come by in developers nowadays. I wouldn't even be surprised if I talk with 100 developers before the last 10 years and tell them about what is Overlay and they have totally no idea about it unelss they studied Pascal.

I bet if I share with them about Intel memory Segment:Offset model, they will certainly give me that "lost" face, or maybe the proud ones will be the expression of "Is that important ?" Happy reading The Segment:Offset Addressing Scheme

So while I do agree having good programming language constructs is definitely helpful in picking out mistakes in programming, the far more important part is education and discipline coming from the human standpoint. It will be a lot more helpful to make programmers understand why certain things are done that way instead of you just do it because the language insist you have to, like the whitespaces management.
 

quekky

Arch-Supremacy Member
Joined
Nov 12, 2000
Messages
18,440
Reaction score
0
I learnt PHP/Perl/Java/C previously too, and I used to do web programming a lot. But I've since changed to adminitrating systems more then programming.

So nowadays most of the cli scripting I do it in BASH or PHP, call me "lazy" :p I do agree that PHP have a lot of those fancy modules that can be used easily. Well, it all boils down to personal perference, all these languages will get the job done eventually

I've never learnt Python, always wanted to but always lack of time to pick up new languages... me old dog liao cant learn new trick... just jk. too much to do too little time

Something that I still don't understand is, if using java for scripting, the startup time and run time most of the time is slower than bash/php/pl. Not sure why... surposingly Java have JIT and the rest need to interpret

btw, I just googled and found Java soon will have a Base64 lib
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,550
Reaction score
1,302
Something that I still don't understand is, if using java for scripting, the startup time and run time most of the time is slower than bash/php/pl. Not sure why... surposingly Java have JIT and the rest need to interpret

btw, I just googled and found Java soon will have a Base64 lib


You could be misinformed, Java codes are not interpreted. Interpretation in programming language context is where syntax are parsed and executed at the same time. Modern programming languages hardly falls under this category anymore, despite they are kept on referred to as interpreted in some sense. However programming languages like PHP/Perl/Ruby/Python etc are often referred to as scripting languages. That is because of their dynamic nature and loosely enforced typing.


Java on the other hand is a strictly typed language like C/C++ and hence do not fall under scripting language. However no part of it is interpreted. The source code is parsed and compiled into VM opcodes to be executed by the JVM. The JVM will translate the opcodes on the fly into the native architecture equivalent. This process is not called interpretation.


JIT(Just in Time) Compilation is an advance compilation that happens at the VM level to convert often executed VM opcodes into the binary equivalence. Because the process is expensive itself and some of them may be a stop-the-world process, by default the JVM only perform the compilation for some of these opcodes after they have been executed for a predefined number of times. The default is 1000, you may read more from FAQs: Java


The JVM startup is unfortunately slower than any native codes or other scripting languages, but it is not sloppy at all when running in server mode on long duration. The JVM is massive in comparison to most scripting languages setup. It has a more elaborate virtual machine design.


In fact, when running for long duration of time, Java is faster than a lot of scripting languages.


When making a decision of performance, we need to measure how often each time the program is run and how long the program is run. Something that run only once daily, whichever scripting language or slow starting JVM is fine. If it's something that need to be run hourly and each time for maybe 10mins, perhaps a server design make more sense to cut down on startup lag, encourage file-buffer caching and to make JIT work in advantage to you.


I hope these information helps in your future assessment.
 
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top