Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Write Clean, Professional, Maintainable, Quality Code in Python (jetbrains.com)
55 points by rdemmer on June 13, 2014 | hide | past | favorite | 54 comments


An IDE will never help you develop "Clean, Professional, Maintainable, [and] Quality" code if you're not interested in writing it in the first place. And if you're interested in writing good code in the first place, an IDE is hardly a requirement.

Frankly, as a developer who has tried a number of IDE's and text editors, I'm not sold on the idea that your choice of editing environment has any correlation to any of those titular descriptors in the first place.


However, I think great IDE will help OTHER people to maintenance and refactor code to clean, professional, and maintainable one.

I always use IDE to refactor code, as other developers might not writing clean code, even myself.


"Senior Code Janitor" would be a fun title to hold.


[deleted]


Certainly in eclipse it's possible to specify formatting rules. You can also use the checkstyle plugin to enforce correct formatting.


Almost all good IDEs allow that. All IntelliJ ones do that. They can even share the code formatting rules and they can be committed to version control so that your whole team uses the same rules.


Actually this is quite easily possible. They have lots of settings for it. But in python, for the love of God, PEP8. This standard is built in to pycharm.

But there's no substitute for an autopep8 [1] commit script. (Preferably make it a check, not a direct reformat)

[1] https://pypi.python.org/pypi/autopep8


I was thinking exactly the same thing reading the headline.

Good design will give you a lot cleaner professional maintainable code.

I do databases, but I like Linus's quite about getting the data structures right, and not needing to worry about the code. I find if the application level is getting too complex, it probably means the database design isn't matching the problem correctly. Others on my team would keep adding "if" statements to the forming ball of mud. (Usually) I find it easier to take the pain of a schema migration up front. The code then becomes simpler, more reliable, and I can usually forget about it.

As for the text editor comment. In general no, but I know a lot of poor programmers who are too lazy to set up / learn an IDE (or any other way of using a step through debugger).


Nor will python. Python is dynamically typed. It may not be impossible to write big functioning python apps, but it's damn hard.

And specifically, it's a lot harder than doing it in java or C++. I've seen C++ codebases that exceed 8 million lines of code and held together (not without friction, that I guarantee). I've seen java codebases with about half that that held together a lot better than the C++ ones.

Even accounting for the fact that python easily lets you achieve 5 times as much in the same amount of lines (at the cost, imho, of more surprises when wrong types get passed to your functions). I'm not sure "normal python" is more than a little bit more succint than (good) C++ though. Easier to read, sure, if you're allowed to make assumptions about types. But not that much shorter.

