Viewing Python in IDE

Someone is trying to talk me into switching from PHP to Python.

This may sound funny, but one of the things that concerns me is how the formatting works in Python.

Everyone seems to think Python is much easier to read, due to things like eliminating curly braces { }.

This point worries me!

When I am working in NetBeans on my tiny MacBook monitor, and I have 300 lines of code nested inside an IF-THEN-ELSE, I want my curly brackets to see how things are grouped, damn it!! :mad:

Can anyone here explain how the visual formatting/hints would occur in NetBeans (or a similar IDE) in such a scenario??

Sincerely,

Debbie

Simple, take your block of code, create a python file, paste it, remove the curly braces :slight_smile:

Remember python uses whitespace to determine which block the code is associated with.

First of all, I don’t use Python, so telling me to create file is pointless.

Secondly, I think you missed the entire point of my OP…

It is a VERY IMPORTANT feature to me that my IDE helps me see where a block of code begins and end.

If have a IF-THEN-ELSE, where the THEN portion is 3 pages long, then I can’t see it all on one MacBook screen, and it helps IMMENSELY to click on the curly brace and have the IDE help me figure out how far down to scroll to find the ELSE portion.

(It’s also nice to have code collapsing/expanding too.)

See example below…

I was hoping someone here codes in Python uses NetBeans - or something very similar - and can tell me how the IDE would know where the end of a block of code is like in the screen-shot above.

Sincerely,

Debbie

Well python forces proper indention, it’s actually part of the syntax. So blocks of code will look the same in the IDE, just without the brackets.

Just a random picture I found of some python code in Netbeans. You can see on the left it has the option to collapse it, so it knows where the code block starts and ends.

Also, if you have such large pieces of code you should consider moving them into functions, classes, or new files. This helps readability. Personally if I start hitting 10 or so lines in an IF statement, I start thinking of ways to make easier to read. Sometimes it’s unavoidable, but most of the time it’s not. This goes for any language I use.

That section on the left the folding indicators combined with the blue grouping lines would also exist in your python code. There would be no yellow highlighting of the curly braces, because they don’t exist in python.

My point was, you have the tool at your disposal. You simply could create a myfile.py file, paste your block and see the formatting. :slight_smile:

Screenshots at http://wiki.netbeans.org/Python (granted, they don’t indicate folding options at the if statements, but I thought certainly that was available – so maybe the screenshots are a prior version)

How does it do that?

(That is somewhat scary if Python of my IDE start telling me how to format things?! Um, my code is about as “pretty” as they come!!) :rolleyes:

Well that sort of helps, but I wish I had a better idea how it would handle a really long If-Then-Else.

Well, maybe if I start learning OOP and learn how to break down my code, I can achieve smaller blocks of code, and this thread will become not applicable!

However, even if I learn and master things like OOP and MVC, any serious system will have blocks of really long and complicated code…

Sincerely,

Debbie

Well, if you have some structure like an IF-THEN-ELSE or a LOOP, how would NetBeans and Python help you figure out where the beginning and end are at?

Sorry, that went over my head.

I thought to use Python I’d have to install software and do a whole bunch of complicated stuff… :blush:

Sincerely,

Debbie

Spacing. You have to indent that code 4 spaces from the indentation of the if statement.

def mymethodname
    if blah blah blah:
       if code goes here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
    else:
       else code goes here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here
       and here

To execute it, yes, but just to see how it is formatted, no. Netbeans should have that built in.

Yeah, I agree it’s weird. But it doesn’t seem that bad. I’m actually still learning Python myself so I’m no authority on writing it, I’m just kinda using it here and there to get familiarized. cpradio seems to be much more familiar with it.

But if you’d like to learn it I do suggest the codeacademy course, it’s interactive. http://www.codecademy.com/tracks/python

Yes, Code Academy has an excellent course over Python, but if I recall correctly it is better to take the Ruby one first, as there are things that you go over in the Ruby one that will give you “ah ha” moments in the python one (especially the latter tutorials, that don’t guide you very much).

Ruby did a lot of hand holding, Python threw you in and said “learn to swim!”

I don’t do a lot of python, but I picked it up a few years ago when I needed to write plugins for kexi (an access database replacement for Linux).

Off Topic:

Why are they trying to do that? And why python?

Nothing personal, but it seems you don’t use an IDE?

I indent and space the hell out of my code now, but that isn’t what my original question was about.

Spacing and indenting don’t help you to easily see where the end of Do-While, of If-Then-Else, or whatever is.

Code highlighting and hinting do.

I don’t care if Python doesn’t use curly brackets, but I am hoping it - or NetBeans - would make it easy for me to see what is logically grouped together.

And as far as trying it out… Sure, I would do that, but since I don’t know Python code/syntax, it seems sort of hard to do.

Sincerely,

Debbie

Because PHP is considered amateurish when it comes to writing enterprise code and doing serious OOP.

