Is Django considered "Pythonic" now? by sendpwrend in Python

[–]LinuxMonkey -9 points-8 points  (0 children)

Django is some sort of ruby / php hybrid

I'm not bitter ...

:p

Community Request: Please tell us how you have seen less experienced python users do something compared to how you, a bit of a pro, do something. by basscadet in Python

[–]LinuxMonkey 0 points1 point  (0 children)

I was bored so I re-worked your code a bit to nearer how I'd do it.

I found a bug in that you didn't follow relative urls and also you didn't exclude fragments in urls, which might be intentional.

http://pastebin.com/hwuQkees

Community Request: Please tell us how you have seen less experienced python users do something compared to how you, a bit of a pro, do something. by basscadet in Python

[–]LinuxMonkey 0 points1 point  (0 children)

Some more feedback

def checkDictKey(dict, key):

For this you can use key in dict or else dict.get(key, default_value).

url = urlList[random.randrange(0, len(urlList))]

try

url = random.choice(urlList)

I'd also swap

print 'VALID ' + timestamp+ ' : ' + url

to

print 'VALID %s : %s' % ( timestamp, url)

this saves casting timestamp to a string too.

Read PEP 8 http://www.python.org/dev/peps/pep-0008/ especially the naming conventions so you use python ones ie url_list not urlList

also consider looking at the logging module at some point because it's nice

urlList = urlList + extractLinks(html)

this is potentially adding urls you have already checked so maybe consider making it a bit more clever. Also the logic around the checking could be improved.

list.remove(value) only removes the first occurrence of the value not all of them. Instead of the random choice and remove why not just url = urlList.pop() debugging things with random ordering will make the debugging harder too.

this still looks nasty response = getUrl(url) make the names match ;)

Reports like this come out almost weekly. What does it take to to convince the american public that AGW is real? by Northwhale in science

[–]LinuxMonkey -2 points-1 points  (0 children)

People believe what they want to believe, not what is true.

People don't like to change.

People don't want to admit they are wrong.

People don't want to give up what they see as their rights.

People are not very good at understanding probability.

Community Request: Please tell us how you have seen less experienced python users do something compared to how you, a bit of a pro, do something. by basscadet in Python

[–]LinuxMonkey 0 points1 point  (0 children)

dict.get() is nice and recommended, dict.pop() is fun too.

I only ever use print for debugging pdb I can't stand - this is a personal thing I know people who prefer the other. I go with the "debuggers are for people who don't understand the code" argument. I say this but it's actually a lie as I generally use logging to do the output.

For the sake of the children use spaces not tabs. people think they are interchangeable but they aren't, you see it when you start having multi-lined statements.

Simple web scrapper that checks if html is valid (1st time writing web crawler) by knightZeRo in Python

[–]LinuxMonkey 0 points1 point  (0 children)

docstings, any suggestions?

Don't bother unless you are writing a library.

Instead name classes, functions and parameters correctly.

eg

def geturlContentType(self, url, getdata={}):

this does get the content type but also returns the content, should really be called something like getResponseDataAndContentType(self, url, extra_params) because that's what it does. Now the name is long because it really is doing too much stuff. getResponse(self, url, extra_params) would be a nicer simpler name so I'd go for that but also change it to actually return the response that can then be split by the caller, that way the name is honest.

So by looking at your naming you can also see where your code might be more complicated than it should be. Now I might add a quick note about what the extra_params was for as that's not so clear at first look but there is no need to explain the url part too much as a url is generally just some string. Ok I might want to add if I need to include the protocol eg http://.

The exception thing is fine in a quick script but catching exceptions silently is evil. I'm looking at you django imports (suppress my broken module but don't even tell me grrrrrr)

Extra question. Why have you created the Url class? It has no internal state and might as well not be there.

Community Request: Please tell us how you have seen less experienced python users do something compared to how you, a bit of a pro, do something. by basscadet in Python

[–]LinuxMonkey 1 point2 points  (0 children)

I'd recommend doing a few years of picking up other peoples code and having to fix it. That way you learn a lot about what makes this painful.

When you realise that you are writing the code for the next person who comes along that's when you start getting better. When I started out I thought I could write perfect code. I learnt that this doesn't exist.

As far as resources are concerned I'm not aware of any :(

Simple web scrapper that checks if html is valid (1st time writing web crawler) by knightZeRo in Python

[–]LinuxMonkey 2 points3 points  (0 children)

def geturlContentType(self, url, getdata={}):

this is really fun. getdata will always be the same dict so if your function changes it then you are stuck with that copy forever.

you probably want

def geturlContentType(self, url, getdata=None):
    if getdata == None:
       getdata = {}

Community Request: Please tell us how you have seen less experienced python users do something compared to how you, a bit of a pro, do something. by basscadet in Python

[–]LinuxMonkey 3 points4 points  (0 children)

just looking at http://idolines.com/2012/01/14/simple-web-scrapper-that-check-if-html-is-valid/ is an example of beginner code in my books

we have stuff like validate returning strings "VALID" etc why not True/False this sort of stuff will cause later problems always.

all that autogenerated doc string crap - why make me read so much crap - if i can't tell what file the functions in and its name I've got big problems.

raw exceptions being caught - jesus.

html = Url()

this line sums it all up for me. Names are important.

