Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dubhe

macrumors 65816
Original poster
May 1, 2007
1,304
10
Norwich, UK
I want to get in to simple programming, I used to do a reasonable amount of BASIC on my old casio 'computer' calculator but those days are long gone.

The kind of programming I want to do is either mathematical for my job, ie I am a Navigator at sea and want to be able to quickly solve spherical trigonometry by entering latitude, longitude, time and declination to give me a calculated bearing of a star. There are commercial programs that do this, but that is on a PC and they are too user friendly and therefore take too long.

The other type would be for personnel interest, I might want to make a program to email me the contents of webpages when I am away at sea. I know I can do this with 'automator' but I would like to be able to play with it more.

As I have said, I am new to programming but feel it is something I could eventually get in to in a serious way, where do you guys recommend I start?

If you could advise firstly which language to use: applescript?
And secondly which books I can buy to get me started!
 

cmaier

Suspended
Jul 25, 2007
25,405
33,474
California
Hmm. I'd almost recommend just learning perl (or python or ruby or some other script language) based on your stated requirements. If you don't need your code to perform GUI operations, that's probably the way to go.
 

yeroen

macrumors 6502a
Mar 8, 2007
944
2
Cambridge, MA
Fortran, though you'll have to install the g95 or g77 fortran compiler since it's not included with Apple's version of gcc.
 

dubhe

macrumors 65816
Original poster
May 1, 2007
1,304
10
Norwich, UK
i've been playing with applescript all afternoon, seems to be reasonable. Are you guys against it? Does it have limitations (for my intended use)?
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
The two tasks you describe are very different. I would not try to do complex math with applescript, even if it is possible. yeroen's suggestion of fortran is a pretty good one. g95 would be the way to go, there's no reason to use Fortran 77 anymore (unless the machine you are working on is not capable of using modern compilers, but I digress).

The web page question might be a more difficult one. if you just want the text of the page and don't care about images, css, and other resources, you could script this pretty easily with shell using the curl command. If you want to pull down all images, CSS, flash content, etc. that's going to be more of a challenge. I would start with applescript for that one, and look at safari's dictionary to see if you can automate the way it saves "complete" webpages, images and all. you could then tar and gzip the directory or just create a disk image (i believe disk utility has an applescript dictionary) of the folder safari saved, and email that.

Good luck, post code as you progress if you need help.

-Lee
 

lazydog

macrumors 6502a
Sep 3, 2005
709
6
Cramlington, UK
I want to get in to simple programming, I used to do a reasonable amount of BASIC on my old casio 'computer' calculator but those days are long gone.

Since you mention you have some experience of programming in Basic you might like to look at RealBasic. I think you can download an evaluation copy from RealSoftware's website. It's not the best language or development environment by far but it might suite your needs. At any rate, it will let you knock up a simple interface to your program and it supports double precision which I guess will be adequate.

FORTRAN is okay if you want to write tools that are heavy on the numeric side, but for general application development I don't think it will be too useful for you (I'm assuming you want to develop on your Mac!).

b e n
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
Since you mention you have some experience of programming in Basic you might like to look at RealBasic. I think you can download an evaluation copy from RealSoftware's website. It's not the best language or development environment by far but it might suite your needs. At any rate, it will let you knock up a simple interface to your program and it supports double precision which I guess will be adequate.

FORTRAN is okay if you want to write tools that are heavy on the numeric side, but for general application development I don't think it will be too useful for you (I'm assuming you want to develop on your Mac!).

b e n

I can't comment on RealBasic from personal, but I've heard it widely panned which never seems like a good thing.

I would say that for anything with a nice GUI on OSX you need to use objective-C. One way around this would be to write the "backend" in fortran, and the "frontend" in applescript. The applescript could gather the variables graphically, validate them, etc. then pass them to the fortran program. I'm not sure about applescript grabbing the results of the fortran run, but if you had the fortran program output to a file, the applescript could open the file and display the contents.

There's no problem developing fortran on the mac, and aside from the obvious lack of GUI bindings (which you might actually be able to get around as you can invoke C methods from fortran and vice-versa) i don't see a real downside to using it, especially for math-heavy development.

