PaulPerger
Posts: 1
Joined: Thu Mar 24, 2016 3:48 pm

Which Language should I learn?

Fri Apr 01, 2016 4:17 pm

I have a train in my office that I want to control via a program running on a Raspberry Pi.

What I really want is to have a display graphic of the train tracks and indicators showing where trains are on the tracks and then use the signals that are driving the graphic to also feed the program data from which it can make decisions on what to do. (Open a siding for example to allow a train to pass. Shutting a section of track down to avoid a collision, etc.)

I have no "real" programming experience, other than writing Basic in the mid 80s, and I do write Visual Basic code to automate processes in Excel and Word. So, I have a basic grasp of programming, but no experience in Python, C, C+, etc.

And my question is very simply, which language would be best to accomplish my goal as stated above?

User avatar
karrika
Posts: 1096
Joined: Mon Oct 19, 2015 6:21 am
Location: Finland

Re: Which Language should I learn?

Fri Apr 01, 2016 6:53 pm

I would probably look for some kind of 2D or 3D game engine that would have support for the kind of program you are planning to write. The language to use depends on what you choose. Most likely it will be Java, C++ or Python.

Perhaps minecraft could be tweaked to do this? Just a thought. It has the elements of building a world and controlling bricks by python.

User avatar
topguy
Posts: 6269
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Which Language should I learn?

Tue Apr 05, 2016 2:51 pm

Many here would recommend Python, not only is it a fairly powerful language which is easy to learn, but its also not complicated to run code. No need for compilers or linkers as for Java/C/C++, but you still need to learn how to install and use libraries (modules).

User avatar
CaptSunset
Posts: 140
Joined: Fri Mar 20, 2015 2:55 pm

Re: Which Language should I learn?

Tue Apr 05, 2016 3:22 pm

I have a similar if more generic question for coding folks who have 20/20 hindsight:

of the 3 'easy' scripting languages frequently used around here: Bash, Python, and Perl...
... which order should a novice learn them in, or should you try to learn them all at once?
Some days my brain hurts :shock:

User avatar
karrika
Posts: 1096
Joined: Mon Oct 19, 2015 6:21 am
Location: Finland

Re: Which Language should I learn?

Wed Apr 06, 2016 7:49 am

CaptSunset wrote:I have a similar if more generic question for coding folks who have 20/20 hindsight:

of the 3 'easy' scripting languages frequently used around here: Bash, Python, and Perl...
... which order should a novice learn them in, or should you try to learn them all at once?
Some days my brain hurts :shock:
The advantage of bash is that it works directly on the bash shell. The command line window. But the language itself is really weird.

Python is definitely the most powerful of these. By learning it well you can do anything.

Perl? I have never bothered to learn it properly so cannot really comment on this.

Go for Python. It is usable for programming complete applications with touch screens and everything. And you can also use it for scripting. Python has also excellent libraries for interacting with data from web pages and web services. Like fetching bus schedules, monitoring sports results, making front ends for internet radio or a jukebox. And of course making cool new games. I even found code for controlling OpenGL 3D meshes with Python on the Raspberry Pi!

Nightflyyer
Posts: 6
Joined: Wed Apr 06, 2016 1:30 pm

Re: Which Language should I learn?

Wed Apr 06, 2016 2:14 pm

You should try python its super simple to use and most people use it when programming on the RPi GPIO.

User avatar
CaptSunset
Posts: 140
Joined: Fri Mar 20, 2015 2:55 pm

Re: Which Language should I learn?

Wed Apr 06, 2016 3:10 pm

Kiitos, Karrika!

I'll take your advice, been browsing for Python tuts and manuals; just found this'n you might like;
The Hitchhikers Guide to Python:
https://media.readthedocs.org/pdf/pytho ... -guide.pdf

First thing I want to program is a combo 2 key-press required for that @#!>~ Caps Lock key;
even trolls don't type in all caps anymore ;)

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: Which Language should I learn?

Wed Apr 06, 2016 3:41 pm

CaptSunset wrote:First thing I want to program is a combo 2 key-press required for that @#!>~ Caps Lock key;
even trolls don't type in all caps anymore ;)
I often don't even use the caps lock key when I'm typing in full caps, I just hold the left shift down with my pinky, even when typing on the left side of the keyboard. So they could do away with that key anyway.

User avatar
piglet
Posts: 913
Joined: Sat Aug 27, 2011 1:16 pm

Re: Which Language should I learn?

Wed Apr 06, 2016 3:46 pm

karrika wrote:Perl? I have never bothered to learn it properly so cannot really comment on this.
If you're wanting to crunch data in files, Perl tends to be very fast to write and runs far far faster than Python. I wouldn't want to try and do 2D / 3D graphics with it. It's not for that sort of thing. Horses for courses.