And now that my website is nearly done - and looks very nice might I add! :slight_smile: - I am thinking of taking the next big leap, and getting into some hard-core programming.

A lot of people would say to go with C++ or Java, but I think there are some obvious pitfalls there.

And at least one person I respect pointed out that Python is older than Java, a good choice to get your feet wet in the OOP world, and is much, much easier to learn.

In my free time I am just checking things out and trying to come to a conclusion later this summer…

(I have always dreamed of being a Java Goddess, but considering how every time I try and learn Java and OOP I fail, maybe that is a sign I need to back off and try something easier.)

As far as the whole PHP-war I likely just started would go, HEY, if I didn’t like PHP, I wouldn’t have spent the lat 4 years writing my website in it.

And, yeah, I know that it was used to build FaceBook and WikiPedia and lots of other major sites.

But for those that want a strongly-typed language, and coding rigour, and a true object-oriented language, PHP will never be the choice!!!

PHP has been VERY good to me, but I think I am ready to step up to the next level, and maybe Python would be a good stepping-stone? :-/

Sincerely,

Debbie

Okay, now I’m starting to get a bit ticked off, as I feel you are not listening to what I’m stating or you just blatantly want a different question answered that was never asked…

I use several IDEs. From Visual Studio (for .NET work) to phpStorm and many in between. I write in PHP, .NET (C#, VB.NET specifically), Ruby, Python, and Bash frequently. I’m very familiar with IDEs and if you are too, then you’d know that if NetBeans supports Python (and it does) that it would have support for highlighting, syntax, folding of method declarations (and likely if blocks), code hinting, etc. (http://wiki.netbeans.org/Python#Features)

I feel like I’ve answered your question and if you really really want to know how netbeans handles python, TRY IT! Find a python script, open it in NetBeans and see how it looks and feels. Sickbeard is a well-known application written in python, feel free to download it and open one of its files within NetBeans.

I don’t know how much better I can explain it to you other than, NetBeans supports Python, supports its indentation syntax (because it has to), and therefore can and would give you a similar experience to what you have with PHP and NetBeans.

I’m not sure why you are even considering moving to a language you don’t understand/know. That is illogical. PHP’s declaration of being amateurish is unfounded at best and primarily based on the number of users that use PHP poorly. No offense, but I can find just as many users that use Python poorly, .NET related languages poorly, etc. Does that make them amateurish? No. It simply means there are crappy developers out there who don’t bother to learn best practices or bother to think about how they code something.

Personally, anyone who claims one language is superior over another loses a lot of respect from me as a developer. No one language is perfect for everything. Pick the language for the given job/requirements you have. Don’t try to fit the language into the job.

Nothing screams enterprise like Java. That doesn’t mean Java is the way to go though. Mostly I feel that enterprise is overrated. It’s usually so much wrapping and bloat going on you can’t see the forest for the trees.
Regarding PHP and OOP, it used to be quite bad in PHP 4, but in PHP 5, especially since 5.3, it’s quite good! There are a lot of reasons not to like PHP, but “not serious OOP” isn’t one of them.
Besides, you’ve said on more than one occasion that you’re allergic to OOP, so this argument should convince you least of all :wink:

Aw, you’re still in that phase where you think a website can be “done”. That’s cute :wink:

Yes, but C++ is older than Python, so …

That’s pretty obvious, since PHP isn’t strongly typed. And even python is, it’s also dynamically types, which has it’s own pitfalls.

Are you considering other languages as well? I’ve been playing with Google Go myself, and I have to say I really like it. It’s strongly and statically typed, and extremely fast!

Amen!

:rofl: Mine has been in the works since 2001 and even today, it isn’t finished :lol:

I wasn’t trying to tick anyone off. I just felt you missed my original question.

Since I have NetBeans for PHP installed, I can’t do your test.

Maybe later this summer I can install NetBeans for Python and find/write some code and give it a good test.

Because C, C++, Java, and Python are more serious, industrial-strength programming languages. PLUS, C++, Java, and Python support real object-oriented programming.

That’s why.

Would you learn sailing in a sailboat or a bathtub? (Unless you’re from Arkansas!) :wink:

PHP offer pseduo support for OOP. That is a fact, not opinion. I never said anything about PHP’s declarations…

Different topic.

All languages have crappy developers.

But C++ and Java are true OO languages. PHP isn’t.

That may not matter to the quality of the end app, but for someone who wants to learn proper OOP, it does matter!

Then you are too attached to certain languages.

I used to hear the same drivel out of people proclaiming that MS Access was a “true” RDMS, and that VBA was a “true” programming language… :rolleyes:

PHP is one of the best languages for the web, but it isn’t strictly typed language, and it’s support for true OOP is questionable.

Exactly.

So why are you implying that PHP is on the same level as C++ and Java when it comes to enterprise development and OOP?

I have.

I am trying to do that, and it may be Python…

So, cpradio… How do you REALLY feel?? :slight_smile:

Sincerely,

Debbie

I never said it was either. (Isn’t this a Python forum…) :wink:

Which is why so many modern developers like Ruby On Rails, Python, etc.

If you want to really learn OOP, why do it in PHP?

I think it is time for me to step out of my conform zone…

For v2.0

One of my final wishes before death is to conquer OOP.

I’m not allergic to it, I just know it is my eternal Achilles Heal.

v2.0 is almost done. Nothing “cute” or “dreamt” there.

Obviously my site will continue to evolve.

So nothing.

My point was Python is not some new, fad.

From my limited research, and one person I respect, I think Python is a stronger language when it comes to structure and OOP.

Yes, I am casually researching how to take my development skills to the next level.

When I learn OOP, I want to learn it with a language that really takes me to the next level. (I highly doubt PHP can do that.)

If I could conquer Python or Java or C++ or some other industrial-strength OO language, I think it would do worlds of good for me and my development skills.

I really like PHP, but I have always found it to be a sloppy language.

I want to get away from writing everything in one script that is my 500 or 1,000 or even 2,000 lines of code.

To accomplish this, I think I need 3 things:

1.) Learn MVC or something like it

