This is topic Why can't people learn basic math? in forum Officers' Lounge at Flare Sci-Fi Forums.


To visit this topic, use this URL:
https://flare.solareclipse.net/ultimatebb.php/topic/10/3229.html

Posted by MinutiaeMan (Member # 444) on :
 
(Please excuse this random rant.)

Okay, this may seem a bit elitist, depending on your point of view. But though I realize that I'm probably a bit more educated than a number of people out there who never finished high school, I fail to see why some people can't remember basic elementary school stuff.

I'm reading the "Visual Quickstart Guide" for PHP scripting, to get myself familiar with the basics of PHP scripts before I dive back into a more advanced book that I purchased a while back, but had difficulty with some of the more advanced stuff and figured I'd start at the very beginning. In the section concerning mathematical operations, specifically the issue of multiple operators (like "10 - 4 / 2")... rather than bother to tell people to remember the basic rules of precedence, he just tells them to use parentheses all the time.

Doesn't anyone learn "Please Excuse My Dear Aunt Sally" these days?

</rant>
 
Posted by Ultra Magnus (Member # 239) on :
 
BEDMAS.
 
Posted by Charles Capps (Member # 9) on :
 
Different languages have different ideas about operator precedence. Knowing how often PHP breaks backwards compatability, it wouldn't surprise me if it changed from version to version.

Using parens is the best way to forcefully ensure that your idea of precedence is enforced.
 
Posted by Cartman (Member # 256) on :
 
Plus, they improve legibility of your code.
 
Posted by MinutiaeMan (Member # 444) on :
 
quote:
Originally posted by Charles Capps:
Different languages have different ideas about operator precedence.

Well, that's brilliant! Probably another example of IT people ensuring their job security by making certain that no one can figure out what they're doing. [Razz]
quote:
Knowing how often PHP breaks backwards compatability, it wouldn't surprise me if it changed from version to version.
Interesting... I took a six-week class at the university learning basic C programming, and from what I've been able to discern, PHP has a lot of similarities, at least on the surface in terms of coding language.
quote:
Using parens is the best way to forcefully ensure that your idea of precedence is enforced.
Oh, I know. But this guy didn't even TRY to explain the concept of precedence, but rather sidestepped it altogether.

I mean really... if you're trying to learn a major computer programming language, isn't it logical to figure that people have basic math skills and know the order of operations?
 
Posted by Charles Capps (Member # 9) on :
 
PHP is to web apps as Visual Basic is to Windows apps.

Any moderately complex PHP application written, say, for version 4.06, will almost surely NOT function for the latest version, 4.3.3. Why? Because they seem to break the most basic functionality in every single version.

In my experience, many people that call themselves PHP programmers have no clue whatsoever. Ask an average PHP programmer about operator precedence, and they'll say something to the effect of "WTF? Use parens!"

Thus your answer.

The same PHP programmers also tend to be completely unaware of security, HTML filtering, and other critical things that you HAVE to do for web applications.

If you must learn PHP, learn it AFTER you learn at least another few languages... Hell, even Java would be better to learn first.

(Of course, being the resident Perl guy hasn't influenced my opinion of PHP at all. Nope. Not a bit.)
 
Posted by Ultra Magnus (Member # 239) on :
 
Once I wrote a program that calculated interest on bank loans in Basic. I colored the text red and green, and I think I made it go "beep" when it was done.

Maybe it was more of a "bloop."

Yeah, that's what it was.
 
Posted by Cartman (Member # 256) on :
 
Move over, Mitnick.
 
Posted by MinutiaeMan (Member # 444) on :
 
Interesting perspective there, Charles... Actually, from what I already know about programming, I could tell a few things about PHP, so your distaste doesn't surprise me too much. (Stuff like not needing to declare variables before you use them; I know that's something you need to do!)

So then... would you suggest some alternative to PHP for integrating with MySQL databases? 'Cause that's why I've been learning it...
 
Posted by Charles Capps (Member # 9) on :
 
Why, Perl, of course. %)

Perl database access is easy, but tends to be obscure unless you know what you're looking for. As with everything Perl, there are two and a half billion different ways of doing things...

Here, have some comparison code that gets a list from the db, then updates... PHP first...

code:
$dbh = mysql_connect("localhost", "user", "pass");
if(!$dbh) {
echo "Could not connect to database: " . mysql_error();
exit;
} // end if

// $dbh == our database handle
mysql_select_db("mydb", $dbh);

// Make a query...
$result = mysql_query("select * from table where col_1 = 3", $dbh);
if(!$result) {
echo "Could not perform query: " . mysql_error();
exit;
} // end if

// ... then pull the info out of the DB, line by line, into an array
$results = Array();
$i = 0;
while($resline = mysql_fetch_array($result)) {
$results[$i] = $resline;
$i++;
} // end while

// We now have our results array. Loop through it and do stuff.
// (using the $i index from above as our array length rather than
// sizeof($results), just because I'm weird)
for($j = 0; $j < $i; $j++) {
$returned_val = do_something_smart_with_row($results[$j]);
$sql = "update table set col_2 = '$returned_val' "
. where col_1 = '" . $results[$j]["col_1"] . "'";
$thisres = mysql_query($sql);
if(!$thisres) {
echo "Could not perform query: " . mysql_error();
exit;
} // end if
} // end for

mysql_close($dbh);

And now, in Perl:

code:
use DBI;
our $dbh = DBI->connect("DBD:mysql:mydb", "user", "pass")
or die "Could not connect to database: $DBI::errstr";

# $dbh is the database handle

# Query from the DB and get all the results in a single hash
my $results = $dbh->selectall_hashref("select * from table where col_1 = 3")
or die "Could not perform query: $DBI::errstr";

# Loop through the hash and do stuff
foreach my $key (keys %{$results}) {
my $returned_val = &do_something_smart_with_row($results->{$key});
my $sql = "update table set col_2 = '?' where col_1 = '?'"
# the ?s get replaced with the 2nd+ arguments in the
# do() method of the database handle...
$dbh->do($sql, undef, $returned_val, $key)
or die "Could not perform query: $DBI::errstr";
} // end foreach

$dbh->disconnect();

The main difference between the code, other than the verbosity, is that all the database functions in the PHP script are database-specific, and all the database functions in Perl are generic. While PHP does have a database abstraction layer, it's not built into the language. (Then again, neither is Perl's DBI... but considering that DBI is all there is to connect to a DB in the first place, that's no big loss.)

Thus, moving the Perl script to another database system later is just a matter of making sure the SQL works, while every single command would need to be translated in the PHP script. This annoyed a coworker so much that, when he transitioned to PHP from Perl, he created a PHP object that duplicated the parts of DBI that he used.

Perl also has a number of other advantages in the convenience departments... for instance, having to escape quotes in prints/echos is a major annoyance in PHP... but in Perl, you can just define another quote character for that one string. I.e.:

$php = "There \" are \" too\"\" many" . '\'quotes\' in' . "\" this\" string";
$perl = qq~There " are " too"" many 'quotes' in" this " string~;

PHP does have its advantages.. often, hosts will compile everything and the kitchen sink into PHP, meaning often it can do graphics, PDF generation, and other nifty things "right out of the box"... Perl can do all of the same things, but hosts often don't compile the modules in by default... and compiling modules would require shell access.

PHP also often has a major speed advantage. Once compiled and running, PHP and Perl scripts are pretty much the same speed... but the startup/compile phase is a killer. PHP is often compiled right into the web server, meaning it practically stays resident in memory. PHP also has the ability to keep cached compiled copies of scripts in memory, which can be a major speedup.

Doing the same things in Perl requires the mod_perl Apache module, which isn't something many shared hosting providers offer. (Writing code for mod_perl is also rather complex. You can't just plug your script in and expect it to work without modification.. sometimes as little as two or three lines, thankfully)

Anyway. I've ranted enough. Personally, I prefer Perl because of the consistancy and the flexability of use and syntax. I don't care for PHP because it gets horrible inconsistant, forces the authors to be very verbose (huge function names) and has a number of forced syntax quirks.
 
Posted by Sol System (Member # 30) on :
 
Computer Science 110: Dropped.

No.

But, man. I do not have such strong or informed opinions on anything. I live a shadow life.
 
Posted by Jason Abbadon (Member # 882) on :
 
Computer....code?
Like Bible Code? [Confused]

Can you predict a thread's future by decrypting this code?

This sucks: I forgot my decoder ring.

Stop me before my wise-ass refrences drift into codes of conduct like Bushido....
 
Posted by Harry (Member # 265) on :
 
quote:
Hell, even Java would be better to learn first.
Well... except you then end up using PHP as an object-oriented language, and PHP objects don't behave like they do in a real OO language, and I've heard it's not particularly efficient either in PHP.

Another thing about PHP is it's easy integration with HTML. While this might look very nice in the beginning, it turns into a readability nightmare for anything larger than 10 lines.
 
Posted by Cartman (Member # 256) on :
 
verbosity is good
 
Posted by Cartman (Member # 256) on :
 
No, but really, Perl doesn't float my boat. It's lazy, man... every single freakin' keystroke has to be correct or you're slapped with an undefined subroutine &main::find_next called at frob.pl line xx unless you resort to symbol::approx::sub which can make your life easier BUT then you get into all sorts of trouble with the autoload function which is mainly used to write even lazier accessors for object data because Perl stores all information about non-lexical variables and filehandles and subroutine names in a massive hash which you can inspect yourself BUT doing so requires code which is so close to spaghetti you could plate it up and serve it to an Italian so the easy way out is to use devel::symdump which (thankfully) provides a friendly and clean interface to the symbol table and various other neat tools like if you are scratching your head trying to resolve an inheritance tree the isa_tree method will help and if you want to find exactly what a module exports into your namespace the diff method is a constant friend as are the eighty billion date and time modules you never need but are there for your amusement nonetheless.
 
Posted by PsyLiam (Member # 73) on :
 
I have a worrying feeling that I am suppossed to know all this stuff for my degree.
 
Posted by Mucus (Member # 24) on :
 
Yeah, I know the feeling.
*stares ruefully at the "C++ For Java Programmers" textbook*
 
Posted by Ritten (Member # 417) on :
 
A vast majority of the people that I have seen don't retain much of that information, the basics and knowing where to look things up is the biggest thing.
 
Posted by PsyLiam (Member # 73) on :
 
Tell me where to look things up!
 
Posted by Wraith (Member # 779) on :
 
Google

Of course.

Or there are apparently these things called books...
 
Posted by Ritten (Member # 417) on :
 
Rob can introduce you to this fellow named Dewey also...

I was thinking of lawyers, programmers, and the such that can resort to looking things up as needed, doctors also, since all these tests done these days give them ample time to consult the net or hospital library....
 
Posted by PsyLiam (Member # 73) on :
 
Doesn't really work if you are a GP. Or in Casualty. Or lots of other places.
 


© 1999-2024 Charles Capps

Powered by UBB.classic™ 6.7.3