Navigate
Home
ArticleWiki
Forum
Journal
Search
Newsletter
Links
Tech News
expertsrt.com
Welcome Guest.
Username:

Password:

Remember me

What language to use?
Welcome, Guest. Please login or register.
December 02, 2008, 08:17:15 PM
11304 Posts in 1248 Topics by 498 Members
Latest Member: katCheeme
Experts Round Table Network  |  Webservers  |  Apache  |  What language to use? « previous next »
Pages: [1]
Author Topic: What language to use?  (Read 560 times)
NeoTeq

Offline Offline

Posts: 21


« on: April 28, 2006, 02:11:55 AM »

Hi guys,

I'm planning to create my own CMS for websites. It's mainly for practise and repetition in some things, and I'm defining the project right now.

To this end, I'll need a server-side scripting language. I want the language to have the following properties:
- Must be possible to program OO
- Must be able to use it with Apache
- Must NOT have loosely-typed variables
- Communication with database (pref. MySQL) must be relatively easy and efficient.

Any ideas?

-NeoTeq
Logged

Still claiming: There is no peace.
VGR
Mentor

Offline Offline

Posts: 682



WWW
« Reply #1 on: April 28, 2006, 04:15:22 AM »

Was it not for the weak typing of variable thing, the best choice would be PHP

Now I see two solutions :
1) Java
2) PHP in OO mode where you force yourself to declare and access variables only through object methods : this way you will have strong typing.

Again, for efficiency, easyness, "OO or not OO" orientation and all the rest of your criteria, PHP (4 or 5) is the best choice.

The shame is that there is not an option to turn off PHP's polymorphism & auto-declaration&initialisation of variables, like an "implicit none" in FORTRAN.
Logged

techie overlord, answers all kind of questions on http://www.europeanexperts.org
NeoTeq

Offline Offline

Posts: 21


« Reply #2 on: April 28, 2006, 11:57:47 AM »

Could you give me an example of how I would handle things in php the way you suggest? I'm familiar with php, but not sure how to go forward with declaring and accessing variables through object methods. Thanks!
Logged

Still claiming: There is no peace.
VGR
Mentor

Offline Offline

Posts: 682



WWW
« Reply #3 on: April 28, 2006, 12:25:20 PM »

in fact, imagine you want to enforce strong typing on integer, string, array and float (classical ;-).

if you declare a class "type_int" with accessor methods (get() and set(), in other words) and an instanciation method (constructor if you prefer) [+ a destructor if you want] ypu will be able to :

-assign a real PHP integer variable IN the class to hold the value
-use set() with typeof() and value validation
-be sure get() will return an integer value, or an exception/errorcode/NaN

the same for the other types.

Very heavy & overkill, but a solution to your problem without compromising performance and Apache integration.
Logged

techie overlord, answers all kind of questions on http://www.europeanexperts.org
NeoTeq

Offline Offline

Posts: 21


« Reply #4 on: April 28, 2006, 12:33:30 PM »

That does sound a bit like overkill, are you sure there's no compromise in performance? I think I'd have to do some benchmarks.

I might go with an in-between solution, where I would just check the types of object properties in the setters. This would force me to use the right types there, and I expect the remainder of variables to be of a neglectable amount, if any.
Logged

Still claiming: There is no peace.
nicholassolutions
Administrator
*
Offline Offline

Posts: 133



WWW
« Reply #5 on: April 28, 2006, 02:04:27 PM »

PHP lets you do a lot of stuff you couldn't get away with in a strongly-typed language, but in addition to doing something like VGR is suggesting, you can actually program much more 'rigidly' if you make yourself. First, type cast everything:
http://www.php.net/manual/en/language.types.type-juggling.php#language.types.typecasting
Next, use the 'is identical' operators rather than equals

== --> ===
!= --> !==

Then, never do anything like:
Code:
$var = ($n > 5) ? 15 : false;


Finally, adopt a variable-naming convention  that clearly incorperates the type of the variable into the name. This will keep you from accidentally doing any funny business with your typing. I quote from section of the ERT PHP Team's coding standard that Richard and I put together:

Code:
$s_striing         a string
$i_num             an integer
$f_num             a float
$b_is_condition    boolean. Always phrased in the positive (i.e. NOT $b_is_not_condition)
$r_resource        a resource
$h_handle          a file handle
$m_var             a 'mixed' variable of non-constant type
$o_class_abbrev    an object, class_abbrev is an abbreviation for the class name
$ax_array          an array of type x, eg $as_blah for an array of strings.
                         If the elements are of different types use $am_mixedbunch
where possible, associative array elements in mixed arrays should be named
according to these conventions, e.g. $am_my_stuff['i_my_integer']


In other words, dont do anything that would get a C compiler to bark at you. As VGR says, it's unfortunate that you can't turn off the type juggling in PHP, but if you follow those guidelines you can get very close while benefitting from the OOP features and built-in functions of PHP. BTW, I'm not sure which version you are most familiar with, but PHP 5 OOP is greatly improved over PHP 4, so I would definitely recommend that for this project.

The one show stopper in the case of PHP is that some functions do not return a single type. For example, strpos() will return either an integer, or if the search string is not found, it returns boolean false. The only way to get around that would be to either not use the function, or to wrap it on your own that obeys strong typing.

Hope that helps and that's not too much you already know.
Logged
Srirangan
Mentor

Offline Offline

Posts: 52



WWW
« Reply #6 on: April 28, 2006, 08:59:17 PM »

If you are feeling a bit adventurous, you may want to give Ruby on Rails a try. I'm linking you to an article of mine which gives a brief introduction.
Logged

I rant therefore I am!
Pages: [1]
« previous next »
    Jump to: