3 ms·
I'd like to reply to your Unicode link with another link: http://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default/6163129#616312
by buster 15y ago
I'd like to reply to your Unicode link with another link:
http://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default/6163129#6163129 http://stackoverflow.com/questions/6162484/why-does-modern-p...
>Exceptions are built in:
Exceptions are built in? Ok, someone decided that this strangely named construct can also be used to emulate exceptions to a minimal degree (finally statement where? does it support "bubbling up" the exceptions over different modules? What if a module redefines signal handlers? I'm also not sure how the error message can be handed over multiple exceptions or how to catch different types of exeptions.. can probably be done but only by bloating up the code unnecessarily). The man page of eval shows a lot of issues and broken cases. This is the preferred way to do exceptions? Really?
Interesting link on your use of "if ($@)": https://www.socialtext.net/perl5/exception_handling https://www.socialtext.net/perl5/exception_handling
It looks like it's not a good idea to do that, because it's a global variable (which in itself shows bad design decisions in the language itself, IMHO).
Finally, why are there myriads of Exception modules and Error handling modules and die/croak/carp modules, if it's already working so good in the base language? All of them try to solve problems in the base language (most of them even state that they exist because of quirks and problems in Perl on their man page). I never came across the need of looking for a replacement for those in another language...
> Yes, Perl assumes that you did not sleep through "Introduction to Data Structures". If the operation of "find out of collection X contains element Y" is one that you need to do often and/or need to be more efficient than linear search, you should not be using an array.
If i would care that much about speed i would expect the language to have an efficient C/asm implementation and not rely on millions of programmers to do it right. It's no magic, it's expected to just be there, by me.
Plus, not everyone that uses Perl is a good programer and this encourages bad behavior and hideous code which could just be avoided. Besides, i write lots of network heavy code. I could run multiple seti@home instances in parallel and not slow the script down. Tbh, i don't care about the speed of this operation. I far more care about convenience. It's not convenient for me to have to read and debug array search operations of other people because they didn't get it right.
One example: I was debugging a clients script and somehow for very few elements out of millions the script failed. Reason: He used regex to compare/search for elements which broke when the element contained a dot, which translated to the regex special character. It was easy to fix but it was a pain in the ass to find.
Another example:
I had to review and maintain code at a client (mind you this is a Dr. and shouldn't be that stupid. Nowadays i think he shouldn't even program ever again but this is a real case!): He obviously wasn't able to figure this out a nice way and wrote a lot of code to put single elements into a string and separate each element by a predefined string (#### in this case). Afterwards he was using regex with #### and ######## and added and removed those limiters and what not. It was a horrible day for me to read this and took hours to even figure out what he tries to achieve. Imo, this person shouldn't touch an editor ever again, but the point here is: I bet you 100$ that he wouldn't have done this in Java or Python or Ruby or whatever, just because it's easy to do in those languages.
Another point is: Very often i came across the recommendation to convert the array to a hash and then check for the key. What recommendation is that? When i have a data structure that is best represented as array, convert it for a simple operation? ugh...
- Mithaldu 15y ago> I'd like to reply to your Unicode link with another link: > > http://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default/6163129#6163129 To which i have to say that both the Great Unicode Shootout as well as that answer are written by the same person. The point being: Yes, Perl's Unicode support is not perfect. But honestly? It's still the best you can get out there. > >Exceptions are built in: > > Exceptions are built in? The both of you are conflating two things here: - Exception flow control - Exception objects The former is in fact implemented in Perl core via eval { literal code block }. In earlier versions of Perl there were issues where DESTROY blocks, called on object destruction, were able to clobber $@, i.e. the error message. Thus Try::Tiny has become the preferred method of doing exception flow control: my $x; try { die 'foo'; } catch { warn "Got a die: $_"; } finally { $x = 'bar'; }; Mind, that issue has been fixed in 5.14 ( http://perldoc.perl.org/perl5140delta.html#Exception-Handling http://perldoc.perl.org/perl5140delta.html#Exception-Handlin... ), so if you're above that, you can safely use eval for your exception flow control. > does it support "bubbling up" the exceptions over different modules? Yes, evals can be nested. > What if a module redefines signal handlers? If it does it via local it won't even concern you. If it does it plainly you're in a bit of a bind, but in practice this kind of thing happens exceedingly rarely on CPAN outside of self-contained applications or testing/installing code. > I'm also not sure how the error message can be handed > over multiple exceptions You die with an array reference containing the interesting exceptions. > or how to catch different types of exeptions. If you know what kind of exception you expect, you write code that interrogates the scalar for that. For example, if you're expecting an object of a certain type: handle_exception( $_ ) if blessed( $_ ) and $_->isa('Exception::Parse'); > Finally, why are there myriads of Exception modules and > Error handling modules and die/croak/carp modules Because we're collectively still trying to decide how to best handle exceptions. > I never came across the need of looking for a > replacement for those in another language... In other languages you get a solution plopped in front of you and have to accept it because you cannot even implement your own exception handling. If they got it right, great. If they didn't ... welp. Anyhow, that was only the first part. The second part is Exception Objects, which is where a lot of the various CPAN modules come in. Since Perl does not provide a native exception object, you can return literally anything you wish and many people experimented to see which kind of exception object they wanted. The concensus for this has landed on Exception::Class. > Another point is: Very often i came across the > recommendation to convert the array to a hash and then > check for the key. What recommendation is that? When i > have a data structure that is best represented as > array, convert it for a simple operation? ugh... Those recommendations are bullshit and that's where you're right. However the fact that you think Perl does not have tools to search through arrays shows a glaring gap in your knowledge. As i mentioned in another comment, Perl has excellent facilities for searching through arrays: > `my @hits = grep { $_ eq 'dogfood' } @array;` > > Alternatively: > > `use List::Util 'first'; my $has_dogfood = first { $_ eq 'dogfood' } @array;` > > And this is in core.