User avatar
Bottersnike
Posts: 52
Joined: Wed Apr 06, 2016 7:17 am
Contact: Website

Re: Which Language should I learn?

Thu Apr 07, 2016 6:21 am

PaulPerger wrote:I have a train in my office that I want to control via a program running on a Raspberry Pi.

What I really want is to have a display graphic of the train tracks and indicators showing where trains are on the tracks and then use the signals that are driving the graphic to also feed the program data from which it can make decisions on what to do. (Open a siding for example to allow a train to pass. Shutting a section of track down to avoid a collision, etc.)

I have no "real" programming experience, other than writing Basic in the mid 80s, and I do write Visual Basic code to automate processes in Excel and Word. So, I have a basic grasp of programming, but no experience in Python, C, C+, etc.

And my question is very simply, which language would be best to accomplish my goal as stated above?
If the trains are DCC then python is the way tp go because of the awesome DCCPi package. I myself wrote a little python script that can control up to 10 trains at once. (if you are using python then probably use pygame for the display as it comes with the pi and when used correctly can be really powerful)
Micro:Pi is an (almost) fully fledged IDE for programming a BBC Micro:Bit using C++. Go check it out at https://bottersnike.github.io/Micro-Pi

User avatar
karrika
Posts: 1096
Joined: Mon Oct 19, 2015 6:21 am
Location: Finland

Re: Which Language should I learn?

Thu Apr 07, 2016 8:05 am

CaptSunset wrote:Kiitos, Karrika!

I'll take your advice, been browsing for Python tuts and manuals; just found this'n you might like;
The Hitchhikers Guide to Python:
https://media.readthedocs.org/pdf/pytho ... -guide.pdf
Ole hyvä CaptSunset,

I was kind of expecting to find the cover with DON'T PANIC on it...
Image

KevinHartmann
Posts: 4
Joined: Wed Apr 06, 2016 5:49 pm

Re: Which Language should I learn?

Thu Apr 07, 2016 6:24 pm

I've spent 8 years as a full-time Perl programmer; and I've been writing code in Python for around five years now... and I'd say Python, hands down.

Choosing a programming language is always a bit subjective; great programmers can write good code in just about any language; and bad programmers can write bad code in any language. It's really a question of how easy or difficult things are to do; which usually depends upon what you're doing. So, in many cases, it comes down to personal experience and personal preference.

As an younger programmer, I felt that the two languages were roughly equivalent; as an older programmer, I consider Python simpler, easier, and more concise.

Perl has the motto: "there's more than one way to do it"; Python tries to find one good way, and get everyone to do things that way. Part of my frustration with working with Perl was constantly wondering why someone wrote something the way they did; were they missing something very obvious, or was I missing something very subtle, or was there a bit of both?

By contrast, Python code usually does exactly what it looks like it does; with fewer choices to make about how to do things, people end up doing things more or less in the same way, which makes code easier to share and understand.

Perl tries hard to guess what you intended to write, and do that for you. Python keeps the rules simple and concise. In Python, if you don't get things right, nothing works at all. In Perl, you often get something related to but not quite what you really wanted; and you might not even recognize it as a bug until months later.

On my first day at a new job, I made one simple program run ten times faster: by changing the word "for" to "while". The two loops were both processed the file one line at a time; the first one loaded the entire file into memory as a side effect of being "evaluated in list context".

Python's grammar can be defined on a single sheet of paper; Perl's grammar had so many odds and ends and special cases that the code to parse it included a section that is actually called a "Guesser" by the people who wrote it. It may still; I haven't worked with it in years.

It was so bad that even the people who wrote it used to joke that "Perl (the Perl programming language, spelled with a capital 'P') is what perl (the UNIX version of the perl program, spelled with a *lowercase* 'p') does": in other words, no one could predict exactly what would happen when you ran something.

In one case, I ran into a situation where, when trying to check the syntax of a Perl program, I ended up trying to connect to a production database instead. When I asked the experts how to prevent doing that in the future, they pointed out that there wasn't one: import statements are always run, and according to the definition of the language, must always be run, because the imported module might want to change the meaning of Perl itself.

That's around when I switched to Python. :-)

Python has functions with named arguments, generators, exceptions, context handlers,
classes, with modules and exception handlers built into the language. I have never seen a program in Python written in the shape of a snake, nor one in the shape of any of the cast or crew from Monty Python. I consider these good things.

Perl has a dozens of special variables, needless semi-colons and braces, awkward syntax, "list versus scalar context", sigils, "magic", die/eval, BEGIN, END, CHECK, and CODE blocks, "packages"
and "typeglobs". I have seen Perl code written to make the shape of a camel. There exist "obfuscated Perl contests" to tax the minds of Perl experts. I've never heard of an "obfuscated Python program"; and I hope I never do. :-)

Return to “General programming discussion”