6 ms·
How the fuck is trim in Python?
- inerte 18y agoI hope there's no problem submitting my own blog post. I've been thinking about making a website like the one I described on the post for a long time but never got up and did it. Anyway, I also hope the "fuck" up there isn't too offensive. I don't live in the USA (and english isn't my primary language), and while it seems people use this word every minute of their lives, on written material (and social contexts) of the web is rarely seen, so I don't quite grasp the ethic relationship of daily english and the internet. If you could read my mind (in portuguese) and see what I really think when I am trying to remember how trim is named in Python, worse profanities would appear anyway :) Oh, and I don't know if this is "HN material". I've complained about some articles that appeared here, blog posts without much content at least. But I've also seen worse stuff live longer on the main page, so I thought, what better way to see if what I wrote would survive than just submitting it?
- bprater 18y agoAh, I wondered what nationality you were. (I'm Portuguese too, but not natively.) Fuck is a bit strong for this type of article. Also, rather than saying 'how the fuck', we would say, at least in American English, "what the fuck is 'trim' in Python?" or even more clearly, "what the fuck is PHP's trim in Python?" But yeah, I have the same problem when moving through languages. I know the concept, but I have to read through the docs to find out the exact function syntax.
- siong1987 18y ago.com.br - Brazil???
- okeumeni 18y agoYup
- okeumeni 18y agoI appreciate your remark on this post. In general I have to say I am sick of people using the "F" word so lightly on this forum. I have an 11 years old very curious daughter that I adore, she get on my laptop all the time and is very interested in what I do. I have been very concern about what will happen if she sees that I’m reading stuff with such language in it. We should all do something about this. Demod me if you want but this is a real problem from the concern parent that I am.
- tptacek 18y agoMine are 9 and 7. If your 11 year old isn't already using the word "fuck", I would be concerned about social norms. The fact is, the Internet is a big scary place, and Hacker News is the very least of the problem, so let's not bother addressing this issue.
- okeumeni 18y agoI’m far from being an expert on this, so take it easy from a fellow parent. There’s a huge difference about you reading or using profanity near you child than him/her hearing it on TV or reading on the internet.
- kirubakaran 18y agoWhile I don't give a fuck about your choice of words, I am unable to read the article as "Websense" blocked the website as pr0n coz of words in the URL :-(
- jsdalton 18y agoI think it's a really awesome idea. As others have pointed out, "what the fuck" is the right way to say it. More common than that these days is "WTF" (the abbreviation). This allows you to get the same point across without using profanity. (Keep in mind that in some environments like schools or corporations, sites with profanity can get flagged and blocked.) So maybe "WTF is ___ in ___?"
- j2d2 18y agoI gotta disagree about "what the fuck" being the right way to say it. I am not concerned about the rebellious nature of cursing, but I am bothered by using words that contribute so little to the meaning. I've heard arguments that they serve to express things in a more emotional manner. Like anything, they've been so over used that the emotional enhancement is diluted to simply being a socially rebellious expression. Edit: On this topic, I think people, at some level, are aware of this. That's why it's not as commonly found in written word vs. spoken word.
- tptacek 18y agoThe nice thing about it here is that it very effectively conveys the frustration that underlies the value proposition for the site.
- SapphireSun 18y agoAt some level I would like to use this sort of site for the humor value. It not only sympathizes with me; it empathizes with me AND works to solve my problem - so long as it works right. If it doesn't I'd be adding a few more colorful words to the mix :-) Edit: Grammar
- jsdalton 18y agoOh, I think what I meant was "how the fuck" was not idiomatic English, and that what he meant to say was "what the fuck." I more meant the "proper" way to say the phrase he was referring to.
- jcl 18y ago
- fallentimes 18y agoI think a well timed & placed swear word adds some zing. As long as you're posts and titles aren't filled with them, you should be fine.
- karim 18y agoI'm just tired of reading blog posts full of swearing. It's always the same bland content without nuances. I'm sure that you could have written a better post, without resorting to swearing - or perhaps you belong to the Zed Shaw school of writing.
- benmathes 18y agoApologies if this gets mentioned elsewhere, but I suspect you'll have trouble dealing with two functions in separate languages that do _almost_ the exact same thing, but differ in some tiny way that screws people up. Maybe they return different values on an error, one does it in-place while the other returns the new value, or even worse are the really tricky differences like what happens if certain variables are/aren't static.
- graywh 18y agoThat can be one of the most frustrating things about using a new language. Great idea, hope you can implement it yourself.
- sam_in_nyc 18y agoI think this is a great idea. What the fuck is <Language>'s [some string] in <another Language>? [some string] can even be common objects methods, like Array.splice For each mapping, you should allow comments to fill in the specifics. For example, VB has "String.left()" and "String.right()", which can both be achieved in by PHP's substr() if you pass the right params. Boy.. am I going to be hated for the languages I just mentioned...
- NyxWulf 18y agoI don't hate you. I think pity or scorn would be more appropriate. ;)
- ivank 18y agoFor operating systems, there's http://bhami.com/rosetta.html http://bhami.com/rosetta.html
- nailer 18y agoThat's vastly out of date - DGUX anyone? I've started on a modern RHEL / Ubuntu / Powershell Rosetta Stone in my own time. Let me know if you want to see it.
- eli 18y ago"How" seems like the wrong interrogative. Perhaps "Where the fuck is 'trim' in Python?"
- decadentcactus 18y agoOh man, I was thinking the same thing. Mine was going to be something along the lines of 'phptopython', where I could half document, half make a site about converting php code to python, or how to do similar things. I wanted it because I found it didn't exist when I was trying to learn Python. I figured if I knew what it was in php, it'd be easier to work on. Then, like yours, I figured a wiki would be good, and have each page dedicated to a code snippet, whether it is "using trim" or "finding the square root of a number". Haven't got around to it though
- nir 18y agoCool idea. There's already a similar site for PHP->Rails - http://railsforphp.com/ http://railsforphp.com/ - would be great to have something that works for multiple languages. My $0.02: Allow user annotation (ie, comments). Back when PHP was new, user comments on the function pages were very helpful for figuring out how to do stuff, what to avoid, known bugs etc. I often miss it when working with other languages.
- hs 18y ago"how the fuck is trim in Python? It’s called strip by the way." too much sex in holland (fat in usa)
- paddy_m 18y agocan anyone else not find the link to the actual site. I can't. I tried http://HTFITIP.com http://HTFITIP.com what's the url?
- raghus 18y agoI’ve been feeling lazy lately so go ahead and implement this if you want. Should be an useful tool. There's no such site now. He wants someone to write this because he thinks it will be useful
- ntoshev 18y agoGoogle would give you the answer if you just type any such phrase.
- mattmcknight 18y agoWhile the initial function mappings could be quite simple, I see the future of this being a bit like Google Translate for computer languages. We just need a Mechanical Turk wiki like process to get the longer snippets code translated. I used to work with ESRI ArcView software and its Avenue scripting language. When they changed their internal scripting to Visual Basic for Applications, there was a lot of work to be had translating scripts. (Now they support Python as a scripting language as well.) I wonder if for any given JVM language (Java, JRuby, Jython, etc.) you could write a decompiler for the bytecode that would take you back to a different source code language.
- strlen 18y agoOne thing: what works for PHP isn't necessarily a good approach to learning another language, such as Python. PHP's global space and the feel of "batteries included" is sharply contrasted to Python's typing and object oriented feel. Having people write PHP in Python would not only be counter-productive, the people being brought up on that style wouldn't get much out of python. The trim example specifically: line = "foo\n" new = line.rstrip("\n") vs. if we were to directly to transliterate from php, it would be string.rstrip(line,"\n") (which is quite a different style) This approach also under-emphasizes using language specific tools (e.g. interactive python, pydoc).
- NyxWulf 18y agoTypically the learning curve on a new language goes something like this. 1. Knows old language 2. Learns the syntax of new language 3. Writes old language style in new language 4. Through continued practice and learning in the new language, starts to pick up the idioms and styles of the new language. 5. Becomes fluent and well versed in the idioms, styles, advantages, and flaws of the new language. Can contrast old language with new language well and use the style most appropriate to the problem. 6. rinse and repeat Not everyone progresses all the way through the process when they pick up a language. In fact I'd argue that some people never even pick up the idiomatic way of doing something in a language even if that is their only language. I think you could think of this like an english-spanish dictionary. It's not going to teach you the idiomatic way of speaking, but it will give you the correct word to use. Which I would suggest is a milestone on the path to idiomatic speaking. * edit for formatting
- graywh 18y agoSorry, but it's Python that uses the "batteries included" phrase. http://www.python.org/about http://www.python.org/about http://www.google.com/search?q=python+ http://www.google.com/search?q=python+"batteries+included"
- gojomo 18y ago"How the fuck is..." is the wrong wording, at least in idiomatic American English. "What the fuck" (aka "WTF?") connotes more "this is wrong/surprising" than "could you please tell me the answer?". "WTF?" is often a rhetorical question, but even when it demands a response, the response is a situational explanation, not a mere bit of trivia (such as "trim is called strip"). "What the fuck is trim doing in Python?" is more idiomatic in its use of 'fuck', but would express surprise that Python has a trim() function, as if it were against the spirit of the language. Because your "How the fuck..." sounds a little like that in its use of 'fuck', it gives the wrong impression for what you're trying to achieve. (Clicking your link, I expected a rant, not a idea for a equivalence-lookup service.) To express curiosity about the right answer -- "what is the equivalent of trim in Python?" -- but with the same sort of irreverence possible via 'swear' words, a more likely wording from a native speaker would be "how the hell do you do trim in Python?" "How the hell" expresses exasperation but also suggests some genuine interest in a 'right' answer. (You sometimes see "how the fuck do I..." or "how the fuck do you..." also, but anything starting "how the fuck" is far less common than either "how the hell" or "what the fuck".) In general, using 'fuck' casually can be a problem, for a number of reasons. I believe the primary reason is that it is distracting -- it claims that the containing statement is emotionally important and demands special attention. Is a simple cross-programming-language lookup facility emotionally important? No. So some people will act 'offended' at use of a word with other 'naughty/private' connotations, and even some people who like to swear will feel like you've diluted the word's value. You need to save 'fuck' for really important uses, or it won't have any fucking meaning left at all.
- russell 18y agoHe also asked if anyone was offended if he linked to his own site. I've been wondering myself. I have been considering submitting some issues for discussion in the form of a two or three paragraph statement backed by an essay elsewhere. Given that the topic is of general interest to HN and is not self-promotional spam, does it fit with the HN etiquette?
- callmeed 18y agoAh, now I understand what you're getting at ... Indeed, this is a great idea. Would love to see someone like Joel Spolsky implement this as part of StackOverflow.com. I'd be interested in doing this in Rails ... if anyone wants to collab with me, let me know (email in profile)
- jawngee 18y agoBest quote in the article: "Web 2.0 baby, the users provide all the content, we make all the money."
- inerte 18y agoOP here, I am watching this thread but not replying to anyone yet, but I want to clarify this phrase. It's not really mine (at least its meaning) but I couldn't find who said it first to give credit, since the words aren't exactly how I typed. Anyway, it's something that has bugged me for some time. Lots of "web 2.0" companies think that users will come and start to post a lot of stuff, and the reality is that unless you can give them some kind of semi-instantaneous gratification, they'll never post anything. Wish I could find who said it first. I think it captures a lot of the hype behind the web 2.0 buzzword.
- csytan 18y agoThis is a really good idea. Whenever I learn a new language, it is always a pain re-learning how to do common tasks. Is anyone interested in working on this as an open source side project with me? My preferred stack is Python, Django, Appengine, and jQuery.
- jodrellblank 18y agoOnce you get past integers and strings I think you'd start hitting language and library limitations where things don't translate smoothly - the same core reason that the languages are usefully different in the first place. Not at all web 2, but the PLEAC project ( http://pleac.sourceforge.net http://pleac.sourceforge.net ) has been working on equivalent samples of code in different languages for a number of years. These days I'd half expect it to be a crossbreed of Google Code and Google Translate.
- jgfoot 18y agoI started a project like this once, but never finished. Contact me if you want my incomplete "Perl to Python phrasebook." My goal was to help unfortunate Perl programmers migrate to Python. One thing to look out for: things that are functions in some languages are syntax in others, methods in others, and complicated recipes in others. You need to give people sample code. For example, look at how each language wants you to express "length of an array/list:" Python: numbers = [4,8,15,16,23,42] print len(numbers) # yields 6 Perl: @numbers = (4,8,15,16,23,42); print $#numbers + 1; # yields 6 # or... $numlen = @numbers; print $numlen; Not really a "function" at all in Perl.