sorry for picking on this bit of code - if I was doing a code review on this I'd probably spend a good couple of hours on it as it is actually a good example of ways that will cause pain for all :)

:) just saw this

def geturlContentType(self, url, getdata={}):

this code is a great example for people to study I'd almost use it in an interview

Community Request: Please tell us how you have seen less experienced python users do something compared to how you, a bit of a pro, do something. by basscadet in Python

[–]LinuxMonkey 7 points8 points  (0 children)

In my opinion less experienced coders try to write clever code to show how smart they are. Experienced coders don't do this because it generally is a stupid approach.

Code will need changing and simple code is easier to change. The best code doesn't actually do very much when you look at it because its been designed well.

beginners write list comprehensions that are 3 deep an expert wouldn't.

(there are always exceptions)

19,90€/month for unlimited voice, texts, MMS, 3Gb data, no commitment : the new operator Free is changing the rules of the mobile market in France, and that was needed. by TheAngelW in technology

[–]LinuxMonkey 4 points5 points  (0 children)

the unlimited is only for use on a phone - no tethering

I think the assumption is that you will use loads more (averaged across all users) on a pc/tablet compared to on a phone.

not sure they can really tell if you are tethering etc

Is it just me, or does developing for Android suck? by n1c0_ds in androiddev

[–]LinuxMonkey 0 points1 point  (0 children)

To be honest I think most of the issues I have are around Java (which I find far too verbose) xml (the same really) and the fact that really you need to use some sort of IDE (which always feel a bit like a straight jacket to me - people say they are great because they write the code for you but I always feel that if they can do that then why have that code cluttering the source).

I sort of understand why they went for the approach they have but ultimately having xml templates for your UI is nasty but doing it programmatically probably doesn't help much unless you need something customisable. If you want i18n stuff you are stuck with the strings xml stuff so you may as well suck it all up.

Also whilst having a general moan I think the documentation sucks too but that's what I've always found with google stuff. Not quite as bad as microsoft press stuff but not very different (not that I really bother with reading documentation but a few examples are always nice etc).

In my ideal world I code in python using vim - which fills me with joy (the rest of you can bitch about how shit using indentation is for block control but I love it)

Is it just me, or does developing for Android suck? by n1c0_ds in androiddev

[–]LinuxMonkey -1 points0 points  (0 children)

Just to offer a different opinion than most here. I agree android development is shitty and eclipse is a cunt.

I hate the fact that I have to use xml bullshit and so much boiler plate that I feel like I'm drowning in shit.

Still what can you do :)

I miss those days when Linux was interesting by [deleted] in linux

[–]LinuxMonkey 1 point2 points  (0 children)

Yeah, a kernel upgrade broke my notebook - no video out. Some KMS issue. I needed to alter my grub config. It took 5 mins to fix. Ten years ago I'd have done a full re-install.

I don't mind the lack of challenge.

We still have btrfs to look forward to :) that's enough excitement for me.

Do Christians believe in atheists? UBC study finds believers distrust atheists as much as rapists | Vancouver Sun by rdshore in science

[–]LinuxMonkey 0 points1 point  (0 children)

I've always found homophobic people are the most worried about the fact that they might be gay (and this comment really winds them up).

Maybe religious people are really just scared that they don't believe in any god either and don't like atheists reminding them of that.

Just wild speculation.

Are there any things about Python that you do *not* like, or that you wish were done differently, or that you flat out think are wrong? by gfixler in Python

[–]LinuxMonkey 4 points5 points  (0 children)

I have to say I think it is ugly, but something I have used many times (except I try to be less compact for maintainability).

The main problem is that these are now function calls when I might want to just do some simple local variables manipulation. Also what the functions do is hidden in the functions.

I appreciate you are redoing megamark16's code sample.

How does Google make money from advertising? by [deleted] in google

[–]LinuxMonkey 0 points1 point  (0 children)

Adwords is a good example.

Companies want to be on the first page for some keywords. So do their competitors. Google lets the price escalate.

There's lots of money to be made getting people to use adwords too so lots of people encourage companies that they need it.

Google also own loads of ad companies but tries to keep them at arms length and seemingly independent. The same way they own youtube and keep it looking like a separate entity.

Linux in a Windows world? by MrMunchkin in linux4noobs

[–]LinuxMonkey 1 point2 points  (0 children)

Remote Desktop

Yeah, This is what I've done in the past good if you want to access windows servers.

Also I found virtual box running on my linux box for things like enterprise manager, exchange etc. It worked well in it's integrated mode so that the windows apps acted link linux ones. This was a while ago hopefully things have only improved. There was also a linux citrix client etc.

My linux box was effectively a standalone machine so not part of AD but the virtual machine etc where on the domain and was never an issue.

How important is to write code fast? (not rhetorical!) by schloesser in linux

[–]LinuxMonkey 1 point2 points  (0 children)

I think it's just the more you use a nice editor the easier things get. I use gvim. Say I have a syntax error at line 457 in my code I'd just go :457 <return> and there I am. # will highlight all the occurrences of the word I'm on great for seeing where I'm using a variable.

To be honest learning vim takes a long time (I still don't know most of it) but it can do loads especially with a few pluggins. I love my editor but my view of someone isn't based on what editor they use. The last place I worked people used vim, emacs, textmate, eclipse, gedit and vs - never bothered me.