Arduino Forum

Community => Bar Sport => Topic started by: tjones9163 on Apr 17, 2017, 03:06 am

Title: Best programming language for beginners?
Post by: tjones9163 on Apr 17, 2017, 03:06 am
Hello, From the community's experience what is the best programming language to learn for absolute beginner? EX. Python, java,c+
Title: Re: Best programming language for beginners?
Post by: jremington on Apr 17, 2017, 03:10 am
BASIC, of course.
Title: Re: Best programming language for beginners?
Post by: tjones9163 on Apr 17, 2017, 03:15 am
Is that the name of the language?
Title: Re: Best programming language for beginners?
Post by: BulldogLowell on Apr 17, 2017, 04:00 am
I would start with JavaScript.

A very useful language that you can do a lot with, and see results quickly.  It can stretch from very basic to very sophisticated (simple web pages to server side functionality like Node.js). 

But if you want to program your Arduino, learning basic C++ would be a good start.

Any language you learn changes your next question from "how do I do this?" To "how do I do this in python/java/ruby/swift/C#/Perl/.......?" 

Title: Re: Best programming language for beginners?
Post by: J-M-L on Apr 17, 2017, 04:24 am
Hello

My recommendation would be : Don't invest massive time in learning  a particular language without investing Equal  time as well into reading (and practicing) logic flow and algorithm. Also Understand the theory and the architecture of a computer and how a micro processor work, what is the memory and how it's used, what compiling means etc.  that will come handy later on

You could start anywhere on line, like wikiversity's School of Computer Science (https://en.m.wikiversity.org/wiki/School:Computer_Science) first two topics or any computer science mooc like the one form harvard (https://www.edx.org/course/introduction-computer-science-harvardx-cs50x) or MIT's open courseware on Electrical Engineering and Computer Science (https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/) and many many more.

Be ready in your mind for a long process - go in steps. Once you have the basis, There are a number of languages in the market today and for general programing I'd say you have procedural languages (C, Pascal, Basic,...) and object oriented languages (C++, Java, Objective C, Swift, Python,...). If you have the theory clear in your mind, a language does not matter much and is not hard to acquire.

if you want to play with micro-controllers like arduino, you need to be close to the hardware and  best high level languages are C and C++ where tons of documentation and libraries exist to help you out.



Title: Re: Best programming language for beginners?
Post by: tjones9163 on Apr 17, 2017, 04:28 am
Thank you i will and i have been reading tons. Thanks
Title: Re: Best programming language for beginners?
Post by: J-M-L on Apr 17, 2017, 04:34 am
Good - that's the key (dont forget to practice too)

+1 karma as encouragement! 
Title: Re: Best programming language for beginners?
Post by: tjones9163 on Apr 17, 2017, 04:40 am
Thank you. I will!!
Title: Re: Best programming language for beginners?
Post by: jremington on Apr 17, 2017, 05:27 am
Don't forget FOCAL, in which the very first lunar lander game program was written (1969).

In researching the history of this popular game, and reverse engineering the code, I was fascinated to discover that the code block consisting of lines 8.10-8.30 is actually wrong. The error has no significant effect on the overall operation, so leaving that block of code out entirely is fine.

However, this code has been translated verbatim into several other programming languages and calculator languages, with the error left intact. Apparently no one bothered trying to figure out what it did.

Code: [Select]
01.04 T "CONTROL CALLING LUNAR MODULE.MANUAL CONTROL IS NECESSARY"!
01.06 T "YOU MAY RESET FUEL RATE K EACH 10 SECS TO 0 OR ANY VALUE"!
01.08 T "BETWEEN 8&200 LBS/SEC.YOU'VE 16000 LBS FUEL.ESTIMATED"!
01.11 T "FREE FALL IMPACT TIME-120 SECS.CAPSULE WEIGHT-32500 LBS"!
01.20 T "FIRST RADAR CHECK COMING UP"!!!
01.30 T "COMMENCE LANDING PROCEDURE"!"TIME,SECS   ALTITUDE,"
01.40 T "MILES+FEET   VELOCITY,MPH   FUEL,LBS   FUEL RATE"!

02.05 S L=0;S A=120;S V=1;S M=33000;S N=16500;S G=.001;S Z=1.8
02.10 T "    ",%3,L,"       ",FITR(A),"  ",%4,5280*(A-FITR(A))
02.20 T %6.02,"       ",3600*V,"    ",%6.01,M-N,"      K=";A K;S T=10
02.70 T %7.02;I (K)2.72;I (200-K)2.72;I (K-8)2.71,3.1,3.1
02.71 I (K-0)2.72,3.1,2.72
02.72 T "NOT POSSIBLE";F X=1,51;T "."
02.73 T "K=";A K;G 2.7

