Falak
Posts: 2
Joined: Sat Jun 23, 2018 7:24 am

Which language is preferable

Sat Jun 23, 2018 9:11 am

Hello I’m new to raspberry pi... I bought raspberry pi zero w, and installed Raspbian stretch on it... now my project requirement is to access database on remote location as well as local location database and might also send sms to mobile phone. And I also want to apply lock on code file and encrypt it if possible. So before opening or copying it, it should ask for password... can you help me which language I should go for....

Thanks in advance

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 19845
Joined: Sat Jul 30, 2011 7:41 pm

Re: Which language is preferable

Sat Jun 23, 2018 9:40 am

Probably Python, although C would also work. Depends on how fast you want it to go.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.

jbudd
Posts: 624
Joined: Mon Dec 16, 2013 10:23 am

Re: Which language is preferable

Sat Jun 23, 2018 12:30 pm

And I also want to apply lock on code file and encrypt it if possible
If you don't want people to see your brilliant/embarassing code, go for a compiled program (C) rather than an interpreted script (Python). But compiling won't protect sensitive strings included in the source.

fbe
Posts: 251
Joined: Thu Aug 17, 2017 9:08 pm

Re: Which language is preferable

Sat Jun 23, 2018 12:51 pm

How about Whitespace? (https://en.wikipedia.org/wiki/Whitespac ... _language) Your code will be invisible ;)

What is the purpose of your project? Maybe you better let a webserver do the database access and sms sending. It will be apart from the users. Or is it required that every user has his own local database on his Windows, Mac or Linux machine?

User avatar
The Traveler
Posts: 307
Joined: Sat Oct 21, 2017 3:48 pm

Re: Which language is preferable

Sat Jun 23, 2018 1:27 pm

C would be my choice but you need to learn and understand best practices to "harden" your code. Of course, that applies to any coding language but I think C has a couple advantages over say Java or Python. C has relatively few programming constructs (simpler is good) and unless someone uses attacks present in the C compiler itself, you have a lot of control of how your code works. The other advantage is that if you need it, you can use inline assembly. This last item is probably well outside the scope of your project, but it's nice to be able to write machine code if you really need it for performance or security needs.

Considering that many other higher level languages, such as Python are written in C, how can you go wrong? :)

Cheers.
Last edited by The Traveler on Sat Jun 23, 2018 1:32 pm, edited 1 time in total.
Retired IT professional, programmer and "beardie weirdie".
RPi interests: Autonomous robotics and machine learning.
“Thinking outside of the box allows you to get rewards outside of your reach.” Matshona Dhliwayo

n67
Posts: 697
Joined: Mon Oct 30, 2017 4:55 pm

Re: Which language is preferable

Sat Jun 23, 2018 1:30 pm

The problem with C/C++ is all the undefined behavior.

I.e., the fact that you have to know so much more than the actual language definition in order to avoid your program going haywire.

More sane languages, with less (or no) UB are much better to use.
"L'enfer, c'est les autres"

User avatar
The Traveler
Posts: 307
Joined: Sat Oct 21, 2017 3:48 pm

Re: Which language is preferable

Sat Jun 23, 2018 1:34 pm

The problem with C/C++ is all the undefined behavior.
Really? In my experience most "undefined behavior" can be traced back to programmer error in not following best coding practices, not understanding the language sufficiently and applying it incorrectly. C, as far as I'm concerned, has far, far fewer "UB"s than practically any other language I've known and used but it does place the onus on the programmer more than other higher level languages.
I.e., the fact that you have to know so much more than the actual language definition in order to avoid your program going haywire.
"In Python We Trust"? Yeah, I've seen it. We're putting more and more technology in the hands of people who just "want it to work" without investing the time and effort to know "why" it works. A generation of "casual programmers". You see it in forums all the time. A broken code fragment or script that needs only a minor tweak or fix either of which could have been done by the user had they a bit more knowledge about the language they were coding in.
More sane languages, with less (or no) UB are much better to use.
Uh-huh. A good rationale until your "sane" language displays an "undefined behavior" you didn't know it had. ;)

Cheers.
Retired IT professional, programmer and "beardie weirdie".
RPi interests: Autonomous robotics and machine learning.
“Thinking outside of the box allows you to get rewards outside of your reach.” Matshona Dhliwayo

ejolson
Posts: 1652
Joined: Tue Mar 18, 2014 11:47 am

Re: Which language is preferable

Sat Jun 23, 2018 6:17 pm