2.) Learn OOA&D

3.) Program in a serious OO language and try to start writing code that you could get paid to do, that an entire development team could work with, and code that could be used by Google, Twitter, Amazon.com or Wall Street.

BTW, another reason for my “snobbiness”, is that I hope to write my own apps for the Apple Store, and that means needing to know Objective-C, and that means I need a hell of a lot more competency than writing HTML, CSS, and PHP all in one barf script!!!

Sincerely,

Debbie

C++ is not a good language to learn. It’s for low level systems programming and optimization, but even there it’s losing ground to other languages that are generally easier to write, like C or Java. Pure CGI programming has been dead for quite a few years. When you see on lists, [URL=“http://en.wikipedia.org/wiki/Programming_languages_used_in_most_popular_websites”]like wiki, where sites use C++ it’s mostly for the backend processes and not the web processes themselves. For instance, at my job the C++ runs some of the legacy CGI stuff built in the 90’s that unfortunately is still floating around in a few places and it also does the majority of the data crunching where it’s used to process terabytes of data. We’re actually moving most of these processes into pure Java so that they are easier to maintain, but it’s not high priority.

You might be referring to C#, which has been the core language used in ASP.Net programming for the last 5 or 6 years. It’s actually a really great language and the .Net web stack is very easy to learn, but it’s a Microsoft product. C# and Java are also very similar. C# was created as Microsoft’s answer to Java and was made to be similar. They have gone different ways over the years, but still syntactically very similar.

ASP.Net (C#) and Java are the reigning kings of Enterprise Web Development.

Sadly, the entry bar for Java web development is set pretty high. I don’t mean that to be pretentious or elitist, I mean it as a bad thing. It shouldn’t be so complicated, but it is and the resources for learning are sparse.

However if you’re really interested in it, the Play Framework makes it a lot easier. But, you should have a pretty good understanding of basic Java programming first. There are tons of resources for Intro to Java programming. Lots of highly rated ones on Udemy.com. If you want a framework that’s more enterprisey and used in more places, then Struts2 or Spring MVC is what you should be looking in to. They are way more complicated than they should be and can be difficult to learn for even seasoned Java developers.

If you want to learn MVC, there are plenty of MVC Frameworks for PHP. There is also a really great tutorial for how to build your own MVC in PHP. I’ve personally done the entire tutorial series and it’s one of the best tutorials I’ve ever come across in any language. It would have really helped me learn MVC initially if I had went through this first. (I learned MVC with ASP.Net)

11 videos and you should have a good understanding of core MVC concepts after about Video 6, though I do suggest doing all of them. This series will also give you a good feel for OOP in PHP, the framework you create is fully object oriented.

I am not a fan of PHP, but it does have it’s place. Since you’re already pretty familiar with PHP, I would suggest this be the route you explore before jumping into a new language. This way you won’t need to learn new programming paradigms on top of learning a new syntax and code structure.

Programming is programming. Syntax is syntax. Knowing how to program is the most important thing, concepts can be transferred between languages and syntaxes. Once you learn to program in a language it’s easier to pick up new ones. That’s why you see developers nonchalantly naming off 5 or 6 or 10 languages they know.

Well, 2 weeks ago that was true. Today and for all foreseeable days in the future, you should learn Swift. It was the major keynote at the Apple World Wide Developers Conference last week. They have pumped a lot of time and money into it being the replacement for Objective-C, which has been out since the 80’s. From what I understand is that it integrates seamlessly with Objective-C, so if you’re set on learning Objective-C then it’s not a waste. Swift is aimed at being easier to learn and use.