03.10 I ((M-N)-.001)4.1;I (T-.001)2.1;S S=T
03.40 I ((N+S*K)-M)3.5,3.5;S S=(M-N)/K
03.50 D 9;I (I)7.1,7.1;I (V)3.8,3.8;I (J)8.1
03.80 D 6;G 3.1

04.10 T "FUEL OUT AT",L," SECS"!
04.40 S S=(-V+FSQT(V*V+2*A*G))/G;S V=V+G*S;S L=L+S

05.10 T "ON THE MOON AT",L," SECS"!;S W=3600*V
05.20 T "IMPACT VELOCITY OF",W,"M.P.H."!,"FUEL LEFT:"
05.30 T M-N," LBS."!;I (-W+1)5.5,5.5
05.40 T "PERFECT LANDING !-(LUCKY)"!;G 5.9
05.50 I (-W+10)5.6,5.6;T "GOOD LANDING-(COULD BE BETTER)"!;G 5.90
05.60 I (-W+25)5.7,5.7;T "CONGRATULATIONS ON A POOR LANDING"!;G 5.9
05.70 I (-W+60)5.8,5.8;T "CRAFT DAMAGE.GOOD LUCK"!;G 5.9
05.80 T "SORRY,BUT THERE WERE NO SURVIVORS-YOU BLEW IT!"!"IN"
05.81 T "FACT YOU BLASTED A NEW LUNAR CRATER",W*.277777,"FT.DEEP.
05.90 T "CONTROL OUT";QUIT

06.10 S L=L+S;S T=T-S;S M=M-S*K;S A=I;S V=J

07.10 I (S-.005)5.1;S S=2*A/(V+FSQT(V*V+2*A*(G-Z*K/M)))
07.30 D 9;D 6;G 7.1

08.10 S W=(1-M*G/(Z*K))/2;S S=M*V/(Z*K*(W+FSQT(W*W+V/Z)))+.05;D 9
08.30 I (I)7.1,7.1;D 6;I (-J)3.1,3.1;I (V)3.1,3.1,8.1

09.10 S Q=S*K/M;S J=V+G*S+Z*(-Q-Q^2/2-Q^3/3-Q^4/4-Q^5/5)
09.40 S I=A-G*S*S/2-V*S+Z*S*(Q/2+Q^2/6+Q^3/12+Q^4/20+Q^5/30)
Title: Re: Best programming language for beginners?
Post by: RayLivingston on Apr 17, 2017, 06:01 am
There is no such thing as a "best" language, without defining exactly what it is you want to do.  I've used literally dozens of languages over the last 35 years.  All have their strengths and weaknesses, and different languages are good at different things.  Even now, I use a number of different languages, depending on what I need to do.  On any given day, I might be working in c, c++, c#, Perl, Java, Javscript, HTML, CSS, shell scripts, or any of a half-dozen others.

Since you're on an Arduino forum, I can tell you that if you want to do something with Arduinos, very nearly your only choice is c++.  Whether that is "best" or not, it IS what is available, and it will get the job done.

Regards,
Ray L.
Title: Re: Best programming language for beginners?
Post by: holmes4 on Apr 17, 2017, 06:10 am
Quote
BASIC, of course.
Basic - Never

The only language designed for teaching programming was PASCAL. But it was designed for noob's to learn the art of programming and there for (sadly) never became a really strong main stream language.

Of the ones in main stream use today the C/C++ is all but the only choice! C(sharp), python or very narrow languages focused on Internet applications,

Java (and NOT Javascript) is the only real alternative.

Mark
Title: Re: Best programming language for beginners?
Post by: GoForSmoke on Apr 17, 2017, 07:53 am
For absolute beginners to just get started, I'd say interpreter BASIC is a good choice.

It is simple and immediate. You can do things with it without writing actual lines of code. Trying simple things out is very easy.

Plus, as the students get experience they will also get an increasing revulsion to BASIC that will help them move on.
hey, it worked for me!
Title: Re: Best programming language for beginners?
Post by: Robin2 on Apr 17, 2017, 09:34 am
Python. 

IMHO interpreted languages are easier for beginners.