I've yet to see the first million line python codebase. And python has certainly had sufficient time to develop such codebases. Why aren't they here already ? Those C++ codebases were almost operating systems though (with extremely tricky threading support libraries, every project it's own of course), something you fundamentally can't do in python. The java codebases were financial stuff though, something that could easily be done in python, and they certainly have the money to absorb the increased hardware cost, and looking to have faster development turnaround. That's another discussion I can guarantee you will have with your boss if your app really grows, the hardware cost. When it comes right down to it, a programmer is worth (rule of thumb) about 15 servers. If python means one less programmer, but 50 extra servers, you will lose that discussion with your boss.

Dynamic typing is certainly a massive advantage for small codebases. It becomes more and more of a disaster on larger ones though. So an IDE for python ... it merely lets you lose the battle with your code that much faster.


Do you include all libraries when you measure the size of a codebase?

One of the main benefits of using Python for me, is that there is usually a (decent quality) library written. If you are having to re-implement everything from scratch and are not including the libraries.

The last thing close to a million lines of code I worked on was horrendous. Legacy banking app in VB6 (after MS had stopped support). I would write a method to do something, then a month later I would find another method somewhere else in the code doing the same thing . At the time I had a lot of Perl experience and could see looking at it the code size could be halved using a more powerful language, and in my opinion, that would have reduced the chance of repeating code (though to be fair the management practices were a far bigger offender).


Well, yes, I agree. I don't know what the largest python code bases are, but I would not expect them to get to the size of some of the really big systems written in strongly-typed system-level programming languages like C or C++. However, I would also suggest that the need for huge code bases like that is diminishing. Much of what we build now consists of smaller bodies of code, sitting at the end of a service pipeline, or collaborating in a distributed system. Python works very well in scenarios such as implementing API endpoints which are really glue between layers anyway. And it's certainly been shown that significant applications can be written in it. But if you're facing something that is Department of Defense-sized, maybe it's not the right choice.


I have personally worked on a 7 man team on a 2.5m LOC codebase in Python (Python 2.4, to be precise). It wasn't public, though.

Working on the code base with dynamic typing wasn't _that_ hard. Certainly not as hard as people make it out to be.


I'd be interested in hearing more about this codebase. What was it's function ? Are you including libraries ? What is taking up so many lines of python ?


Python is currently making inroads in finance, both Bank of America and JP Morgan have large projects involving it. I've worked on one of them, and like you I'm unusure if it's a good long-term plan, though I don't have experience with large codebases in other languages. Performance is an issue and navigating a large Python codebase is tricky. One thing that doesn't help is that many of the developers come from Java/C#/C++ and pick up Python quickly but with "unpythonic" habits, the code ends up being almost as verbose as Java but with none of the type safety.


Detailed review of PyCharm - Review of PyCharm 3 from a Vim User’s Perspective http://andrewbrookins.com/tech/one-year-later-an-epic-review...


I have been using PyCharm for few months after using Sublime Text 2 for years. It is very well engineered tool and has greatly improved my code quality.

Just came to know 'Python code compatibility checks' option. Will definitely be helpful as I am starting to write Python 2/3 compatible code.


I too am a convert from ST to PyCharm and PHPStorm. Although, I'm still using ST for editing javascript. I need to break that habit.


WebStorm is a solid javascript IDE, I recommend giving the trial a shot.


PHPStorm is essentially a superset of WebStorm.


PyCharm is a superset of WebStorm as well


Yes, PyCharm is miles ahead of other IDEs or text editors, love it.

I wish they had another big sale so i could afford the latest pycharm again.. :(


Me too!


You know about the free community edition, right?


Or you could throw them a few dollars to maintain a product you like.


Unfortunately the community edition can't do a lot of nice stuff i care about like remote debug/run, remote interpreters, vagrant integration and some other nice things that make the difference between ST3 and pycharm for me. Without those i can stick with ST3 and python plugins.


PyCharm was the reason I started coding in Python. I know it sounds weird, but I was a visual studio addict & going to sublime text or a plain text editor just didn't compare.

I wish they had a "startup" package so even boots trappers can get started right.


They actually do. It says "50% OFF for startups" on the pricing page: http://www.jetbrains.com/pycharm/buy/

More details here: https://www.jetbrains.com/estore/startup/


Sweet! Thank you! If you're ever in Melbourne, FL, you can swing by & partake in he extra pizza you just helped us buy!


> I wish they had a "startup" package so even boots trappers can get started right.

You could also stay at your day job for a day or two longer and save up for the $99 personal edition.


We have 8 people. That's $800 for license. Which by no means is crazy, but using atlassian products we're a little spoiled. You are right though. It would be very short sighted to say that's not worth the money.

Wishful thinking: We'd be willing to pay a higher price in the future since that would mean more pizza money for us now

In another startup that I was a part of, we were more than happy to pay the significantly higher price for Atlassian products once we grew past the 10 people limit.


Well, there's the 'Community Edition'. Unless you're heavily into WebDev, it's great.


My concern about PyCharm is that it's becoming the Microsoft Office of IDEs. I feel like there's more and more bullet points per release that are more marketing-oriented than widely useful. While my needs remain simple. Maybe everyone needs only 2% of the feature set, and a different 2%, but we all have to pay for the bloat anyway.

I keep repeating a cycle where I try an IDE because it sounds interesting, but a few weeks later I find I'm spending a lot of time doing things like arranging tool windows, dismissing alerts, trying to figure out how to turn off or customize features. So I always go back to a simpler text editor that I've been using for 15+ years and does everything I need very well without the sluggishness of a feature-rich IDE.

For example, every time I open a PyCharm project I get an alert I need to dismiss that managing files will be slow because they're on a network drive. Technically it's a network drive but it's really mounted from a VM on my local machine, so no, it's not slow, and if it was I wouldn't need Clippy telling me so. There may or may not be a way to turn off this alert, but I shouldn't have to hunt for these things so often. I want to use PyCharm but keep getting annoyed with it.


If your text editor works better than PyCharm, then by all means use that instead. However, the article is actually trying to make some point about what an IDE can do that text editors can't so perhaps you'd want to respond to that?

> Maybe everyone needs only 2% of the feature set, and a different 2%, but we all have to pay for the bloat anyway.

This is not a useful mental model for thinking about software. First, big doesn't equal bloated, and one thing my IntelliJ IDEA fanboy colleagues highlight is just how sleek, light weight and fast it is, especially compared with Eclipse (we're in Java land). Second, if everybody only uses 2% of the package, then basic price theory tells us that everybody is only paying for those 2%. (I think, in reality, the number is significantly higher, although I agree that probably nobody uses 100% of the features).


I think the OP has a point. I bought WebStorm (the javascript equivalent of PyCharm) last year and loved it. A couple of updates ago, it started exhibiting a strange behavior where the editor will hang for a few seconds while it loads up the intellisense which is annoying since I don't use intellisense all that much.

Jetbrains' products are not immune from bloat.


The everyone-uses-a-different-2% is a point that's frequently made about Microsoft Word, and it's not so much literal as a way of explaining why a product like that gets the way it does. If something is bloated, you can't just start removing obscure features because they're not obscure to everyone.

So an IDE, also, can get into that state. Which is maybe why I can never find an IDE I like to use. I could only see calling PyCharm "sleek" if that was in comparison to something like Eclipse. It's a better choice than that, but still not the experience that it could be, or that I'm looking for.


I've been trying PyCharm for a few days. It doesn't do anything that emacs can't do (maybe refactoring, but that's on the list ahead), but it's easier to setup. If it's really a memory hog like people are saying, I didn't notice, and didn't look, and didn't care, my computer has enough memory.

