anders_w
Posts: 15
Joined: Sat Jul 19, 2014 7:27 am

Python, Java or both?

Wed Mar 14, 2018 9:27 am

I am beginning a project where an RPi will be running a big control panel with a lot of lights and switches. In a second phase, it will be interfaced against other HW and SW that runs java code.

I'm unsure as to what programming language to use, though. The panel interface will run through a number of I2C I/O cards from land-boards.com, routed through an I2C spliter from the same company.

The only code I have seen that does this is in Python, but for the panel to work properly, I think I need the concurrency of Java. I have done some Python programming before, but am really a novice at Java. Maybe I should use Python for the I/O and Java for the internal logic (where the concurrency is needed), but how does one interface the two?

Does the collective have informed opinions on what language to use?

Heater
Posts: 10312
Joined: Tue Jul 17, 2012 3:02 pm

Re: Python, Java or both?

Wed Mar 14, 2018 10:11 am

Warning. Language war alert!

I'm sure the "collective" will have as many different views on this as there are members. Or at least as many as there are programming languages.

Personally I'd say:

1) Pick one language and use it. It's frustrating, for me at least, to have to swap between languages while working on the same project. Both Python and Java can do what you want.

2) Neither. I'd do this in Javascript under node.js. When it comes to concurrency Python and Java are verbose and clunky. Javascript on the other hand, with it's event driven programming model makes this sort of thing a breeze.

anders_w
Posts: 15
Joined: Sat Jul 19, 2014 7:27 am

Re: Python, Java or both?

Wed Mar 14, 2018 10:59 am

Javascript, You say? Hm...

Is there any beginner's guide to it that You could recommend? Or one for node.js? Or both?

User avatar
jostle
Posts: 16
Joined: Tue Mar 06, 2018 6:26 am

Re: Python, Java or both?

Wed Mar 14, 2018 3:46 pm

Have a look at
https://www.w3schools.com/
for JavaScript and node.js tutorials
Have Fun ...

Lorqq
Posts: 1
Joined: Wed Apr 11, 2018 8:30 am

Re: Python, Java or both?

Wed Apr 11, 2018 8:34 am

Of course pick one language
Look here: https://www.codementor.io/javascript/tu ... t-properly

jahboater
Posts: 3311
Joined: Wed Feb 04, 2015 6:38 pm

Re: Python, Java or both?

Wed Apr 11, 2018 1:01 pm

What about: Java -> JNI -> C

Though I would code it all in plain C personally, easier (better support) and faster.

rin67630
Posts: 138
Joined: Fri Mar 04, 2016 10:15 am

Re: Python, Java or both?

Sat Apr 28, 2018 5:21 am

anders_w wrote:
Wed Mar 14, 2018 9:27 am
Maybe I should use Python for the I/O and Java for the internal logic (where the concurrency is needed), but how does one interface the two?
The best would have been to keep in one language. Else you could use named pipes / UDP ports to transfer the data between the programs.

ghans
Posts: 7819
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Python, Java or both?

Sat Apr 28, 2018 7:38 am

Python has the theading and multiprocessing module. Threading in Python is somewhat limited, that is why the multiprocessing module was introduced as work-around.

I too believe sticking to one language is essential.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

millers
Posts: 2
Joined: Fri Aug 17, 2018 10:27 am

Re: Python, Java or both?

Fri Aug 17, 2018 10:33 am

If you ask me - Python. :D

Heater
Posts: 10312
Joined: Tue Jul 17, 2012 3:02 pm

Re: Python, Java or both?

Fri Aug 17, 2018 11:12 am

Any particular reason for that choice? In light of our opening posters stated application.

hippy
Posts: 4031
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Python, Java or both?

Fri Aug 17, 2018 12:56 pm

jahboater wrote:
Wed Apr 11, 2018 1:01 pm
What about: Java -> JNI -> C
One could probably put a Python wrapper around that and call it from a Free Basic program :twisted:

I think choosing one language is best, which suggests Java given that's already being used. But it's not clear how tightly integrated this control panel project has to be with the Java side of things. If it's just a data connection rather than an API connection it would be perfectly acceptable in my books to treat them as independent and develop the control panel side of things in a different language.

User avatar
DougieLawson
Posts: 34177
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Python, Java or both?

Sat Aug 18, 2018 10:36 am

Heater wrote:
Wed Mar 14, 2018 10:11 am
Warning. Language war alert!

I'm sure the "collective" will have as many different views on this as there are members. Or at least as many as there are programming languages.
You weren't wrong. The language wars have started.

I'd say COBOL but the support on a Raspberry is a bit patchy (although you can get COBOL code to spit out Java JAR files with Elastic COBOL).

The obvious answer is "pick a language you know". The less obvious answer is "pick a language you want to learn" (which is why all the code I've written recently has been in C++).
Note:The use of baseball bats for educational purposes is completely disallowed on this forum.

Any DMs sent on Twitter will be answered next month.

Heater
Posts: 10312
Joined: Tue Jul 17, 2012 3:02 pm

Re: Python, Java or both?

Sat Aug 18, 2018 11:54 am

Hmm...COBOL... An interesting choice.

How easy would it be to access the GPIO pins from COBOL? How easy would it be to get interrupts from those pins or other devices? Things that our OP needs for his project.

A couple of years back I decided I'm done with it. I'm old enough that I don't ever want to learn yet another programming language. I have done enough. What a pointless waste of life.

Then I found myself learning Verilog because I wanted to get something done with FPGA's. This year I found myself learning Scala because it can be used as an HDL for said FPGA projects using the Chisel or SpinalHDL libraries. That is far easier and nicer than fighting with Verilog. At least these last two are conceptually very different from your run of the mill programming languages.

richrarobi
Posts: 271
Joined: Sun Feb 08, 2015 1:13 pm

Re: Python, Java or both?

Fri Oct 05, 2018 3:47 pm

Ugh! Sorry! Try Golang? (But you have to find the language that suits you) I doon't like Java, tried Scala, it is too "sophisticated", I tried Rust (too "tight"), etc. (Just my personal view - some like more "obfuscation" - some (me) like it simple, etc)

There is a pre-built version of the latest go available - very easy install - this worked for me:-

Code: Select all

 sudo apt remove golang
 wget https://storage.googleapis.com/golang/go1.11.linux-armv6l.tar.gz
 sudo tar -C /usr/local -xvf go1.11.linux-armv6l.tar.gz
 
 cat >> ~/.bashrc << 'EOF'
 export GOPATH=$HOME/go
 export PATH=/usr/local/go/bin:$PATH:$GOPATH/bin
 EOF

 source ~/.bashrc
https://www.raspberrypi.org/forums/view ... 0#p1373750
For the interconnection of languages, sockets or messaging works for me...

https://github.com/richrarobi/zeegolink

Rich R
Last edited by richrarobi on Fri Oct 05, 2018 4:03 pm, edited 4 times in total.

jahboater
Posts: 3311
Joined: Wed Feb 04, 2015 6:38 pm

Re: Python, Java or both?

Fri Oct 05, 2018 3:55 pm

DougieLawson wrote:
Sat Aug 18, 2018 10:36 am
The obvious answer is "pick a language you know". The less obvious answer is "pick a language you want to learn" (which is why all the code I've written recently has been in C++).
Good answer.

I would consider a language that is well supported on the platform.
That is, comes pre-installed and ready to use, has a large user base so there are lots of people that can help you (in these forums), has a choice of great libraries for directly using the GPIO - and so on.

User avatar
DougieLawson
Posts: 34177
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Python, Java or both?

Fri Oct 05, 2018 5:18 pm

jahboater wrote:
Fri Oct 05, 2018 3:55 pm
That is, comes pre-installed and ready to use, has a large user base so there are lots of people that can help you (in these forums), has a choice of great libraries for directly using the GPIO - and so on.
That's the hard part of my answer. At the moment I'm doing everything in C/C++ with more focus on C++. There's good support for the GPIO wiggling in those two.

The other hard part is: scripting language (perl), scripting language with a byte code interpreter (python), compiled to native code language (C/C++) or compiled to byte code language (Java).

That gets us to the speed of coding, speed of debugging, speed of running, ease of maintenance questions and that brings us full circle. Back to "a language you know" versus "a language you want to learn".
Note:The use of baseball bats for educational purposes is completely disallowed on this forum.

Any DMs sent on Twitter will be answered next month.

Heater
Posts: 10312
Joined: Tue Jul 17, 2012 3:02 pm

Re: Python, Java or both?

Fri Oct 05, 2018 5:23 pm

Perhaps the less obvious answer is to select the language that gets your job done in the most simple and efficient manner. Use the right tool for the job as it were.

Of course we can debate what we mean by "simple" and "efficient". Perhaps quick and easy development time is important to you. Perhaps your task requires the utmost in run time performance. Perhaps support on many platforms is important to you, or not. You decide.

And of course it's hard to make such evaluation and selection unless one has already learned and tried a variety of languages already.

My current selections look like this:

C/C++ for anything that needs to be small, have a simple run time and/or achieve maximal run time performance. C/C++ are standardized, have good support at the the ultimate in cross-platform usability. The price for all that is development complexity.

Javascript. For anything in the browser of course, but also running under node.js for anything that is a web server, deals with networking of any kind, or generally has to juggle lots of events from multiple sources. JS is well standardized, has excellent support and is usable across many platforms including micro-controllers. Performance is very good as well.

Scala. Normally I would not be interested in some new fangled language that relies on the Java virtual machine but in this case I make an exception because Scala and the SpinalHDL library make an excellent way to design logic for FPGA. All the type checking, ease of development and luxury of a high level language but producing as tight a Verilog code as one can create by hand.

Python might be of use if I ever need to do a lot of work with big integers, which it supports naturally. Or perhaps if I needed to make use of some functionality that is available as a Python module but not elsewhere. So far this has not happened.

Most other languages I got to know well are seriously obsolete. Algol, Ada, Coral, PLM, BASIC, Lucol. Lost to history.

I strive to use languages that are properly standardized and in common use. Not dependent on a single vendor. Top marks for good cross-platform support, you never know when you need a change of OS or hardware.

Andyroo
Posts: 688
Joined: Sat Jun 16, 2018 12:49 am

Re: Python, Java or both?

Fri Oct 05, 2018 5:27 pm

Forget everything above - do it backwards in Forth.

The ONLY language where you cannot remember what the code does by the time you’ve pressed the space bar for the next bit :D

To be honest - if it’s not critical I agree with do it in a language you want to learn.
Need Pi spray - these things are breeding in my house...

jahboater
Posts: 3311
Joined: Wed Feb 04, 2015 6:38 pm

Re: Python, Java or both?

Fri Oct 05, 2018 5:34 pm

Andyroo wrote:
Fri Oct 05, 2018 5:27 pm
The ONLY language where you cannot remember what the code does by the time you’ve pressed the space bar for the next bit :D
Look up APL :)

https://www.whoishostingthis.com/resources/apl/
https://en.wikipedia.org/wiki/APL_(prog ... _language)

Extract from the first link:-
Some programming languages have been intentionally designed to be easily read by anyone — programmer or not.

Ruby, Python, COBOL, and many other programming languages employ a syntax that can be read, if not really understood, by anyone with a solid grasp of the English language.

APL is not one of these languages.

To anyone unfamiliar with the syntax of the language, APL looks like a series of nonsensical graphical symbols, letters, and numbers.

User avatar
DougieLawson
Posts: 34177
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Python, Java or both?

Fri Oct 05, 2018 5:47 pm

I wrote a program in APL once.

Code: Select all

2 + 2[enter]
The next thing I typed was

Code: Select all

)OFF HOLD
and I've never looked at APL ever since. There's no value to a language where you have to learn degree level Greek to be able to begin with it. It really was a "write only" language as I doubt anyone could come back to a mass of APL Greek even ten minutes after they wrote it and fathom out what they were doing before drinking that cup of tea.
Note:The use of baseball bats for educational purposes is completely disallowed on this forum.