Some time ago I would have said Ruby, but its support infrastructure is not as good as Python.

...R
Title: Re: Best programming language for beginners?
Post by: pert on Apr 17, 2017, 09:49 am
I don't feel that BASIC is the best choice for a motivated beginner in the year 2017. Maybe it was in 1990 but no longer. Once you learn how to use BASIC you'll never use it again. Of course you'll learn the general concepts of programming from it but any language specific knowledge will just be thrown away. Decide on something you want to do with your programming skills and pick the best language for that application. Then you will have a goal to work towards instead of just flipping bits. In my life C++ and Python are the most useful. I'm forced to work with some others (Scheme, Windows Batch, Bash, PHP, HTML) but when possible I prefer to spend my time getting good at one or two rather than spreading it over a dozen languages.
Title: Re: Best programming language for beginners?
Post by: J-M-L on Apr 17, 2017, 10:04 am
Agree that it also depends on your target platform - Java for Android (with ability for a C/C++ wrapper), Swift and Objective C (and C/C++) for Apple, C# (and C/C++)  for Microsoft

So while all major platforms have their preference, you can see they support C and C++ as well so that's not a bad choice to expose yourself to the world.

That being said - There was a study last year: 15 best paying programming languages in 2016 (https://www.techworm.net/2016/06/15-highest-paying-programming-languages-2016.html) that put Java, Python, R, Objective C, Swift, C#, JavaScript, Perl, C++, SQL, Ruby on Rail, C,  in this order of demand in the market - but starting with C and C++ to understand OO programing will get you on the right path


Title: Re: Best programming language for beginners?
Post by: msssltd on Apr 17, 2017, 12:18 pm
Taking the question literally, I would say Pascal is the best language for a beginner to learn first.  Pascal bridges the gap between low and high level, reaches as far as object orientation and goes a long way towards deterring bad habits.  Learning Pascal first, makes everything else much easier.

BASIC still has a place, despite the snobbery.  The advantage is the immediate rewards which inspired so many of us to stay the course.  Modern structured BASICs often come with OOP and a compiler of sorts.  Apart from the near English constructs which make it so easy to learn, I honestly struggle to see much which distinguishes these modern BASICs from most other high level languages.  BASIC remains popular for macro languages, rapid prototyping and there are still millions of applications in production use written in 'BASIC like' languages. 

The shortcoming of BASIC is it is strictly high level and won't help much when you get to lower level languages like C/C++  The drawback to learning BASIC first is the bad habits it lets you fall into can be difficult to drop...And of course that snobbery.

Once you have a low level and a high level language under your belt, learning becomes more about design patterns, libraries and fashions.  Whatever language you choose, the constructs are generally similar as there is a microprocessor with input and output underneath them all.


Python though...Is Devil spawn.  Making indentation and white space syntactically significant sucks the very joy from life.  I am pretty sure if I had been made to learn Python at school, I would have ended up with a completely different career.
Title: Re: Best programming language for beginners?
Post by: Robin2 on Apr 17, 2017, 01:16 pm
Python though...Is Devil spawn.  Making indentation and white space syntactically significant sucks the very joy from life.  I am pretty sure if I had been made to learn Python at school, I would have ended up with a completely different career.
Tosh.  :)

If someone learns to use indentation with Python and then applies the same style in their Arduino programs it makes them easy to read. How many times do you see requests here for people to use the AutoFormat tool? People brought up on Python would do the indentation automatically. The only thing that Python does not require is the equivalent of the closing }

...R
Title: Re: Best programming language for beginners?
Post by: GoForSmoke on Apr 17, 2017, 03:29 pm
Yes, definitely saddle completely raw beginners with structure and a compiler. What was I thinking?
Title: Re: Best programming language for beginners?
Post by: pert on Apr 17, 2017, 03:56 pm
Yes, definitely saddle completely raw beginners with structure and a compiler. What was I thinking?
That must be why Arduino has been such a huge failure with people new to programming. Oh wait...
Title: Re: Best programming language for beginners?
Post by: BulldogLowell on Apr 17, 2017, 04:17 pm
Quote
Taking the question literally, I would say Pascal is the best language for a beginner to learn first.
I studied Latin in school. It's great, Today I can speak it with absolutely no one. It wasn't until I was an adult before I learned another language that is actually used (Spanish) somewhere other than the classrooms where it's taught (is it even anymore?).

Chinese... tough language to learn, well, except for the billion plus who started there!

Jump in and learn a useful language based on what you may feel you want to do!

There are places like this where people will help self-starters wanting to learn. I'm sure I could even find a Latin forum if I really wanted!

Computer programmers like to stand behind the scary, fiery wall like the Great Wizard of Oz. Warding off folks, lest they discover what's behind all that fire and smoke.... just some dude pulling levers.
Title: Re: Best programming language for beginners?
Post by: TKall on Apr 17, 2017, 04:22 pm
Excellent beginner course. https://see.stanford.edu/Course/CS106A (https://see.stanford.edu/Course/CS106A)


Title: Re: Best programming language for beginners?
Post by: Robin2 on Apr 17, 2017, 04:56 pm
That must be why Arduino has been such a huge failure with people new to programming. Oh wait...
I think you are mixing your apples and oranges.

IMHO the Arduino has been successful in spite of its programming language, not because of it.

Nobody in his right mind would use C or C++ if he did not have to. :)

...R
Title: Re: Best programming language for beginners?
Post by: Henry_Best on Apr 17, 2017, 06:51 pm
Is that the name of the language?
Yes.
Beginners
All purpose
Symbolic
Instruction
Code
Title: Re: Best programming language for beginners?
Post by: J-M-L on Apr 17, 2017, 06:56 pm
 it claims it's for Beginners but does not claim it's the Best  which is part of the OP ask :)
Title: Re: Best programming language for beginners?
Post by: Henry_Best on Apr 17, 2017, 07:00 pm
it claims it's for Beginners but does not claim it's the Best  which is part of the OP ask :)
I never said it was. I was only answering the OP's question that I quoted.
Title: Re: Best programming language for beginners?
Post by: J-M-L on Apr 17, 2017, 07:15 pm
Fair enough was just trying to make a joke
Title: Re: Best programming language for beginners?
Post by: GoForSmoke on Apr 17, 2017, 08:03 pm
That must be why Arduino has been such a huge failure with people new to programming. Oh wait...
As long as you don't say ALL the people new to programming who try it because I don't see near 100% success on the forum but then I've only been here 5 years now.

By your "how many people" metric, BASIC has been an astounding success.

By what I've been saying, 20 or 30 hours with interpreter line-number BASIC can get fundamentals down that I've seen more than a few newbies with more time miss.

Take a break, sheesh.
Title: Re: Best programming language for beginners?
Post by: GoForSmoke on Apr 17, 2017, 08:07 pm
Nobody in his right mind would use C or C++ if he did not have to. :)
Call the men with the butterfly nets for me then.
Title: Re: Best programming language for beginners?
Post by: GoForSmoke on Apr 17, 2017, 08:12 pm
Computer programmers like to stand behind the scary, fiery wall like the Great Wizard of Oz. Warding off folks, lest they discover what's behind all that fire and smoke.... just some dude pulling levers.

There's a priesthood with jargon and all, and boy oh boy they HATE when outsiders fix their code and beat them to contracts.
Title: Re: Best programming language for beginners?
Post by: westfw on Apr 18, 2017, 06:08 am
The problem with BASIC is that it has little standardization.   A modern BASIC (say, Microsoft Visual Basic, or RealBasic) has most of the features that a modern programmer should like, has a compiler that produces fast code, and has a good IDE with powerful debugging features.)  But those tend to lack "embedded" features.  Other BASIC compilers are specifically aimed at microcontrollers, but you're likely to think that you've been handed a completely different language than those "Desktop BASICs" (you have.)  Parallax Stamp PBASIC is horribly primitive and slow, for instance (but they make up for it by including "embedded programming functions" as language keywords (like "shiftout")

Pascal was indeed designed as a teaching language.   But that was back in the mid-1970s, and it's been a bit neglected since the 1980s.  To be useful, it needs "extensions" beyond the basic language, which are somewhat poorly standardized.   I became disenchanted with Pascal when I realized how much it cheats - the language has features and syntax that a user can't duplicate (at least, not without more 'extensions.')  And the extent to which it seemed to deliberately limit itself to be ONLY a "teaching language" (not that that lasted.   For a long time, a lot of the Apple system and application software was written in a Pascal-like language.)

When considering a "learning language", you need to consider the teaching and learning resources available.  And your "goal" - a lot of "learn XXX in 5 weeks" sort of programming instruction (including Arduino) is about learning to do some useful things as quickly as possible.  That's great, but you miss out on principles.   A lot of "University introductory Computer Science" classes are big on principles and theory, but essentially only prepare you to take the next class, where you'll learn more details (and eventually, how to do something more useful than a class assignment.)  (and the truth is, that even after getting through a 4-year CS degree, your actual programming skill may be "meh" by industry standards, especially if you haven't forced yourself to do some major "projects" outside the scope of the usual assignments.)  And University teach different languages depending on whether you're going into theory (CS) or into actual problem solving (EE, ME, Most of the sciences, etc.)  (At one of the colleges my daughter looked at, they were still teaching Fortran!  To Physics or ME majors, IIRC.

So... universities today seem to be teaching Java, Python, and C++ as their "intro" languages.  I've take a bunch of online classes (MOOCs.)   There have been some very good classes using Java and Python.  The only C++ class I took was ... pretty awful.   There was also the UTexas "Embedded Systems" class that used C (and taught some "embedded C constructs, but expected you to already know the basics.)

There's also the fact that "beginning" classes are NOT going to teach you everything there is to know about a language.  One of the complaints about all three of those languages is that they're HUGE, with MANY FEATURES and EVEN MORE LIBRARIES.  (as opposed to, say, C, which is really tiny (but still has lots of libraries.))   Some of the features seem to be obscure nods to some tiny corner of some unknown discipline, rarely used unless YOUR PROFESSOR happened to like them (or someone where you work.)  The way you learn about these generally involves coming across them in published code, and going "WTF?" and then figuring them out...)  Then you can either decided that they're useful, or the product of a deranged mind who shouldn't have been allowed near a compute.  (There was a post recently where someone had used C++ operator overloading such that "a = b + c;" changed b and c.   Shudder.)

Finally, it doesn't really matter all that much.  If you learn C++, but the next class you take is "Data Structures and Algorithms using Java", you'll have a few things to catch up on, but you're not going to be completely lost.  There are a lot of similarities between languages; you find pieces that you like better, pieces that you like worse, in one or another, and it may influence what you choose to use for your personal programming.  But professionally, you're more likely to have that dictated by your employer, and it won't be THAT uncommon for an prospective employer to expect their language choice to be irrelevant.  If you've done GPS data logging in C# for Windows Phone, the "GPS data logging for a phone" is likely to be a more important piece of the hiring decision than the "C#" part; you'd be expected to be able to do something similar in Java for Android phones without too much additional effort.
Title: Re: Best programming language for beginners?
Post by: GoForSmoke on Apr 18, 2017, 08:34 am
x=3.14159
print x
3.14159
i%=x
print i%
3

Sometimes it's just about playing with the blocks directly, getting to know the shapes.
Structure? There are concepts that don't even need code to demonstrate directly, instantly.

We do get people on the forum who are semi-clueless mimes when it comes to variables despite writing scores of lines of well it runs code. That's just success waiting for help to happen, right? It it wasn't waiting, it would have happened.
Title: Re: Best programming language for beginners?
Post by: GoForSmoke on Apr 18, 2017, 08:47 am
Pascal was indeed designed as a teaching language.   But that was back in the mid-1970s, and it's been a bit neglected since the 1980s.  To be useful, it needs "extensions" beyond the basic language, which are somewhat poorly standardized.   I became disenchanted with Pascal when I realized how much it cheats - the language has features and syntax that a user can't duplicate (at least, not without more 'extensions.')  And the extent to which it seemed to deliberately limit itself to be ONLY a "teaching language" (not that that lasted.   For a long time, a lot of the Apple system and application software was written in a Pascal-like language.)
I still have my 1985 Byte issue where Niklaus Wirth wrote that to get a program right you write it twice and throw the first one away. Then he wrote that Pascal is that first one, Modula is the one to keep. And who am I to argue? I've helped fix Pascal homework because logic is logic but I swear that language is more anal-retentive than COBOL. I never tried the next step into that.
Title: Re: Best programming language for beginners?
Post by: Robin2 on Apr 18, 2017, 10:19 am
I never tried the next step into that.
Sheesh - I was getting all psyched up for your Modula introduction  :)

...R
Title: Re: Best programming language for beginners?
Post by: westfw on Apr 18, 2017, 11:04 am
Quote
Sometimes it's just about playing with the blocks directly, getting to know the shapes.
I dunno.  Can you actually do loops and stuff "interactively"?  Certainly not in some of the microcontroller BASICs.
BASIC was my first language, and I've even written BASIC for work (a long time ago (http://www.oocities.org/westfw/ibmftp.bas.txt)) (ok: BASIC and x86 machine language!)   I don't remember ever doing much with "interactive mode" (debugging perhaps?) - maybe the interpreters I used didn't have that feature?  In any case, that's just a glorified calculator - part of programming is planning the whole thing ahead...

(I had to look at i%=x for quite a while before stopped thinking "modulus?  BASIC doesn't do THAT!"  :-) )