n67 wrote:
Sat Jun 23, 2018 1:30 pm
The problem with C/C++ is all the undefined behavior.
While formal language specifications have their uses, it can be misleading to count how many places undefined behaviour leaves decisions to the compiler, which allow it to optimize for different hardware.

For example, the original C language did not specify the associativity of floating-point arithmetic, because additional optimisations are possible if it is assumed associativity doesn't matter. The C89 standard specified left-to-right associativity. As a result gcc, for example, has the option

-funsafe-math-optimizations

to revert to the previous undefined behaviour.

While there are some algorithms, for example Kahan summation, that rely on precisely defined associativity rules, most algorithms don't care. Moreover, a language that forces the programmer to specify things they don't care about in order to avoid undefined behaviour is not as useful as it might at first seem.

It should be pointed out that for many people, C is actually forces the programmer to specify too many details. The essential idea behind C++ is to create undefined behaviour by hiding algorithmic details (which may change depending on version, architecture and optimization) behind the class interface of an opaque object. For example, a sort object may perform a merge sort when running on parallel hardware and a quick sort when running on serial hardware. The programmer doesn't care which behaviour happens and is happy giving the computer the opportunity to optimize things.

Built-in vector and matrix operations are another area where undefined behaviour could allow a compiler to perform optimisations that change behaviour that the programmer doesn't care about. C doesn't have such built-in functionality. Therefore, it could be argued that C does not allow a programmer to express enough undefined behaviour to be a convenient and efficient programming language.

User avatar
The Traveler
Posts: 307
Joined: Sat Oct 21, 2017 3:48 pm

Re: Which language is preferable

Sat Jun 23, 2018 7:15 pm

It should be pointed out that for many people, C is actually forces the programmer to specify too many details.
Yes, it requires them to think about the details instead of hiding them in the language. How can you have "too many details"? What is programming but a "gestalt of details"? Any realistic expectation for competency, in anything, is attention to the small bits and pieces that comprise the whole. My opinion and contention is that if one starts with a coding discipline that is "detail oriented" then it helps form critical and analytical thinking later on.
The essential idea behind C++ is to create undefined behaviour by hiding algorithmic details (which may change depending on version, architecture and optimization) behind the class interface of an opaque object.

Concerning C++, personally I think the whole "object oriented" paradigm is much overused. People tend to apply OOP in cases where it's really not useful. Why do I need a class with all it's burden when a simple struct will suffice? You posit that C has too many details? C++ is loaded with them, polymorphism, inheritance, abstraction. encapsulation, overloading, on top of the basic language syntactic details.

OTOH, maybe it's too much to expect from people approaching a Raspberry Pi for the first time. I'm sure that most RPi hobbyists are quite happy with Python and can work within it's limitations for most of their projects.

Cheers.
Retired IT professional, programmer and "beardie weirdie".
RPi interests: Autonomous robotics and machine learning.
“Thinking outside of the box allows you to get rewards outside of your reach.” Matshona Dhliwayo

User avatar
Paeryn
Posts: 2018
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Which language is preferable

Sat Jun 23, 2018 8:10 pm

The Traveler wrote:
Sat Jun 23, 2018 7:15 pm
Concerning C++, personally I think the whole "object oriented" paradigm is much overused. People tend to apply OOP in cases where it's really not useful. Why do I need a class with all it's burden when a simple struct will suffice?
C++ doesn't force you to write your code OOP (other than when using the parts of the standard that are).
Why do you think a class has more burdon than a struct? A struct and a class are practically the same, the only difference is that, until you explicitly set visibility, a struct's members are public whereas a class' members are private. A struct can have everything that a class can have and similarly a class can be used just like a traditional C struct.
She who travels light — forgot something.

ejolson
Posts: 1652
Joined: Tue Mar 18, 2014 11:47 am

Re: Which language is preferable

Sat Jun 23, 2018 8:32 pm

The Traveler wrote:
Sat Jun 23, 2018 7:15 pm
It should be pointed out that for many people, C is actually forces the programmer to specify too many details.
Yes, it requires them to think about the details instead of hiding them in the language. How can you have "too many details"?
Any detail which isn't needed to express the algorithm and that the programmer is not interested in is too much.

If I'm indexing a three dimensional array with dimensions n by n by n, I may not care whether n is a 16-bit, 18-bit, 32-bit, 36-bit or even a 64-bit integer. I just want the compiler to choose what is efficient for whatever computer architecture I happen to be using so I can focus on more important things.

Multiplying two n by n matrices together takes n-cubed multiply and add instructions that can be executed in any order to achieve the required result, though rounding errors will be different. I want the computer to figure out the best way to order those operations for efficiency. Making a programmer specify the order explicitly is too many details.
Last edited by ejolson on Sat Jun 23, 2018 8:39 pm, edited 1 time in total.

User avatar
bensimmo
Posts: 2911
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Which language is preferable

Sat Jun 23, 2018 8:38 pm

The Traveler wrote:
Sat Jun 23, 2018 1:34 pm
"In Python We Trust"? Yeah, I've seen it. We're putting more and more technology in the hands of people who just "want it to work" without investing the time and effort to know "why" it works. A generation of "casual programmers". You see it in forums all the time. A broken code fragment or script that needs only a minor tweak or fix either of which could have been done by the user had they a bit more knowledge about the language they were coding in.
Not really a Python problem, it just makes it a bit easier.
The same could be said for C and Arduino.
Casual programming and a few tweaks to make it work.., no idea what most of the code does or all the modules they import.

User avatar
The Traveler
Posts: 307
Joined: Sat Oct 21, 2017 3:48 pm

Re: Which language is preferable

Sat Jun 23, 2018 8:52 pm

Any detail which isn't needed to express the algorithm and that the programmer is not interested in is too much.
So, you're only interested in the details as they apply to your current problem domain? Interesting. Learn and apply only what you need to know and no more. I imagine if one is an academic solving only algorithms using only a subset of the language is fine. However, in my personal experience, successful programmers solve a much broader range of programming issues. Understanding the details of a language allows one to formulate different approaches to a problem. It allows one to "think outside the box" with more creative freedom to solve problems.
If I'm indexing a three dimensional array with dimensions n by n by n, I may not care whether n is a 16-bit, 18-bit, 32-bit, 36-bit or even a 64-bit integer.
If you've never been tasked with writing portable code for different architectures you probably wouldn't care. For someone who programs for his or her bread and butter it matters significantly. Relying on the compiler doesn't always work in those cases.

Cheers.
Retired IT professional, programmer and "beardie weirdie".
RPi interests: Autonomous robotics and machine learning.
“Thinking outside of the box allows you to get rewards outside of your reach.” Matshona Dhliwayo

n67
Posts: 697
Joined: Mon Oct 30, 2017 4:55 pm

Re: Which language is preferable

Sat Jun 23, 2018 9:25 pm

While I have found the responses to my previous post in this thread amusing and entertaining as always, it seems pretty clear that very few posters on this board understand what the term "undefined behavior" actually means and what its purpose (in the C programming language) is.

Yes, purpose. It is actually a feature, not a bug.

However, it makes the language unsuitable for beginners - especially here and now in the year of our Lord 2018.

Some number of decades ago, it was about the only choice (if one was learning to program on Unix), but those days are now gone.

Mind you, none of what I have written in this thread should be in any way taken as stumping for Python (or any other language). I have intentionally left that part vague.
"L'enfer, c'est les autres"

User avatar
The Traveler
Posts: 307
Joined: Sat Oct 21, 2017 3:48 pm

Re: Which language is preferable

Sat Jun 23, 2018 10:04 pm

However, it makes the language unsuitable for beginners - especially here and now in the year of our Lord 2018. Some number of decades ago, it was about the only choice (if one was learning to program on Unix), but those days are now gone.
Hardly. Beginners can cope with undefined behaviors now just like we did then by being taught how to deal with them. Everyone starts out as a beginner. You seem to think that beginners are what, less intelligent, when they are simply less experienced. You gain experience by doing something, repeatedly if necessary, until you learn from it.

C is just as relevant today as it was when Ritchie and Bell Labs created it 46 years ago. I find that it's interesting that C is one of the few programming languages that has endured for such a length of time and is still in constant use. C is the foundation on which a large number of higher level languages are built and I'm thankful that more "beginners" don't take the point of view that you seem to have about learning it.

That's it for me on the subject.

Cheers.
Retired IT professional, programmer and "beardie weirdie".
RPi interests: Autonomous robotics and machine learning.
“Thinking outside of the box allows you to get rewards outside of your reach.” Matshona Dhliwayo

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

Re: Which language is preferable

Sun Jun 24, 2018 6:03 am