-Lee
 

yeroen

macrumors 6502a
Mar 8, 2007
944
2
Cambridge, MA
The subtleties of passing data back and forth between Fortran and C are likely to confound and overwhelm the inexperienced user.

Maybe it's just better to use GNU Octave.
 

dubhe

macrumors 65816
Original poster
May 1, 2007
1,304
10
Norwich, UK
(I'm assuming you want to develop on your Mac!)

Yes!

The subtleties of passing data back and forth between Fortran and C are likely to confound and overwhelm the inexperienced user.

I am an intelligent guy and have the patience to learn a new way of doing things. But consider that my BASIC programs could pretty much do what I needed maths-wise. As long as I can do spherical trigonometry, which is basically sine, cosine, tan, cotan etc then that will do. But, I want pretty boxes to come up and ask me for the inputs. So, maybe using applescript for at least part of this is a good idea.

However, another way of doing my maths is to use certain rules, easy to work out with a pen and paper but getting program to do it could be harder. For example, if latitude and declination are in the same hemisphere you add the result of two equations, if they are different you subtract.

I can do it in Basic in about 50 lines of code, but I want to start afresh (and I can't find Basic anymore!)
 

lazydog

macrumors 6502a
Sep 3, 2005
709
6
Cramlington, UK
I can't comment on RealBasic from personal, but I've heard it widely panned which never seems like a good thing.

I would say that for anything with a nice GUI on OSX you need to use objective-C. One way around this would be to write the "backend" in fortran, and the "frontend" in applescript. The applescript could gather the variables graphically, validate them, etc. then pass them to the fortran program. I'm not sure about applescript grabbing the results of the fortran run, but if you had the fortran program output to a file, the applescript could open the file and display the contents.

There's no problem developing fortran on the mac, and aside from the obvious lack of GUI bindings (which you might actually be able to get around as you can invoke C methods from fortran and vice-versa) i don't see a real downside to using it, especially for math-heavy development.

-Lee

Yes you're right… it does get a panning, but for a lot of people it fits their needs very well and they are happy bunnies. I honestly wouldn't have recommended looking at RB if I thought it was as bad as you make it out to be:) or if it couldn't handle the maths.

b e n

I am an intelligent guy and have the patience to learn a new way of doing things. But consider that my BASIC programs could pretty much do what I needed maths-wise. As long as I can do spherical trigonometry, which is basically sine, cosine, tan, cotan etc then that will do. But, I want pretty boxes to come up and ask me for the inputs. So, maybe using applescript for at least part of this is a good idea.

I'm certain that RealBasic will do all you want… even HTML and JavaScript would do!

b e n
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
As I stated, I haven't used RealBasic so I have no idea of its quality, just passing on what I've heard. It may be very suitable for this problem, I just didn't know if this was the only problem dubhe would ever need to solve. If not, it might be better to pick something that's better liked for no other reason than ease of getting help. There may be a very active, friendly RealBasic community that I am unaware of, and if so, that mitigates the issue entirely.

A lot of suggestions have been thrown out there. it seems like the current focus is on the nautical app mentioned and not the web page archiving/mailing, so I'll summarize what we've come up with:

FORTRAN backend / Some other frontend (AppleScript, Bridge to Obj-C, etc.): The math should be easy in fortran, but a shiny frontend would be the tougher part.

AppleScript only: might not be the best for complex computations, as it appears there are not trig functions built-in: http://lists.apple.com/archives/Applescript-users/2004/Feb/msg00941.html

HTML/Javascript: This definitely would make the input and output easier. This has an advantage over AppleScript in that it appears there are trig functions available in javascript: http://www.w3schools.com/jsref/jsref_obj_math.asp

RealBasic: Certainly capable it seems, and apparently makes adding a frontend much easier.

GNU Octave: The only time I've used octave was to simulate a math-heavy load on x86 under linux for a project that required us to propose hardware modifications to improve performance of mathmatical software. As such I don't know what's its capabilities are in terms of providing a frontend, but due to the nature of the software I'm sure the math part would be trivial. http://www.gnu.org/software/octave/

Any further conversation (and we're probably past this point already =) ) would be academic. Pick your poison and start coding. I'm sure people here will be glad to help with whichever you go with. HTML/Javascript would probably be better suited to the web development forum than this one, and Octave might be outside of the expertise of many here, but I'm sure a few people could provide some pointers if you needed them.

-Lee
 

dubhe

macrumors 65816
Original poster
May 1, 2007
1,304
10
Norwich, UK
Thanks for the input everyone, I've got to return to the real world now as the wife is back from work :D but I'll be on it again in the morning!
 

ChrisA

macrumors G5
Jan 5, 2006
12,917
2,169
Redondo Beach, California
i've been playing with applescript all afternoon, seems to be reasonable. Are you guys against it? Does it have limitations (for my intended use)?

Shperical trig with Apple script? No.

The way you write stuff like that today is to find a good math library that has the functions you need and then write a bit of code to get the numbers and string together the function calls.

You will never be able to beat the guys who wrote the libraries. For example I couldfind the great circle distance between to points on a sphere. It is not quite rocket science. But I'd be hard pressed to find the distance on an arbitrary elipsiod and even harder pressed to prove my code worked in all cases. So we depend on the work of others. That is how software is built. back to programming languages. You'd pick the language based on if it can talk to the shpereical trig library you happen to like and if it can talk to the overall environment that it has to run it. In this case one of the C varients will likely be the way to go.

As for e-mailing web sites. Very different problem but you pick the language the same way. Choose an infrastructure that works well for grabbing pages and sending emails and so on. Likely it will turn out to by Perl, shell script o one of the newer interpeted languages. I would not want to do this job in C. I'd looks at Perl, Python Ruby or maybe Apple script. or automator
 

PlugNPray95

macrumors newbie
Apr 9, 2008
3
0
Thanks for the input everyone, I've got to return to the real world now as the wife is back from work :D but I'll be on it again in the morning!

I havent seen it mentioned above... What about Microsoft Excel, at least for the mathematical computations.
 

dubhe

macrumors 65816
Original poster
May 1, 2007
1,304
10
Norwich, UK
I havent seen it mentioned above... What about Microsoft Excel, at least for the mathematical computations.

I have done some of the simpler ones in Excel but again it proves difficult when it comes to rules. Perhaps I need to perceiver with it, or Numbers as I now use.

I don't really need to be doing any of this, I just fancy broadening my programming skills! So really I would like to do the programs I mentioned as a reason to get in to it. But I want to be learning something I can use in the future for whatever programming requirements I need/make up.
 

lazydog

macrumors 6502a
Sep 3, 2005
709
6
Cramlington, UK
The suggestion for using html and JavaScript was a real one on my part. You could actually make a pretty good looking application with that combination and even turn it into a Widget.

To get started all you need is TextEdit and Safari. A few hours reading an introduction to programming in JavaScript and HTML and you'd be ready to get started I'm sure.

Good luck with which ever route you choose… and have fun!

b e n
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
Of the list I made above, html and javascript does seem the best. The UI part is very easy, and javascript seems up to the mathematical task. You shouldn't have to get too muddied up with the object-oriented aspects of JS for the scope of this issue, nor wrestle much with the DOM.

The reasons for going another route would be that one of them sounds more interesting or will be more applicable to you in the long term.

-Lee
 

Denarius

macrumors 6502a
Feb 5, 2008
690
0
Gironde, France
I'm a fairly novice programmer myself, mostly php dynamic web applications, but I've been looking at languages myself and have begun to learn Ruby: I reckon it's got tonnes of things going for it other than the sheer elegance of the language. it comes as standard in os x (from 10.4 onwards I believe) and there's also the rather attractive feature of the rubycocoa bridge, which means you can use it for full on applications as well. There's also an apple events bridge, which means it can be used as an alternative to applescript.

To me it looks like the ultimate one-stop shop for os x. That said, I'm not an expert and other more experienced programmers may disagree. I'm certainly enjoying what I'm doing with it at the mo though! :)

Something I forgot to mention was that it has very good standard xml reading/writing support which could be useful if the websites you want to email to yourself have rss feeds.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.