(Hopefully you don't have to do  LET x=3.14159 )

(Heh.  LISP and FORTH have fine interactive interpreters as well, but I'm not going to recommend them either.  Python does pretty well as an interactive interpreter:
>>> x=3.14159
>>> print x
3.14159
>>> i = int(x)
>>> print i
3
for i in [x/6, x/4, x/3, x/2, x]:
...   print sin(i)
...
0.499999616987
0.707106312094
0.866024961519
0.999999999999
2.65358979335e-06
>>>
)

Title: Re: Best programming language for beginners?
Post by: Robin2 on Apr 18, 2017, 12:40 pm
Python does pretty well as an interactive interpreter:
You can do the same sort of thing with Ruby and many of the introductions to both languages use the interactive interpreter. However I have never been able to see the point of it myself.

If I want to do calculations I have a calculator.

If I want to write a program then I want to save it in a file so I can use it over and over - or amend it if I've got it wrong.

...R
Title: Re: Best programming language for beginners?
Post by: msssltd on Apr 19, 2017, 12:57 am
I studied Latin in school. It's great, Today I can speak it with absolutely no one.
Apples and oranges.  The first commercially useful program I wrote was in BASIC and VB is probably the language I have made most money from.  I did some assembler and C/C++.  Then I had to do a couple of projects in Delphi and it brought clarity, to what I had been hacking away at for years.  Type, scope and OOP particularly, made so much more sense.  When I went back to C++ it was so much easier to write clear, bug free code, first time around.  When I switch to another language or dialect, the important lessons are carried from Pascal and just have to learn some new keyword and fit within the syntax of the constructs provided.

Quote from: Robin2
Tosh!
Sounds like the 1950s classroom where Python belongs.  Where kids were punished for writing with their left hand, just because.  Indentation has no computational value.  It should not cause a compiler to choke.  Indentation is for humans and should remain in the human domain.  If it is that important, have the editor impose it automatically.  While you are still trying to learn what a variable is, worrying about whitespace is a distraction nobody needs.  Clearly this is a personal opinion ;)
Title: Re: Best programming language for beginners?
Post by: jremington on Apr 19, 2017, 04:47 am
Quote
Once you learn how to use BASIC you'll never use it again.
Nonsense!!!

I have a Toshiba T1200 laptop with an LCD screen from about 1988 that runs QBASIC in DOS 3.3.

I still use it to collect data for my weather station.  A 720K floppy disk holds months of data, and the laptop runs for hours on 6xAA batteries if the power goes out!

Also keeps a nice plot of the last ~20 hours of average wind speed and gusts on the screen.

For the BASIC aficionados among you, here is the wind gauge code:

Code: [Select]
REM read wind gauge and store statistics on disk.

REM circular buffer push and pull
DECLARE SUB gbuf (array!(), v!, nsp%, nsmax%)
DECLARE SUB pbuf (array!(), v!, ns%, nsp%, nsmax%)

REM plot wind speed data in box 1-600 on x, 0-99 on y, lower screen
DIM t0(600), t1(600)
DEFINT I-N
DEFSNG K

nsec = 300 'sample save interval in seconds

SCREEN 2 '640x200
'
' VIEW defines graphics viewport in absolute screen coords, subsequent
' pixel coords are relative to view window
'
' VIEW SCREEN  (ditto) but subsequent pixel coords are absolute
' Order of coordinate pairs is immaterial!
'
VIEW (21, 98)-(620, 198), , 1: REM view won't frame extreme edges
WINDOW (1, 0)-(600, 99): REM logical coords 1-600 on x, 0-99 on y
CLS

OPEN "com1:4800,n,8,1,cs0,ds0,cd0" FOR INPUT AS #1

LOCATE 1, 1: PRINT "Starting wind monitor at: "; DATE$; " "; TIME$
LOCATE 2, 1
INPUT "Output file name: ", n$
OPEN n$ FOR OUTPUT AS #2

PRINT #2, DATE$; " "; TIME$; " sample:"; nsec

