LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-17-2009, 05:18 AM   #31
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454

Quote:
Originally Posted by Hko View Post
Sorry, I really can't help you with that. I don't know perl at all.
But I suspect "readable code" would be one.
As I wrote elsewhere - learn the alphabet first.

My other examples:

Code:
foreach my $element(@elements)
  {
  # do something
  }

unless($condition_is_met)
  {
  # do something
  }
- the point is that due to notation I can simply read

foreach my $element(@elements)

as

for each my element at elements;

I can read

unless($condition_is_met)

as

unless condition is met

and so on.

So, what's the problem with readability ? Does Python have "unless"
("unless($condition_is_met)" means if(!$condition_is_met), which can be better said if(not condition_is_met) ?

Does Python have "or", "and", "not" keywords which help readability ?
 
Old 02-17-2009, 05:31 AM   #32
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by Sergei Steshenko View Post
Well, Perl quite well implements "do what I mean" principle.

So, for starters, please translate the following into Python:

Code:
sergei@amdam2:~/junk> cat -n md_array.pl
     1  #!/usr/bin/perl -w
     2
     3  use strict;
     4
     5  my @array;
     6
     7  $array[0][1][2] = 123;
     8  $array[3][4][5] = 456;
     9
    10  warn "\$array[0][1][2]=$array[0][1][2]";
    11  warn "\$array[3][4][5]=$array[3][4][5]";
    12
    13  warn "\$array[3][4]=$array[3][4]";
sergei@amdam2:~/junk> ./md_array.pl
$array[0][1][2]=123 at ./md_array.pl line 10.
$array[3][4][5]=456 at ./md_array.pl line 11.
$array[3][4]=ARRAY(0x8194ddc) at ./md_array.pl line 13.
sergei@amdam2:~/junk> cat -n md_hash.pl
     1  #!/usr/bin/perl -w
     2
     3  use strict;
     4
     5  my %hash;
     6
     7  $hash{foo}{bar}{doo} = 123;
     8  $hash{goo}{dah}{bah} = 456;
     9
    10  warn "\$hash{foo}{bar}{doo}=$hash{foo}{bar}{doo}";
    11  warn "\$hash{goo}{dah}{bah}=$hash{goo}{dah}{bah}";
    12
    13  warn "\$hash{goo}{dah}=$hash{goo}{dah}";
sergei@amdam2:~/junk> ./md_hash.pl
$hash{foo}{bar}{doo}=123 at ./md_hash.pl line 10.
$hash{goo}{dah}{bah}=456 at ./md_hash.pl line 11.
$hash{goo}{dah}=HASH(0x8194e04) at ./md_hash.pl line 13.
sergei@amdam2:~/junk>
, and then we'll talk about human being concerned.
what is a real application or problem for the way the above is implemented? In other words, a use case.
 
Old 02-17-2009, 05:37 AM   #33
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by Sergei Steshenko View Post
As I wrote elsewhere - learn the alphabet first.

My other examples:

Code:
foreach my $element(@elements)
  {
  # do something
  }

unless($condition_is_met)
  {
  # do something
  }
- the point is that due to notation I can simply read

foreach my $element(@elements)

as

for each my element at elements;

I can read

unless($condition_is_met)

as

unless condition is met

and so on.

So, what's the problem with readability ? Does Python have "unless"
("unless($condition_is_met)" means if(!$condition_is_met), which can be better said if(not condition_is_met) ?

Does Python have "or", "and", "not" keywords which help readability ?
That's why i said you have to really learn about Python to use how its used.
Code:
for i in a_list:
  print i
the above is your equivalent to your foreach() Perl construct. No pesky open and close brackets, no semicolons to denote end of statement. definitely easier on the eye. If Python don't have unless construct, it means it doesn't need one. Normal while loop with condition is enough to implement it.

the Python "not":
Code:
b=[1,2,3]
a=4
if a not in b:
 #do something
the Python "or"
Code:
if a in b or c in d:
  # blah blah

Last edited by ghostdog74; 02-17-2009 at 05:39 AM.
 
Old 02-17-2009, 06:01 AM   #34
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by ghostdog74 View Post
what is a real application or problem for the way the above is implemented? In other words, a use case.
???

I can, say, parse a text file and as a result create out of it a data structure.

And there can be reasons data (levels) in the data structure to have different from parsed items order.

So, parsed items are first stored in variables, and then a "line" (a path in the tree) is filled at once.

I.e.

Code:
# fill $var4
# fill $var3
# fill $var1
# fill $var2

$hash{$var1}{$var2}{$var3} = $var4;
But the question is pointless - I had a lot of such use cases, especially in EDA, STA, HW VLSI design as a whole.
 
Old 02-17-2009, 06:05 AM   #35
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by ghostdog74 View Post
...
If Python don't have unless construct, it means it doesn't need one.
...
Brilliant ! The knower of ultimate truth !!!

The holly war begins :-). But I am taking this to become my signature ;-)
 