Maybe it gets better with practice, so I'll keep trying a bit more, but currently, count me as unimpressed:

1 - About code inspection. Well, I fully understand that inspecting Python code is hard, and any tool will have either false positives, or false negatives. But PyCharm gets false positives to the extreme, it complains about not resolving Python standard functions (like open), and it can't find some libraries at my virtualenv. It's so full of false positives that I'm not sure I'll be able to keep reading them - I normaly can't stand code with warnings, but in PyCharm there is no other way.

2 - About formating. It fully enforces PEP8, the most completely enforcement I've seen on any tool (no I didn't try the emacs el for that). That's a good thing if there is an option to turn it off, what I don't know, because I didn't search for it yet.

3 - About refactoring. No, PyCharm, I don't want Django to change because I changed a function name in my code. Maybe there is a way to tell it not to touch some dirs, but the default settings makes PyCharm much less reliable and slower than grepping the old name and replacing it by hand. I'll try to find such setting when I get out of work today, but it's making the case of PyCharm being easier to setup way less appealing.


FWIW, if you're a developer who uses IntelliJ's flagship IDEA Ultimate IDE, you can get the Python plugin and get nearly all the functionality of PyCharm. Same goes for most of their other products (WebStorm, PHPStorm, etc.). Fabulous products for those of an IDE-inclination.


My biggest problem with the JetBrains IDE is that it scatters file turds through your project; making it a pain for developers to use source control without generating random conflicts. An IDE's files have no reason to be version controlled in every project (nor should a project require every developer to use the same IDE).

If they had a sane way to keep IDE files in a single top level project directory, I would be much happier.


I've certainly seen the IDE turd files you mentioned, but I'm pretty sure they all live in .idea. Github has a nice .gitignore build for these (and other common ignores):

https://github.com/github/gitignore/blob/master/Global/JetBr...


I find that this typically isn't a problem when you instruct git to ignore those files.

Brilliant way of describing the IDE metadata files, BTW. I got a nice chuckle from that.


All of the IDE files are in fact in the .idea folder.

gitignore .idea/ and you should have no trouble. What other type of files are you finding scattered in the project?


I have no idea what you are talking about. PyCharm stores every setting in a directory called ".idea"


How do people find PyCharm these days? My brother uses it daily but finds it to be a major memory hog (1G+ of RAM on startup)


The compelling use case for me was that I was already used to the Intellij key bindings, which tend to (mostly) remain constant across JetBrains products. It does use a fair amount of RAM, but these days 8GB seems fairly standard and seems to be plenty most of the time. I currently have PyCharm open and it's using 427MB.


It's getting better with each release. First startup consumes a lot of memory, because PyCharm does a lot of indexing


The linked article is really nothing more than an advertisement for PyCharm. Is it acceptable now for companies to just post links to advertisements for their products on Hacker News?

I'm a fan of JetBrains and I own PyCharm and WebStorm, but I don't want this to become a trend...


Now if only they would do a Go-lang IDE with the "extract method" refactoring.

I do mostly Java, and wow I never realized how much I'd miss that until it was gone!


vim+python-mode is more than enough for my needs.


Same here. It seems like a really solid IDE, but I like a more lightweight development environment, and there's always that one vim command that vim emulator plugins miss. However, I've recommended PyCharm to several of my coworkers who use IntelliJ for Java development, and they love it.


If this advertisement convinced you to try a Python IDE, consider giving PyDev/LiClipse a try. It's free and open.


I have been a long time Eclipse / Aptana user. I gave the community edition for Pycharm a try, but it lacked a number of features. Plus I have used Eclipse for long enough that I have a fair idea what to when it screws itself up.


In PyCharm can you set the indentation size (# of spaces per tab) per file type?

I would like 2 spaces for JavaScript and HTML but 4 for Python.


Yes, you can. They can be set from: File->Settings->[Project Settings] Code style. You'll then be able to set the indentation level for each filetype separately.


Thanks, I always use the Help -> Find Action to get to settings. I never thought to look under File.


Yes

Or, it's certainly possible to have custom formatting rules in IntelliJ and AppCode and I assume that PyCharm is the same.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: