The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   OS X Developer (http://hintsforums.macworld.com/forumdisplay.php?f=27)
-   -   What program to program with? (http://hintsforums.macworld.com/showthread.php?t=101331)

coletrain 05-05-2009 10:06 PM

What program to program with?
 
This is probably a dumb question but i would rather flamed than run around in circles for days. I have been doing some research on here on what languages to learn and i'm going to find some books on Java and C programming. My question is what do i use to run and compile the programs? I have been playing with xcode but i'm not sure if it is specific to one or the other. I am running on a mac. thanks for any help.

hayne 05-05-2009 11:43 PM

You can use Xcode to compile C (and C++) programs. You can also use it to compile Java programs, but for Java programming I much prefer Eclipse.

coletrain 05-06-2009 12:16 AM

thanks! the only programming (if you can call it that) has been with matlab, So i'm relatively new to the area.

robinwmills 05-06-2009 12:32 AM

Hi Coletrain

Don't worry about being flamed on this forum. Everybody's well behaved here and will help you willingly. And I agree with Dr Hayne about Eclipse and XCode.

Robin

Mikey-San 05-06-2009 12:34 AM

Quote:

Originally Posted by robinwmills (Post 531598)
Don't worry about being flamed on this forum.

Unless you use PHP or Java.

oh i went there

coletrain 05-06-2009 12:32 PM

I guess i'm use to my off road forum where everyone seems to get less patient everyday :rolleyes:. I will still use the search button cause i know how it can be when the same question gets answered all the time

Quote:

Originally Posted by Mikey-San (Post 531599)
Unless you use PHP or Java.

oh i went there

I might be running into the fire on this one :D

cwtnospam 05-06-2009 12:59 PM

I like php. It's easy, yet powerful, and it's cross platform so something I write for a Mac server will run on a Linux server, or some other platform.

Mikey-San 05-06-2009 01:49 PM

Quote:

Originally Posted by cwtnospam (Post 531704)
I like php. It's easy, yet powerful, and it's cross platform so something I write for a Mac server will run on a Linux server, or some other platform.

PHP is terrible and anyone who prefers it has never used better languages.

cwtnospam 05-06-2009 02:08 PM

I'm not saying php doesn't have limitations, but at least some of its problems rise from that fact that lots of newbies code in it. Many of them have never heard of OOP, and their code shows it clearly.

Mikey-San 05-06-2009 02:34 PM

Quote:

Originally Posted by cwtnospam (Post 531714)
I'm not saying php doesn't have limitations, but at least some of its problems rise from that fact that lots of newbies code in it. Many of them have never heard of OOP, and their code shows it clearly.

You have not read any of the links I just posted.

cwtnospam 05-06-2009 02:38 PM

Yes, I have. I think that complaining about how php coerces type shows a bit of bias, and putting an image of training wheels up shows that the derision is aimed more at the people who use the language than the language itself.

Edit: This is understandable. Newbies often want to be spoon fed, and it can be annoying.

Mikey-San 05-06-2009 04:15 PM

Blaming "newbies" for the problems with the language means you either didn't read the articles or don't understand them.

All languages have newbies. Not all languages are awful. PHP happens to qualify for both.

cwtnospam 05-06-2009 04:21 PM

Sigh. I'm not blaming newbies for problems with the language. I'm blaming elitist programmers for nitpicking* the language because it gets used by so many newbies. I believe that if there were no php, then some other language — maybe Perl or Ruby —would end up with the lion's share of newbies and hence derision by 'real' programmers.

* ie, Complaints about underscores, and the use or nonuse of 'i' for case sensitivity.

Mikey-San 05-06-2009 04:27 PM

Well, there are four articles (that might not have been visually apparent, sorry) in my post that outline, quite explicitly, why PHP is a terrible abortion of a language. Everything from the Alzheimer's-inducing standard library to its broken Unicode support to WTF which string escaping do I need for this situation oh god just kill me now this is ridiculous. Documentation? Terrible, too.

And if you really think PHP is "portable", enjoy this one:

http://www.mysqlperformanceblog.com/...d-portability/

cwtnospam 05-06-2009 04:42 PM

Quote:

Originally Posted by Mikey-San (Post 531728)
Well, there are four articles

Yes, and I saw them, but I didn't think it necessary to critique them all.

Here's a few denigrating other languages:
http://pythonguy.wordpress.com/2008/...ks-perl-sucks/
http://rs79.vrx.net/opinions/computers/languages/PerlC/
http://www.onlamp.com/pub/a/onlamp/2...hilosophy.html
http://advice.cio.com/esther_schindl...ds_why_c_sucks

I'm not saying anything about any of these opinions. My only purpose in posting them is to show that no language is perfect. All have their detractors, and the one with the most newbies will inevitably have the most detractors.

In any case, I think we can all agree that it isn't the weapon that matters. It's the person using it that counts. If you think a class is something you go to, it doesn't matter what language you're using.

Mikey-San 05-06-2009 04:55 PM

A good carpenter can't make a crappy hammer screw bolts any better that it's capable of.

tw 05-06-2009 05:06 PM

Quote:

Originally Posted by robinwmills (Post 531598)
Don't worry about being flamed on this forum. Everybody's well behaved here and will help you willingly.

mostly.

just clarifying. ;)

mvmn 05-07-2009 04:08 PM

Quote:

Originally Posted by Mikey-San (Post 531710)

Nice selection of articles of PHP critics. My 50 cents - http://mvmn.wordpress.com/2009/02/08...s-abomination/

cwtnospam 05-07-2009 08:30 PM

Since we're talking about language quirks, I'd say that any language that uses "void()" is a little strange. Sure, I'm nit picking, but let's face it: this site, as well as the Wordpress site and many others, is done in php, and they don't suffer because of the language. Are there problems with the language? Sure, but what language doesn't have issues?

benwiggy 05-08-2009 06:13 AM

Quote:

Originally Posted by Mikey-San (Post 531734)
A good carpenter can't make a crappy hammer screw bolts any better that it's capable of.

But doesn't a bad workman blame his tools...? :p

acme.mail.order 05-08-2009 09:54 AM

Quote:

Originally Posted by Mikey-San (Post 531710)

Those pages were written prior to 2006*. Got anything recent?

* PHPv3 did indeed suck by current standards, but it did what it was designed to do. V4 was like a teenager learning to drive.

Lots of functions are not a bad thing and minor inconsistencies like hyphens and underscores in function names are typical of community-developed anything.

cwtnospam 05-08-2009 10:09 AM

Quote:

Originally Posted by acme.mail.order (Post 532055)
... and minor inconsistencies like hyphens and underscores in function names are typical of community-developed anything.

Yes, and to add to that, what's wrong with a little variety? Does everything have to be homogenized? Do we all have to live in tract housing? Honestly, I couldn't give a rats butt that some function use underscores and some don't.

tw 05-08-2009 10:21 AM

Quote:

Originally Posted by cwtnospam (Post 532060)
Yes, and to add to that, what's wrong with a little variety? Does everything have to be homogenized? Do we all have to live in tract housing? Honestly, I couldn't give a rats butt that some function use underscores and some don't.

oh, this is just the old 'Esperanto' debate applied to computer languages. sure, southern European languages are a mess of corruptions of Latin, with idiosyncratic usages and forms, strange illogical aberrations, odd pronunciations, and the like. Esperanto is a nice, neat, clean, organized, logical, well-designed substitute that's much more efficient to use and easy for everyone to learn. Esperanto is better than French, Italian, Spanish, and etc in every way possible except that no one uses it.

PHP is perfectly fine once you get used to its oddities, and in some ways its easier to use than a more sophisticated language like Ruby or Perl (both of which are brilliant at making clean, concise code, but which require a lot more mental effort to create or understand).

cwtnospam 05-08-2009 10:48 AM

Quote:

Originally Posted by tw (Post 532067)
oh, this is just the old 'Esperanto' debate applied to computer languages.

Which is why I'm a little surprised that it goes on with such ferocity. They're just languages! None of them do exactly what I want, when I want it. They all require me to do things their way when I want to do them mine!
Quote:

Originally Posted by tw (Post 532067)
PHP is perfectly fine once you get used to its oddities, and in some ways its easier to use than a more sophisticated language like Ruby or Perl (both of which are brilliant at making clean, concise code, but which require a lot more mental effort to create or understand).

Here's a Ruby snippet I took from another site:
Code:

class Stuff
  def evaluate(coefficient, x)
    degree = coefficient.length - 1
    value = 0
    coefficient.each { |c|
      value += (c * x**degree)
      degree = degree - 1
    }
    return value
  end
end

and it's php equivalent (not tested, so I've probably made a mistake or two):
PHP Code:

class Stuff {
 function 
evaluate($coefficient$x) {
    
$degree count($coefficient) - 1;
    
$value 0;
    foreach(
$coefficient as $c) { 
      
$value += $c $x^$degree
      
$degree--; 
    }
    return 
$value;
  }


I think it's the similarity that irks purists more than the differences, although I'm sure the differences act as speed bumps when moving from one to the other.

tw 05-08-2009 11:26 AM

Quote:

Originally Posted by cwtnospam (Post 532075)
I think it's the similarity that irks purists more than the differences, although I'm sure the differences act as speed bumps when moving from one to the other.

That's a peculiarity of human nature. Big differences are just differences, because there's no meaningful comparison; small differences have a meaningful comparison, and so they have to be right or wrong, which makes people argumentative. Christians have never had more than passing difficulties with Buddhism or Hinduism as faiths, but have slaughtered other Christians in droves over minor doctrinal issues. Human=Weird. :)

sorry, that should be Human==Weird. logical equivalence, not assignment... :D

cwtnospam 05-08-2009 11:39 AM

Quote:

Originally Posted by tw (Post 532078)
sorry, that should be Human==Weird. logical equivalence, not assignment... :D

Minor/big problem: :D
Human === Weird
Logical equivalence, both value AND type. :p

ganbustein 05-08-2009 06:41 PM

Quote:

Originally Posted by cwtnospam (Post 532075)
Here's a Ruby snippet I took from another site:
...
and it's php equivalent (not tested, so I've probably made a mistake or two):

Well, OK, if you write a program in C, and then massage the syntax as little as possible to shoehorn it into two other languages, both translations are still going to look pretty much like the C version, and therefore like each other.

For the Ruby version, how about:
Code:

class Stuff
    def evaluate(coefficient,x)
        coefficient.inject(0) {|v,c| v*x+c}
    end
end

That's not only more in keeping with the style of Ruby, it's also more efficient and (with experience) more readable. In the C-style version, your mind is being distracted by having to figure out the significance of all those extraneous variables (degree, value) and making sure they're initialized correctly. (degree = coefficient.length - 1? Why -1? My OBOB detector goes off on that line, and I have to take a mental side trip to satisfy myself that it's correct. And x**degree? Why is there an exponentiation operator in this at all? You can evaluate a polynomial using only add and multiply.)

tw 05-08-2009 07:13 PM

well, the PHP version could be reduced to
PHP Code:

class Stuff {
    function 
evaluate($coefficient$x) {
        for (
$i=0$i<sizeof$coefficient ); $i++) {
            
$value += $coefficient[$i] * $x^$i
        }
        return 
$value;
    }


and this is pretty much what I meant: the Ruby version is way cooler (from the code-geek perspective), but you can understand the PHP version without a magic wand and decoder ring. :eek:

cwtnospam 05-08-2009 07:55 PM

Quote:

Originally Posted by ganbustein (Post 532145)
Well, OK, if you write a program in C, and then massage the syntax as little as possible to shoehorn it into two other languages, both translations are still going to look pretty much like the C version, and therefore like each other.

It wasn't my intention to optimize anything, but it seems to me the "optimized" versions look like each other too. ;)

acme.mail.order 05-09-2009 06:33 AM

Quote:

Originally Posted by cwtnospam (Post 532060)
... Honestly, I couldn't give a rats butt that some function use underscores and some don't.

Actually I do find this annoying - have to keep checking the references for the proper syntax. And there's the odd haystack/needle vs. needle/haystack order issues.

But it's not bad enough to make me want to learn Perl :rolleyes:

ganbustein 05-09-2009 08:11 AM

Quote:

Originally Posted by cwtnospam (Post 532154)
It wasn't my intention to optimize anything, but it seems to me the "optimized" versions look like each other too. ;)

It's not a matter of optimization, so much as reducing the mental load. The "optimized" PHP introduces an extraneous loop variable (i) and a bug (it applies the coefficients in the wrong order). It still uses exponentiation instead of multiplication, but that's merely optimization. It also still looks like C, which I guess makes it "more readable" if you already know C (and of course everyone should), but you can hardly hold up C's bizarre for loop construct as a paragon of clarity to anyone who doesn't already sport that decoder ring.

You're also using indexing in the PHP version (as you did in the C version), so the coefficients have to be an array. The Ruby version only requires the coefficients to be enumerable. (In C++ terminology, you're requiring a random access iterator where an input iterator would have sufficed.)

This example is so tiny that it's hard to appreciate the significance of these distinctions. The thing is, the C/PHP version is constructed from smaller mental "chunks" than the Ruby version, so you need more of them. That means it takes more mental effort when reading the program to figure out what it does.

It's like the difference between a 1000-piece jigsaw puzzle and a 500-piece jigsaw puzzle. The number of pieces makes a huge difference in the time it takes to assemble the puzzle.

tw 05-09-2009 08:37 AM

Quote:

Originally Posted by ganbustein (Post 532202)
the C/PHP version is constructed from smaller mental "chunks" than the Ruby version, so you need more of them. That means it takes more mental effort when reading the program to figure out what it does.

that's backwards, I think. the Ruby version may have fewer conceptual chunks, but the chunks it uses are more complex and abstract, and so more difficult to work with. when it comes right down to it, the logical task is the same in both cases; what differs is the shorthand we use for writing that task down. it's like different compression formats for an image. bitmaps take up more space but are very easy to process computationally. jpegs take up less space, but need more computational power to decode. same picture though.

cwtnospam 05-09-2009 09:45 AM

Or in other words: yes, you can evaluate a polynomial with only addition/multiplication, but exponents are faster, even if the code looks slicker without them.

tw 05-09-2009 03:46 PM

Quote:

Originally Posted by acme.mail.order (Post 532198)
But it's not bad enough to make me want to learn Perl :rolleyes:

Ugh, Perl... if the world was about to be destroyed by a giant bomb and I had to learn Perl to disable the computerized fuse, I'm not at all certain it would be worth it. :D

acme.mail.order 05-09-2009 08:37 PM

On the positive side the giant perl-coded bomb would destroy perl too.

cwtnospam 05-09-2009 09:20 PM

Quote:

Originally Posted by tw (Post 532244)
Ugh, Perl...

But is it the language, or the people who code in it? There seem to be two types of programmers: those who look for the best way to obfuscate their code, and those who plan on being able to make changes in the future. Maybe Perl attracts more of the former.

tw 05-09-2009 10:03 PM

Quote:

Originally Posted by cwtnospam (Post 532267)
But is it the language, or the people who code in it? There seem to be two types of programmers: those who look for the best way to obfuscate their code, and those who plan on being able to make changes in the future. Maybe Perl attracts more of the former.

so what you're saying is that it's like throwing Perl before swines? :p

cwtnospam 05-09-2009 11:06 PM

I was trying not to. :D

In the interest of accuracy, I need to correct myself and point out that php doesn't do exponents as:

$a^$b

It does them this way:

pow($a,$b);

One more thing for its detractors to gripe about. :eek:

ganbustein 05-10-2009 04:31 AM

Quote:

Originally Posted by tw (Post 532208)
that's backwards, I think. the Ruby version may have fewer conceptual chunks, but the chunks it uses are more complex and abstract

Not at all. The ruby code uses only one conceptual chunk: if you have a sequence of values, you can form an expression by "injecting" a binary operator between them.

If you have the sequence a, b, c, d,

you can form the sum by injecting addition: a + b + c + d
you can form the product by injecting multiplication: a * b * c * d
you can form the longitudinal checksum by injecting xor: a ^ b ^ c ^ d
or in general, inject an arbitrary binary operator op to get a op b op c op d

In each case, these operators associate left-to-right, so the expressions are really evaluated as
(((a + b) + c) + d)
(((a * b) * c) * d)
(((a | b) | c) | d)
(((a op b) op c) op d)


All you have to do in ruby is tell it which binary operation to inject.
The polynomial ax^3+bx^2+cx+d can be more efficiently written as
(((ax + b)x + c)x + d)
which we get by injecting the operator op defined by v op c == v*x+c.

And that's exactly how it's written in ruby:
coefficients.inject {|v,c| v*x+c}

or in words "given the sequence of coefficients, inject the operator which, on arguments v and c, computes v*x+c. Return the value of that expression."

Notice that there's no need to create a loop. We're just building an expression. (Sure, there's a loop going on under the hood, but we don't need to think about that, any more than we need to think about all the dictionary lookups and memory management and subroutine calls that are also going on under the hood, in both languages.)

Since we don't introduce a loop, we don't need to grok C's baroque for loop syntax, nor do we need to introduce the auxiliary variable $i whose sole purpose is to keep track of our progress through the loop. No need to count how many coefficients there are. No need to treat the coefficients as an indexable array (as in the expression $coefficient[$i]).

In ruby, it's just a sequence, and we're just injecting an operator into it to form an expression. One simple (albeit powerful) concept.

Well, OK, two concepts. We're using the fact that lambda expressions are easy to write and easy to use. In ruby they're called blocks; {|v,c| v*x+c} is an example of one. You don't write much ruby without using lots of blocks.

Oh, and BTW, multiplication is a LOT faster than exponentiation.

cwtnospam 05-10-2009 09:19 AM

Sure, one multiplication is faster than exponentiation, but that's not what you have:

a0 + a1x + a2x^2 + a3x^3 + ... + anx^n

can be written in your (((ax + b)x + c)x + d) form, but only by using a loop, which is exactly what inject does. The result is many multiplications and many additions. Remember, we don't know how many items exist in the array: coefficient.

tw 05-10-2009 10:47 AM

Quote:

Originally Posted by ganbustein (Post 532294)
Not at all. The ruby code uses only one conceptual chunk...

yes, one conceptual chunk that it took you almost a page of text to explain. I knew a physics proff who used to say that the unified field theorem was maybe the simplest equation in physics: you can write it symbolically in maybe 7 characters. however, you need about 15 years of study and research to really understand what those 7 characters are saying. experts always think that what they are doing is easy, but you can't really neglect mental effort that way.

ganbustein 05-10-2009 06:35 PM

Quote:

Originally Posted by cwtnospam (Post 532307)
Sure, one multiplication is faster than exponentiation, but that's not what you have:

a0 + a1x + a2x^2 + a3x^3 + ... + anx^n

can be written in your (((ax + b)x + c)x + d) form, but only by using a loop, which is exactly what inject does. The result is many multiplications and many additions. Remember, we don't know how many items exist in the array: coefficient.

I don't see any loops.

Let me repeat that. I don't see any loops.

I am always cognizant of what's "really happening" under the hood. I know that in executing the program there's a lot happening down under. Symbols are being looked up in dictionaries. Memory is being allocated to hold values. Method dispatch tables are being consulted to locate the correct code to execute next. And yes, there are some loops down there, too.

But I don't need to look at any of that to understand what the program does. The code I look at and have to understand doesn't have any loops in it.


ax^3 + bx^2 + cx^1 + dx^0 takes 4 exponentiations, 4 multiplications, and 3 additions.

(((ax + b)x + c)x + d) takes 3 multiplications and 3 additions.


But we're drifting away from the point I wanted to make. The PHP version could easily be rewritten to evaluate the polynomial using multiply-add. Any competent programmer would do that as a matter of course. Let's consider it done and move on.

My main point was this: if you're comparing two languages by looking at sample code to perform a given task, write each sample the way a reasonably competent user of that language would have written it.

It's pointless to write the program in yet a third language (C in this case) and then translate that clumsily into the languages being compared. That doesn't give you a useful comparison. Besides the obvious perils of non-idiomatic translation, it rules out beforehand any features of the target languages that aren't present in the source language.

In this case, Ruby has a slew of operators that operate on entire sequences (of which arrays are only one flavor) as fundamental objects. While you can loop across the elements of a sequence, it is much more common in Ruby to operate on entire sequences with a single operation.

To someone not used to this, operations like inject, collect, reverse, sort, detect, any?, all?, and grep may seem exotic, but they're the bread and butter of Ruby programming.

A Ruby programmer would no sooner replace any of these with an explicit loop than would a C programmer replace for(...) with the equivalent if() and goto statements. You could do it, but why? It takes more code to write, and it's harder to read, as well as being more error-prone.

If you try to explain that "for" is easier to understand than "if/goto", and they reply "But 'for' just uses 'if/goto' under the hood, so they're still there," you know they're just not getting it. This fancy-schmancy "for" construct isn't just some exotic hard-to-understand thing you're doing to show off. It really does make the program easier to read and easier to get right. All it takes is the initial effort to learn what "for" does.

Likewise when you explain that we have all these operators that work on entire sequences so you don't have to write out the explicit loops, and they say "But 'inject', 'collect', 'grep' et al. really do still run loops underneath," you know they're still not getting it. These aren't fancy-schmancy constructs that get thrown in just to show off. They really do make the program easier to read and easier to get right. All it takes is the initial effort to acquaint yourself with them.

I feel that I'm being sucked into acting like a Ruby fanboy here. I do kinda like some features of Ruby, but it's not my favorite language. (Trying to debug Rails code cured me of that.) I just thought this particular example was maligning it unfairly.

tw 05-10-2009 06:49 PM

who's maligning anything? everybody chill a bit. all code gets executed in machine language - everything higher level is just a metaphor. what metaphor you use depends on what you know, what you're trying to do, and how your brain works. beyond that... whatever.


All times are GMT -5. The time now is 05:34 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.