The Traveler wrote:
Sat Jun 23, 2018 10:04 pm
However, it makes the language unsuitable for beginners - especially here and now in the year of our Lord 2018. Some number of decades ago, it was about the only choice (if one was learning to program on Unix), but those days are now gone.
Hardly. Beginners can cope with undefined behaviors now just like we did then by being taught how to deal with them. Everyone starts out as a beginner. You seem to think that beginners are what, less intelligent, when they are simply less experienced. You gain experience by doing something, repeatedly if necessary, until you learn from it.
Yes. In most cases UB is pretty obvious (such as writing outside of an array for example). For more unusual things I refer to the standard which is small enough to find your way around in easily. The standard is very clear and precise about what is "undefined behavior" , "implementation defined behavior", and "unspecified behavior". A strong feature in my book.

That is one of the good things about C - the ISO standard. Python does not have one, and (for example) look how thats developed over the years, a major rift between versions.
The Traveler wrote:
Sat Jun 23, 2018 10:04 pm
C is just as relevant today as it was when Ritchie and Bell Labs created it 46 years ago. I find that it's interesting that C is one of the few programming languages that has endured for such a length of time and is still in constant use. C is the foundation on which a large number of higher level languages are built and I'm thankful that more "beginners" don't take the point of view that you seem to have about learning it.
Yes indeed.
And more than half the worlds software is written in C.
Many, if not all, of the other languages mentioned around here rely on C to do the heavy lifting - to implement their libraries in, to write their interpreters in and so on. I always wonder if these languages are so good, why they must rely on another language to do the complex or speed sensitive stuff.
Last edited by jahboater on Sun Jun 24, 2018 7:40 am, edited 1 time in total.

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

Re: Which language is preferable

Sun Jun 24, 2018 6:21 am

ejolson wrote:
Sat Jun 23, 2018 6:17 pm
While there are some algorithms, for example Kahan summation, that rely on precisely defined associativity rules, most algorithms don't care. Moreover, a language that forces the programmer to specify things they don't care about in order to avoid undefined behaviour is not as useful as it might at first seem.
Then there is the "as if" rule. A compiler may ignore associativity and most other language rules as long as the end result is the same. I once saw gcc execute "if( a == 5 || a == 6 )" the wrong way round and raised a bug. But the "as if" rule allows it. And I have since realized that in more complex expressions, such reordering/folding/eliding has huge benefits.

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

Re: Which language is preferable

Sun Jun 24, 2018 6:36 am

ejolson wrote:
Sat Jun 23, 2018 8:32 pm
If I'm indexing a three dimensional array with dimensions n by n by n, I may not care whether n is a 16-bit, 18-bit, 32-bit, 36-bit or even a 64-bit integer. I just want the compiler to choose what is efficient for whatever computer architecture I happen to be using so I can focus on more important things.
In an ideal language, what would you want?
Perhaps the programmer does not specify the type for "n". The compiler must deduce from the code that "n" is being used for array subscripting and choose "size_t" say. BTW gcc will mostly do that anyway (declare "n" as a 32-bit int, and you will see it using a 64-bit register for all the array indexing, and 32-bits for arithmetic - ignoring what the programmer said).

Where the compiler cant do that for some reason, the costs of choosing the wrong type are high (constant sign extending, prefix bytes, limited support on RISC etc).

If you care about speed then things like this matter, if not, choose a language like Python which will allow you to focus on more important things, as you say.

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

Re: Which language is preferable

Sun Jun 24, 2018 1:00 pm

The Traveler,
C, as far as I'm concerned, has far, far fewer "UB"s than practically any other language I've known...
Clearly you have not known many other languages.

If you want to know how your C/C++ program will behave not only do you have to know the language standard documents inside out, you also have to know how your compiler does things inside out. And if you want your code to run on multiple platforms, OS and hardware, compiled by different compilers you need to know about all the ways they define things.
"In Python We Trust"? Yeah, I've seen it. We're putting more and more technology in the hands of people who just "want it to work" without investing the time and effort to know "why" it works. A generation of "casual programmers".
So what?

A user of a high level language should not have to worry about implementation details. That is the whole point of HLLs after all. Sadly C/C++ fail badly in this respect. Sadly so do many others to this day.

Besides, I'm sure there are many things you use everyday that you have no real understanding of. When you press the light switch in your living room do you really know all about what is happenning to make the light come on? When you take your meds in the morning, do you really know what effect they have on your body and how?

Having said that, I do agree that it is useful and interesting to know what goes on under the hood of one's software creations. From the compiler to the OS to the processor to the logic gates to the transistors to the quantum mechanics of it all.

None of which helps our OP with their problem.

Return to “Beginners”

Who is online

Users browsing this forum: Banyanss and 61 guests