Old 02-17-2009, 06:34 AM   #36
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 60
Quote:
Originally Posted by ghostdog74 View Post
If Python don't have unless construct, it means it doesn't need one.
Actually, this strikes me as true by design - to twist a phrase. As I understand it, Python's guiding principle is that there should be one (and only) one way to do things. Thus, you don't get both if-not and unless - just one. Perl's guiding principle (or one of them) is that there should be lots of ways to do things. Thus, you get if-not and unless, while-not and until, etc.

For whatever it's worth, Damian Conway recommends never using unless or until in his Perl Best Practices book.

We now return you to your regularly scheduled holy way - already in progress...
 
Old 02-17-2009, 06:38 AM   #37
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by Telemachos View Post
Actually, this strikes me as true by design - to twist a phrase. As I understand it, Python's guiding principle is that there should be one (and only) one way to do things.
you are right. I find this makes code consistent.
 
Old 02-17-2009, 07:38 AM   #38
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Telemachos View Post
Actually, this strikes me as true by design - to twist a phrase. As I understand it, Python's guiding principle is that there should be one (and only) one way to do things. Thus, you don't get both if-not and unless - just one. Perl's guiding principle (or one of them) is that there should be lots of ways to do things. Thus, you get if-not and unless, while-not and until, etc.

For whatever it's worth, Damian Conway recommends never using unless or until in his Perl Best Practices book.

We now return you to your regularly scheduled holy way - already in progress...
Well, even in "C"

Code:
#define UNLESS(cond) if(!(cond))
- any language with macros allows such a trick.

And syntax sugar, well, sometimes is really sweet.

But my point is different - languages evolve, so a claim that if a language doesn't a feature it means it doesn't need it is funny.

...

Well, in our comparison of features we haven't elaborated on data/code export/import yet.
 
Old 02-17-2009, 08:40 AM   #39
xhypno
Member
 
Registered: Sep 2004
Posts: 62

Rep: Reputation: 16
I have done extensive work in PERL, Python, PHP, LUA, and many compiled languages.

It is all a matter of what suits your needs. Any programmer that pigeon holes their beliefs into a single language is fit into one thing, A BAD PROGRAMMER! No one language is going to fill all needs.

If I have to write a fast web app, I use php. If I have to write a fast text or log parser I use PERL. If I have to write a fast multi-control script that can be extended, I use Python. If I am writing data interpreters for MySQL or tight embedded data controls, I use LUA. It is all about solving a problem with the most appropriate means.

A program to parse an apache log to an easy to read format in PERL might be 20 lines of code, while it is 100 in Python, while a script to control the flow of the start of a daemon or string of daemons on a node in a computer cluster can be done with PERL, the script would be much shorter and easier to manage in Python, AGAIN IT IS ALL ABOUT THE PROBLEM YOU ARE SOLVING.

So stop the 2 year old argument that makes you all look like horrid programmers.
 