Any DMs sent on Twitter will be answered next month.

Andyroo
Posts: 688
Joined: Sat Jun 16, 2018 12:49 am

Re: Python, Java or both?

Fri Oct 05, 2018 6:07 pm

I’ll stick with my statement on Forth thanks :D

APL is the only language that you forget after each character!

I once had the option to learn it - NEVER EVER regretted saying no.
Need Pi spray - these things are breeding in my house...

Heater
Posts: 10312
Joined: Tue Jul 17, 2012 3:02 pm

Re: Python, Java or both?

Fri Oct 05, 2018 6:28 pm

Andyroo,
...if it’s not critical I agree with do it in a language you want to learn
Sounds reasonable.

But it's not clear to me how one can know what language one wants to learn before one has learned it?

My theory is that all programming languages have their limitations and annoyances. Skillful programmers who have used one or more languages long enough eventually get annoyed enough by these limitations and annoyances that they are driven to invent their own new programming language. Or extend an old one they like.

Which is why we have such chaos in the programming language world today. Which is why C++ is a gigantic mess and Python keeps getting broken all the time.

jahboater
Posts: 3311
Joined: Wed Feb 04, 2015 6:38 pm

Re: Python, Java or both?

Fri Oct 05, 2018 6:35 pm

Heater wrote:
Fri Oct 05, 2018 6:28 pm
But it's not clear to me how one can know what language one wants to learn before one has learned it?
Perhaps try jobsearch or something similar:

1,883 C++ jobs

11,969 C jobs

3,143 Python jobs

6,595 Javascript jobs

17 Cobol jobs

3,901 Java jobs

Bit surprised at the C++ result.
But ECMAScript and C look worth learning.

Heater
Posts: 10312
Joined: Tue Jul 17, 2012 3:02 pm

Re: Python, Java or both?

Fri Oct 05, 2018 7:39 pm

Interesting.

I'm old school. I don't understand this modern day obsession with chasing programming languages in order to get a job. Sounds like a recipe for a generation of programmers who are not really passionate about what they do and end up with working lives that make them miserable.

Back in the day I was hired to do all kinds of things from military communications to PC applications and the whole question of programming language or even operating system was incidental. It was expected that one was smart enough to pick up those details on the job.

I recall that in one interview I spelled it out that I don't know the language they are using, or their operating system or anything much about their application domain and I don't see how I could be of help. At the end of the two hour interview I was offered the job! It was great, I learned a lot there.

Personally, I have mostly gotten into programming languages just for fun. From Algol to Javascript. I have been curious. If it gets boring let it go. Never a thought about job prospects.

Return to “General programming discussion”