Ok, so I figure it's about time to live up to the title of this blog, since I've spent the vast majority of the language discussion firmly planted in parentheses. Aside from the fact that my company is starting a project in Erlang, I've also been scripting Python and Ruby pretty heavily.
They're actually not very different languages. Neither is perfect from my perspective[1], and neither sucks. If I had to, I could get work done in both (and having gone through the Ruby chapter in 7 Languages in 7 Weeks, I'm more inclined to look at Ruby for my next big project than I used to be). To start with, here's a boiled down, no-nonsense table that represents my perspective.
...is more annoying than... | |
len([1, 2, 3])
|
[1, 2, 3].length |
"foo " + bar + " baz" or
"foo %s bar" % bar
|
"foo #{bar} baz" |
", ".join(["one", "two", "three"]) |
["one", "two", "three"].join ", " |
map(lambda a: a + 1, [4, 3, 2, 1]) ## still makes more sense ## than join or len, though |
[4, 3, 2, 1].map {|a| a + 1} |
a = [4, 3, 2, 1].sort()
a[0]
|
[4, 3, 2, 1].sort[0] |
nothing.jpg | foo.methods.sort |
require 'optparse' require 'pp' require 'fileutils' |
import optparse, fileutils
## I also prefer the more granular
## symbol access I get with python
|
sudo apt-get install ruby-full irb |
python |
...is about as annoying as... | |
def aFunction(foo, bar): #do stuff return baz |
def a_function(foo, bar) #do stuff baz end |
with tempfile.NamedTempFile() as tmp: tmp.write("Test test\n") ##more stuff tmp.flush() popen(["lp", "-d", "a-printer", tmp.name()]) |
Tempfile.open() do |tmp| tmp.write("Test test \n") ## more stuff tmp.flush system("lp", "-d", "a-printer", tmp.name) end |
So I am slightly biased, but like I said earlier, not enough to actually decry either language. The biggest point in Ruby's favor is its handling of blocks (as seen in that tempfile pseudo-code). I like having an expression that says "Create an entity, do this stuff and then clean up", without having to clean up myself. Python doesn't like that.[2] Gotta admit, I boggled at the join
syntax the first time around. Rhetorically, who the hell decided it makes sense that a join
operation is something you do to the delimiter, rather than the list? In my opinion, it would even make more sense to make it a standalone function a-la len
.
I really like the syntactic whitespace in Python.
def something(): foo() bar()seems like it's cleaner than the Ruby equivalent. Except that when I want to return the result of
bar
(which I do quite often, given that I much prefer functional programming to OO), I need to do so explicitly. Ruby has me waste an additional line on end
, but returns implicitly. While I'm at it, Python libraries seem to be heavily anti-functional programming. They do the standard "OO" thing of exposing functionality via classes, but they also typically have a heavy reliance on side effects, which makes it harder than it ought to be to compose things. A recent example I had to go through involved using pyPDF
and reportlab
to process existing PDFs. You can do it, but the amount of fiddling involved is nontrivial if you want to decompose the problem properly because you need to do so by setting up multiple instances of PdfFileReader
/canvas
and making destructive changes to them.
Also, not represented in the table is how much easier it is to install python
packages in Debian. While gem
frequently errors on something, I've yet to find a package I need that I can't either apt-get
or retrieve using python-setuptools
. That's worth something (in fact, it's worth enough that I've been procrastinating on a ruby port of get-youtube-series
, which used only default components in Python, but requires several installs in Ruby).
The last thing that table doesn't encompass is the version situation. That's a fairly major one from my perspective, but I'm not sure how serious it actually is. Python 3 has been out for quite a while, but it's not uncommon to see "Supports Python 2.7" on various frameworks/utilities. Squeeze still provides 2.6.6, Django still requires 2.[4-7] and Google app-engine is still asking for 2.5 (with 2.7 being supported as an "experimental" feature). That's less than encouraging. By contrast, Ruby 1.9 is fairly widely supported (though the Debian repos are still at 1.8.7). That just doesn't seem to bode well for the next version, regardless of how enthusiastic Rossum is about it.
Footnotes
1 - [back] - Though, to be clear, my opinion is that Ruby gets a damn sight closer than Python.
2 - [back] - Thank you Brendan Miller for pointing me to the with
statement (documented here, here and here) which does emulate blocks well enough for my purposes.
For the tempfile thing, you should use python's with statement. It's actually very similar to lisp's with-* macros like with-open-file, but a little more flexible since it defines a general interface for releasing any resource...
ReplyDeletewith tempfile.NamedTemporaryFile() as tmp:
tmp.write("Test test\n")
tmp.flush()
subprocess.popen(["lp", "-d", "a-printer", tmp.name()])
This will of course, properly clean up in the face of an exception.
@Brendan Miller: Thanks! Updated the article to reflect that point.
ReplyDeleteI took another look. You should also replace:
ReplyDeletemap(lambda a: a + 1, [4, 3, 2, 1])
With [a + 1 for a in [4, 3, 2, 1]]
map isn't really used much in python because list comprehensions/generators do the same job better.
The first time I saw the loop macro in CL, I thought of how similar it is to python comprehensions and generators.
adapazarı eskort
ReplyDeleteadana eskort
aksaray eskort
bartın eskort
yalova eskort
eskort
düzce masöz
manisa masöz
izmit masöz
görükle masöz
YENİ PERDE MODELLERİ
ReplyDeletenumara onay
vodafone mobil ödeme bozdurma
Nft Nasıl Alınır
ankara evden eve nakliyat
TRAFİK SİGORTASİ
DEDEKTOR
Kurma website
ask romanlari
Smm Panel
ReplyDeletesmm panel
iş ilanları
İNSTAGRAM TAKİPÇİ SATIN AL
hirdavatciburada.com
beyazesyateknikservisi.com.tr
Servis
tiktok para hilesi indir
Dynamic Health Staff stands at the forefront of nursing recruitment in India, seamlessly connecting exceptional nursing professionals with reputable healthcare institutions nationwide. Our meticulous selection process ensures we recruit only the most skilled and compassionate nurses. We offer customized training programs that equip our candidates with the latest industry knowledge and skills. Our efficient placement procedures facilitate their smooth integration into healthcare teams. We are renowned for our unwavering commitment to excellence and ethical practices. Our dedication to continuous career development enables our nurses to thrive professionally. Trusted by the medical community, Dynamic Health Staff is committed to raising healthcare standards throughout India.
ReplyDeletehttps://dynamichealthstaff.com/
Choosing the best hosting plan in India involves assessing reliability, support, and features. Hostinger offers exceptional affordability with plans starting at ₹79/month, featuring a 99.9% uptime guarantee and easy-to-use interface, perfect for beginners. Bluehost stands out for excellent customer support and comprehensive packages starting at ₹199/month, including a free domain for the first year. For budget-friendly users, MilesWeb provides plans at ₹60/month, complete with free SSL and round-the-clock support. HostGator India excels in versatility, offering shared hosting plans from ₹99/month and VPS options for advanced requirements. Lastly, BigRock introduces robust plans from ₹99/month, offering unmetered bandwidth and seamless scalability.
ReplyDeletehttps://onohosting.com/
Breast cancer surgery costs in Delhi can fluctuate greatly depending on whether treatment is sought at government or private hospitals. Government hospitals typically offer more economical options with costs ranging from ₹80,000 to ₹2,00,000. In contrast, private hospitals, which provide advanced facilities and comprehensive care, may charge between ₹3,50,000 and ₹8,00,000 or even more. Key factors influencing these costs include the type of surgery performed, the surgeon's expertise, the anesthesia used, and the duration of the hospital stay. Ancillary expenses such as preoperative diagnostics, medications, and post-operative care can also add to the overall financial burden. Patients are encouraged to explore financial aid options including health insurance, governmental schemes, and support from charitable organizations to help manage these costs effectively.
ReplyDeletehttps://www.breastoncosurgery.com/services/breast-cancer-treatment-cost-in-delhi/
Dr. Neha Kapoor is a distinguished colorectal surgeon in Ahmedabad with over 18 years of expertise. Her proficiency in both traditional and minimally invasive surgical techniques ensures optimal outcomes for patients. Dr. Kapoor is associated with premier hospitals equipped with advanced medical technology, allowing for comprehensive and high-quality care. Her patient-centered approach focuses on personalized treatment plans tailored to each individual's condition and needs. She is highly respected for her meticulous surgical skills and compassionate consultations, which significantly enhance patient confidence and comfort. Dr. Kapoor remains actively engaged in medical research, continuously updating her knowledge to incorporate the latest advancements in colorectal surgery. Her dedication to excellent post-operative care further solidifies her reputation as a trusted specialist in Ahmedabad.
ReplyDeletehttps://drvirajlavingia.com/colorectal-cancer-specialist-in-ahmedabad
Dr. Manisha Sharma is a distinguished breast cancer specialist in Mumbai, celebrated for her extensive experience and compassionate patient care. With over 24 years in the field, Dr. Sharma is adept in both traditional and contemporary surgical techniques, achieving outstanding treatment results. She is affiliated with top-tier hospitals that provide advanced technology and all-encompassing cancer care services. Dr. Sharma’s patient-focused methodology emphasizes creating personalized treatment plans tailored to each patient’s specific needs. Her precise surgical skill and empathetic consultations have earned her high regard from both patients and colleagues. Actively participating in medical research, Dr. Sharma keeps abreast of the latest developments in breast cancer treatment, underscoring her standing as a trusted specialist in Mumbai.
ReplyDeletehttps://drnitanair.com/about/about-top-breast-cancer-surgeon-mumbai
Dr. Shona Nag is a highly esteemed breast cancer specialist based in Pune, celebrated for her unparalleled clinical expertise and empathetic patient care. With extensive experience in diagnosing and treating diverse breast cancer cases, she utilizes state-of-the-art techniques such as genomic testing and targeted therapies. Her multidisciplinary approach ensures comprehensive care through close cooperation with oncologists, radiologists, and pathologists. Committed to continuous medical education, Dr. Nag stays at the forefront of breast cancer treatment advancements. Respected by her peers and deeply trusted by her patients, she stands as a leading figure in breast cancer care in Pune.
ReplyDeletehttps://www.drshonanagbreastcancer.in/understanding-cancer/what-is-cancer-can-cancer-be-cured
Mobile app development companies in Delhi are at the forefront of technological innovation, crafting custom applications that cater to the unique requirements of diverse industries. They excel in creating engaging, user-friendly interfaces that enhance the overall user experience on both iOS and Android platforms. With a deep understanding of local market dynamics, these companies incorporate regional trends and preferences into their designs. They follow a comprehensive development process, from initial brainstorming and wireframing to testing and deployment, ensuring high-quality standards at every stage. Post-launch support and maintenance are also provided to adapt applications to evolving user needs. By harnessing modern technologies such as AI and machine learning, these firms deliver cutting-edge solutions that drive business growth. Partnering with a reputable mobile app development company in Delhi can significantly improve customer engagement and streamline operational efficiency. Ultimately, these services play a crucial role in navigating the rapidly changing digital landscape.
ReplyDeletehttps://olycoder.com/mobile-app-development-company
Minoxidil for women in Australia is a widely recognized treatment for hair thinning and loss. This topical solution works by stimulating hair follicles, encouraging regrowth, and preventing further hair loss. Available in various concentrations, it meets different stages of hair thinning, providing a tailored approach. Minoxidil is simple to apply and integrates easily into daily routines, typically causing minimal side effects. Consistent use of this treatment often leads to significant improvements in hair density and thickness, making it an effective and practical option for enhancing hair health and restoring confidence.
ReplyDeletehttps://generichealth.com.au/minoxidil-hair-loss/