r% = 0
REM number of points in graph, buffer pointers
n0m = 300: n0 = 0: n0p = 1
n1m = 300: n1 = 0: n1p = 1

REM get version #

'ON ERROR GOTO handler

LINE INPUT #1, a$
LOCATE 3, 1: PRINT "Version and time: "; a$
LOCATE 4, 1: PRINT "Hit Esc to exit..."

nsamp = 0: wmaxt0 = 0: avgt0 = 0: vart0 = 0

ON TIMER(nsec) GOSUB 5000
TIMER ON

10 LINE INPUT #1, a$: LOCATE 9, 33: PRINT a$; "     "
nc = INSTR(a$, ","): a$ = MID$(a$, nc + 1)
nc = INSTR(a$, ","): a$ = MID$(a$, nc + 1)
   
15      temp0 = VAL(a$) / 22.6
nc = INSTR(a$, ",")
20      temp1 = VAL(MID$(a$, nc + 1)) / 22.6: REM max reported by sensor
       
IF (wmaxt0 < temp1) THEN wmaxt0 = temp1
avgt0 = avgt0 + temp0
vart0 = vart0 + temp0 * temp0
nsamp = nsamp + 1

LOCATE 11, 26

PRINT USING "& Avg: ### Max: ### mph"; LEFT$(TIME$, 5); temp0; temp1;

IF INKEY$ <> CHR$(27) THEN GOTO 10

REM escape key hit, all done

GOSUB 5000
CLOSE #2
STOP

5000 r% = r% + 1: REM write record: average, max and s.d. this interval
avgt0 = avgt0 / nsamp
vart0 = vart0 / nsamp - avgt0 * avgt0
vart0 = SQR(ABS(vart0))
PRINT #2, USING "###.#,###.#,###.#"; avgt0; wmaxt0; vart0
CALL pbuf(t0(), avgt0, n0, n0p, n0m)
CALL pbuf(t1(), wmaxt0, n1, n1p, n1m)
nsamp = 0: avgt0 = 0: wmaxt0 = 0: vart0 = 0

REM plot data

CLS 1

' dotted gridlines
FOR i = 1 TO 600 STEP 4
PSET (i, 30): LOCATE 21, 4: PRINT "10";
PSET (i, 60): LOCATE 17, 4: PRINT "20";
PSET (i, 90): LOCATE 13, 4: PRINT "30";
NEXT i

' pull out most recent temp0 and max measurements

nsp = n0p
FOR i = n0 TO 1 STEP -1
CALL gbuf(t0(), v, nsp, n0m)
v = 3 * v: i2 = 2 * i
PSET (i2, v): PSET (i2, v + 1): PSET (i2, v - 1): PSET (i2 + 1, v): PSET (i2 - 1, v)
NEXT i

RETURN

handler:
LOCATE 3, 30
PRINT "error "; ERR; " at line "; ERL; TIME$; " "; DATE$;
LOCATE 4, 30
PRINT a$
RESUME NEXT

DEFINT K
SUB gbuf (array!(), v!, nsp%, nsmax%)
DEFINT I-N
REM NO check for buffer underflow
v = array(nsp)
nsp = nsp - 1
IF nsp < 1 THEN nsp = nsmax
END SUB

SUB pbuf (array!(), v!, ns%, nsp%, nsmax%)
DEFINT I-N

REM returns ns%, number of values pushed
array(nsp) = v
nsp = nsp + 1: ns = ns + 1
IF nsp > nsmax THEN nsp = 1
IF ns > nsmax THEN ns = nsmax
END SUB

Title: Re: Best programming language for beginners?
Post by: Robin2 on Apr 19, 2017, 09:17 am
Indentation has no computational value.
That may be true of the visual part of it. But I can't see any technical difference between starting a block of code with a TAB character or starting it with a '{' character. And it saves me having to type the closing '}' And as a side effect it makes the code easy to read

Get over it  :)

...R
Title: Re: Best programming language for beginners?
Post by: westfw on Apr 19, 2017, 09:31 am
Quote
have the editor impose [indentation] automatically.
And of course, Python editors DO that.

I was a little surprised at how little the "whitespace issue" bothered me when using python.  I mean, it's only INDENTATION that matters; other whitespace is still malleable.

