2017-05-31

PyCharm Tip of the Day 2

This is a continuation of the last post, PyCharm Tip of the Day 1, in which I decided to go through all the Tip of the Day:s that pops up when I start PyCharm.

  • Ctrl+E (View | Recent Files) pops up a list of recently visited files. 
  • In menu (File | Settings (Ctrl+Alt+S) | Editor | General | Appearance), checking the box "Show method separators" will show separator lines between methods in the editor. (Let's try it)
  • Code Completion, Ctrl+Space, also completes indentifiers from letters inside the identifier, for example if you type "ell", the word "hello" might be suggested.
  • Alt+Up/Down will quickly move you between methods in the editor.
  • Press Ctrl+Shift+V to choose and insert recent clipboard contents.
  • Quick Documentation (Ctrl+Q), Parameter Info (Ctrl+P) and Declaration (Ctrl+B) also works in the code completion lookup list.
  • Override a method of the base class by pressing Ctrl+O (Code | Override Methods).
  • Information and description is displayed in the bottom bar on the PyCharm frame when items are hovered upon.
  • Any particular method of field is opened by pressing Ctrl+Alt+Shift+N (Navigate | Symbol).
  • Press Alt+Shift+C to review recent changes.
  • Quickly switch coloring theme by pressing Ctrl+Back Quote. The back quote button is the § button above Tab and next to 1. Doesn't seem to work on my Swedish keyboard though.
  • Select text in columns by holding Alt while selecting a block of text.
  • Set colors to different type of files in the menu (File | Settings | Appearance & Behaviour | File Colors). I'm setting my Problems to Rose.
  • Search through the menus by pressing Ctrl+Shift+A.
  • Run an inspection (*) by pressing Ctrl+Alt+Shift+I.
  • Pressing Alt+Shift+F9/F10 opens the Debug/Run dropdown menu.
  • Want to view an image inserted as code? Select the image name and press Ctrl+Shift+I.
  • PyCharm has a built-in spellchecker. Select a highlighted (misspelled) word and press Alt+Enter to pop up a list of available actions.
  • Add your own words to the spellchecker dictionary by pointing to a text file that you name with .dic format with each word starting on a new line. Do the pointing in the (File | Settings | Editor | Spelling) menu.
  • Search for patterins in a word by using *. For example searching for "*elo" might get you the suggestion "hello".
  • Comment and uncomment code with Ctrl+Slash.
About Code Inspection and Analysis.

Ok, it seems that there's almost infinite of tips and I'm getting way too curious about this to keep reading the "manual". This is the last post with Tip of the Day for now, maybe it'll come back sometime in the future, who knows.

/Ludvig

2017-05-30

PyCharm Tip of the Day 1

Today I'm starting off with going through the Tip of the Day that pops up when PyCharm is started. I'm going to go through them and do a, hopefully, short summarization.

  • Menu bar -> Help -> Tip of the Day pops up the window if you need it again
  • You can work with multiple projects in one window. To do this just open another project folder in the Open File or Project window. Click OK. A new dialog box will show up in which you select "Open in current window" and "Add to currently opened projects".
  • To open any class inside the editor, press Ctrl+N (Nagivate | Class) and start typing the name of the class, you'll get options in a drop down menu.
  • Use the Code Completion feature by start typing for example the name of a class, select the intended class in the lookup list and press Ctrl+Space to complete the name.
  • Pressing Ctrl+Space twice completes the name of any class no matter if it is imported in the current file or not.
  • Find Usage is a feature which allows the programmer to find where any class, method or variable is used in a project. Press Alt+F7 to use Find Usage on marked code. To highlight usages of a variable in the current file, press Ctrl+Shift+F7.
  • Navigate through highlighted usages with F3 and Shift+F3. Remove highlighting with Escape.
  • Need to know about a code symbol? Mark it and press Ctrl+Q to pop up the Quick Documentation.
  • Navigate to the declaration of a class, method or variable by marking code inside it and press Ctrl+B. The same feature is invoked by Ctrl+Mouse Clicking code.
  • Navigate in the currently edited file with Ctrl+F12 (Navigate | File Structure). Select an element and press Enter or F4 to jump to it.
  • Ever felt that you want to replace a word in a file? The feature is invoked by pressing Ctrl+F6 (Refactor | Rename) and it will replace the currently marked code. Inside the new word in the popup window.
  • When using Code Completion, accepting the currently highlighted selection with Tab will, unlike using Enter for selection, overwrite the rest of the name. Use this is you don't agree with the Code Completion suggestion.
  • To close a tab in the editor you can either Shift+Click the tab, or click on it with the scroll button
  • Press Alt+F1 to quickly select the currently edited class, file, method or field in any view.
  • There's a speed search feature in which you just start typing and it'll start searching no matter what view you work with.
  • Press Escape in a tool window to move focus to the editor.
  • Press Shift+Escape to move focus to the editor and hide the current or last active tool window.
  • F12 moves focus from the editor to the last focused tool window.
  • Ctrl+W invokes a feature called extended selection. Select a word in your code and press Ctrl+W times to select for example methods that calls the selected code. Press Ctrl+W to extend the selection even further.
  • Select a complex part of your code and press Ctrl+Alt+V (Refactor | Extract | Variable). It will invoke the Extract Variable feature which help you to simplify your code. Instead of typing multiple extensive expressions as an argument in a function, this feature will create shorter variables for the expressions to make the arguments easier to read.
  • Press Ctrl+D to duplicate the currently selected block of text or the current line the marker is on.
  • Move code up or down by selecting to and pressing Ctrl+Shift+Up/Down. If nothing is selected, the current selected line will be moved.
  • Merge two lines and remove unnecessary spaces by pressing Ctrl+Shift+J.
  • When cursor is between two parentheses when calling a method, press Ctrl+P to pop up a list of valid selections.
  • Want to continue from where you last edited? Press Ctrl+Shift+Backspace (Navigate | Last Edit Location). This can be done multiple times to browse change history.
  • Change history of your file is found in the menu (VCS | Local History | Show History). This feature will never delete any code.
No code this time, and next time I'll continue with the Tip of the Day. I think I got half way through the tips this time. Reading these tips gives me a kick start into the programs features unlike anything I've had before. The throw-the-manual-in-the-bin-and-then-try-everything is fun, but I think this is more effective.

/Ludvig

2017-05-29

PyCharm vs PyDev in Eclipse

So what does Internet say about this? I've googled "pycharm vs pydev" and read a few of the most relevant hits. So just to recap, in my last post I concluded that I'm looking at either PyCharm Community or Eclipse with PyDev. Eclipse is a platform on which addons can be installed for different purposes. For Python development, it seems to be the PyDev addon that's what's needed to develop Python programs in Eclipse.
What is remote debugging? According to Wikipedia, remote debugging can be explained as follows:

"Remote debugging is the process of debugging a program running on a system different from the debugger. To start remote debugging, a debugger connects to a remote system over a network. The debugger can then control the execution of the program on the remote system and retrieve information about its state."

and which is something that I don't need at the moment. So to conclude it all, I believe that Internet thinks that I should go for PyCharm, so here we go!

Let's start off with hitting the PyCharm Community Download button.

 The automatically selected, I guess latest stable, version of PyCharm Community is 2017.1.3 and the setup file is approximately 147 MB large. A few moments later I'm executing the downloaded setup file.  Required space is 412.7 MB. Seems like it's time to upgrade my hardware.


Ok, so there are separate launchers for 32-bit and 64-bit systems, and as I'm allergic to having stuff on my desktop I'll keep those two boxes unchecked. I also skip the file association to .py, I don't really know why, but it's easy to fix afterwards if it becomes annoying. What is "JRE x86 by JetBrains"? I'm running Windows 7 64-bit, so x86 doesn't sound applicable to me, but let's check it out. JRE stands for "Java Runtime Environment" and is needed to run java applications on your computer.


Nothing special here...


Nothing special here...


Finish and run!


I have no settings to import.


And I guess I have no choice but accepting the privacy policy.


First settings to make. The keymap scheme determines shortkeys for different commands etc. It's all reconfigurable inside the program later on. The IDE theme determines the visual theme of the program. Let's try IntelliJ.


Clicking the "Click to preview" unfolds a small windows with a code example. Changing the Editor colors and fonts changes the code example.


I'm going with Warmneon.


After click OK on the short configuration wizard this is what comes up. Hit the Create New Project button.


 No Python interpreter selected? -> Google -> Stack overflow -> I haven't installed Python! I shut down PyCharm for now.


Let's download and install Python then. Which one to go for? -> Google -> Python wiki -> "Short version: Python 2.x is legacy, Python 3.x is the present and future of the language" -> I'm going for Python 3.6.1. Clicking the left button take's me to a new page


on which I scroll down to Files and select the appropriate file for me, "Windows x86-64 executable installer".


29.9MB later I run the executable and then click Customize installation button just to see what's in the installation.

 Nothing weird really, maybe I could do without the Documentation since I've got Internet close at hand, but hey, maybe it's useful for once. Next...


I deselect the Create shortcuts box. Next...


Install... Great success!


Checking in Programs and Features (Windows), Python 3.6.1 (64-bit) takes 90.5MB and Python Launcher 1.73MB.

Now try again with PyCharm and see if there's any difference. The red text is gone! I'm selecting another location for my project. Create!

 

 Tip of the Day. For the first time ever I'm going to go through this kind of thing and see what happens.


That's all for this post folks. Next post will be about getting started with the coding and maybe running a "Hello world" program.

/Ludvig

2017-05-28

Where to do the coding (IDE)?

First of all I need to find an IDE (integrated development environment) to write my code in. I run Windows 7 64-bit and wish to continue to do so.

With my rather little experience in programming, I've got even less experience in choosing IDE. The C# I've previously coded was written in Visual Studio and the C code was written in Atmel Studio 7 (I think?). Oh right, I've done some Arduino programming aswell, and that code has been written in Arduino's own IDE called Arduino.

Now let's go find a suitable IDE. I start out with the making of a requirements list based on my current knowledge of what there is to get.
  • Free
  • Runs on my OS
  • Debugger
  • Compilator
  • Code completion
  • Bracket completion
  • Dark color theme
I start off by reading a "10 best python IDE:s" blog post to get a grasp of what's out there. That post got me interested in following IDE:s:
  • PyCharm
  • PyDev on Eclipse
  • Wing Personal
  • Komodo Edit
  • PTVS
After checking out the features for those five candidates, I made a new requirements list:
  • Free
  • Runs on my OS
  • Debugger with break points
  • Dark color theme option
  • Syntax highlighting
  • Auto code formatting and intendation
  • Auto code folding (braces, brackets, quotes)
  • Code analysis
 and with Excel as my very good friend, I then conclude following:


. It seems as though most IDEs have the same features, and it's possible that Komodo Edit has the features that are missing in my matrix, but the other candidates are atleast as good it seems, so I feel no need to do a deeper research about it.

PTVS, Python Tool for Visual Studio sounds really interesting since it runs in an environment that I'm familiar with. What makes me wonder though is why there's only one person on Quora who mentions it on the question "What is the best IDE for Python?". Maybe most Python programmers run other OS:es than Windows and that's why? Anyway, I added the row "Answers on Quora" as a tiebreaker and what it presents is the number of answers to the above mentioned question that mentions different IDEs. This Stack Overflow post is also interesting to look at.

This is it for now and next step is to do a deeper research on PyCharm and PyDev.

Intro

This blog is intended to be a log over my adventure into the world the programming language Python. Due to my lack of motivation when there's no aim for what I'm doing, I've decided to make this journey public and hope that it'll be a good enough motivator for me to continue learning. I've got one semester of C#, and a few weeks of C, programming on university level.

/Ludvig