TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Wrapping An OO module in a procedural API using Exporter::Simple (perl)

18 pointsby f00li5hover 14 years ago

1 comment

jrockwayover 14 years ago
A few thoughts. Don't do "package Foo; { ... }". Nobody else in the world has ever done this. It's completely pointless and confuses people.<p>Use Sub::Exporter instead of Exporter::Simple. Bigger community, more testing, more features. (Attributes? No thanks.)<p>Don't let your users use global variables and singletons. Don't make an OO interface that needs a functional interface on top. Pick the right one for the job. If there is state, it should be an object. If there is no state, it should be a set of functions.<p>File::Spec is OO because someone was way too clever when implementing it, not because it is actually OO. (The cleverness is that @ISA is changed to File::Spec::YourOS at runtime, and then File::Spec-&#62;whatever delegates to File::Spec::YourOS-&#62;whatever magically. This is clever, but not the best way to implement that.) File::Spec::Functions is a band-aid on top of a flawed design. Design your module's interface correctly from the beginning, and you won't need to write 300 lines of hacks on top of it.<p>(This is why people hate Perl, because many people start using Perl, get excited by super-amazing-awesome-cool features like changing your class's inheritance hierarchy at runtime, and write confusing and unmaintainable code when they could have <i>not</i> used the cool feature instead. A lot of dynamic language features are there for the very special 0.01 percent case. Your program is probably not that, so just do it normally, see how you like it, and go from there. With Perl, you <i>can</i> write very clever code. Try not to. &#60;/rant&#62;.)
评论 #1865410 未加载
评论 #1864462 未加载
评论 #1865475 未加载