(Hmm.  Look at it this way: it's not the first time when a "recommended practice" has become a "required behavior of the language."  The other main one I can think of is pre-declaring your variables (C, Pascal, PL/1...) (something that Python got rid of...))
Title: Re: Best programming language for beginners?
Post by: GoForSmoke on Apr 19, 2017, 10:36 am
(Heh.  LISP and FORTH have fine interactive interpreters as well, but I'm not going to recommend them either.  Python does pretty well as an interactive interpreter:
>>> x=3.14159
>>> print x
3.14159
>>> i = int(x)
>>> print i
3
for i in [x/6, x/4, x/3, x/2, x]:
...   print sin(i)
...
0.499999616987
0.707106312094
0.866024961519
0.999999999999
2.65358979335e-06
>>>
)


My first Basic let me use bits in integer vars. I consider learning bits early to be important foundation knowledge.
Is Python deficient in that department?

I think the real beauty of Basic for Beginners is that they can get utterly sick of it before too long and move on to better. If you start on a hilltop that's going to be harder to do.
Title: Re: Best programming language for beginners?
Post by: msssltd on Apr 19, 2017, 12:40 pm
That may be true of the visual part of it. But I can't see any technical difference between starting a block of code with a TAB character or starting it with a '{' character.
Was that some sort of pun. ;)  

I can see '{' and '}' characters but I can't see a TAB character, or any other white space or control characters.

Quote
Get over it  :)
I am over it, but from a beginners perspective, I think it is better to be encouraged to consider the purpose of adding white space to increase human readability, than be taught to slavishly please a compiler.

I bet you just loved learning tables by rote too :D


Quote
The other main one I can think of is pre-declaring your variables (C, Pascal, PL/1...) (something that Python got rid of...)
Pre-declaring variables in Pascal, teaches you how a procedure, function or unit is arranged in memory.  It makes it very easy to see where and why variables fall out of scope.  Similarly Pascal type declarations, which can seem unwieldy but you soon get your head around type equivalency.  

Not that type and scope are important computing concepts in any way :D
Title: Re: Best programming language for beginners?
Post by: Robin2 on Apr 19, 2017, 01:31 pm
I bet you just loved learning tables by rote too :D
Yeah. A nice sense of achievement :)

...R

Title: Re: Best programming language for beginners?
Post by: TomGeorge on May 06, 2017, 04:13 pm
Hi,
First computer language was psuedo-code to introduce HPBasic. (Secondary School)

The only computer you needed was your brain, the input device, eyes and blackboard , output device hardcopy pen and paper, RAM another piece of paper.


Even learnt flowcharting.


HPBasic was on cards you used a HB pencil to cross out squares to optically encode the card.
Turn around time three days, one day on the bus to the computer, one day for program run (if it did), one  day of bus to bring it back.
So mistakes wasted very valuable programming time at school.


By the way does anybody remember what   1H1 in a fortran print format statement did, especially if it was trapped in a loop?
Apart from raising the blood pressure of the Computer Centre Manager.


Tom... :)
Title: Re: Best programming language for beginners?
Post by: GoForSmoke on May 07, 2017, 03:32 am
Is that the Halt Catch Fire command?
Title: Re: Best programming language for beginners?
Post by: TomGeorge on May 07, 2017, 05:32 am
Is that the Halt Catch Fire command?
Just about.
It tells the lineprinter to go to the top of the next page.
If its trapped in a loop, you have fanfold paper cascading, in a magnificent arc, out the top of the lineprinter.
:o :o :o :o :o
Title: Re: Best programming language for beginners?
Post by: Robin2 on May 07, 2017, 03:10 pm
you have fanfold paper cascading, in a magnificent arc, out the top of the lineprinter.
Presumably so students have free paper to write their lecture notes on ?  :)

...R
Title: Re: Best programming language for beginners?
Post by: Zahran_Sajid on May 17, 2017, 06:29 pm
I would personally suggest Python. Start off with python 3 not 2, there are quite a few small differences and as python 3 is the current version under development, start with that. But like J-M-L said, learn the syntax structure and the logical flow of programming. DONT learn basic as your first language, it is outdated and lot of elements found in new programming languages are missing. Some may argue that starting with a dynamically typed language like python (basically you make up stuff as you go along,it's not as strict as a statically typed language like c,c++,java) might make you lazy but I find it a lot of fun. Python also sports a lot of libraries which simplify and make stuff easier and more fun (a particular favourite of mine is tkinter, It makes building GUI interfaces very easy, like 10 lines easy). Despite it being an interpreted language (which does have it's benefits) it's adequately fast. Besides why not try learning Python and c or c++ together. The choice is yours.