Old 02-17-2009, 09:01 AM   #40
arfon
Member
 
Registered: Apr 2004
Location: Texas
Distribution: Slackware
Posts: 201

Rep: Reputation: Disabled
This is funny, after 3 pages of bickering, the question hasn't really been answered-

Quote:
I just saw that Python is "the programming language of the year".
I study Java (for 2 weeks now) at my school and I think its good enough.
What makes python so good and popular?? Can it do all the thinks Java and C++ can??
No, Nesrail, Python cannot do all the things that C++ and Java can do. They compile into binaries that you can take and put where ever and Python compiles on the fly and dumps the binary after it's run. It's like comparing boats to cars, both are vehicles but they serve different purposes.

EXAMPLE: If you want to write a game, use C++. If you want a program to make sure databases stay clean, use Python (or Perl).

Now, as for the "programming language of the year", don't read much into that. Basically more Python guys wanted it to win so they voted en masse.


As for the Perl vs. Python argument, After reading all these pages, What I got out of it was:
1) Perl sucks because it can be hard to read.
2) Python sucks because it can be hard to read.
3) Perl sucks because it is too backwards compatible.
4) Python sucks because it's not backwards compatible enough.
5) Perl sucks because it's old and has too many features.
6) Python sucks because it's not old and doesn't have many features.

Did I miss any of the Perl vs Python points?

Last edited by arfon; 02-27-2009 at 07:56 AM.
 
Old 02-17-2009, 09:06 AM   #41
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by arfon View Post
As for the Perl vs. Python argument, After reading all these pages, What I got out of it was:
1) Perl sucks because it can be hard to read.
2) Python sucks because it can be hard to read.
3) Perl sucks because it is too back-wards compatible.
4) Python sucks because it's not backwards compatible enough.
5) Perl sucks because it's old and has too many features.
6) Python sucks because it's not old and doesn't have many features.

Did I miss any of the Perl vs Python points?
A suggestion for you. Learn Perl for 1 week. Then Learn Python for another. See and judge for yourself. That's the only answer. As for the above 6 points, you are joking right?
 
Old 02-17-2009, 09:05 PM   #42
arfon
Member
 
Registered: Apr 2004
Location: Texas
Distribution: Slackware
Posts: 201

Rep: Reputation: Disabled
Thanks for the suggestion but, I already know Perl and it KICKS ASS! No need to waste my time with Python.

So far, Perl has done everything I need.
 
Old 03-04-2009, 07:58 PM   #43
arfon
Member
 
Registered: Apr 2004
Location: Texas
Distribution: Slackware
Posts: 201

Rep: Reputation: Disabled
The answer: Because Google is pushing it. IMHO, it's not good, it's lacking.

The question: What makes python so good and popular??
 
Old 03-04-2009, 10:15 PM   #44
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by arfon View Post
The answer: Because Google is pushing it. IMHO, it's not good, it's lacking.

The question: What makes python so good and popular??
Nothing. I read a blog of somebody prominent at Google, and the guy dislikes Perl in favor of Python.
 
Old 07-01-2009, 10:54 AM   #45
jagooch
LQ Newbie
 
Registered: Sep 2008
Posts: 7

Rep: Reputation: 1
The original question was ..."why was Python voted the language of the year?"

Let's stay on topic.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Review: Programming in Python 3: A Complete Introduction to the Python Language LXer Syndicated Linux News 0 01-26-2009 04:50 AM
python update - Unable to load GTK2 Python bindings: No module named gtk itpedersen Linux - Software 2 10-03-2008 03:44 AM
LXer: Charming Python: Python elegance and warts, Part 2 LXer Syndicated Linux News 0 08-31-2007 08:40 AM
LXer: Move to python 2.4 / Changing the packaging style for python packages LXer Syndicated Linux News 0 06-13-2006 07:54 PM
python problem - compiled from source - python -V still showing old version txm123 Linux - Newbie 1 02-15-2006 11:05 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration