The Artima Developer Community
Sponsored Link

C++ Community News Forum
The Problem with Programming

212 replies on 15 pages. Most recent reply: Dec 8, 2006 6:12 AM by James Watson

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 212 replies on 15 pages [ « | 1 ... 12 13 14 15 ]
James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: "No sliver bullet" is in the fine print Posted: Dec 7, 2006 3:03 PM
Reply to this message Reply
Advertisement
Firstly, I want to apologize for being a little less than civil in this thread. I think the technical term for this is being 'kind of a dick'.

I mean, you did piss me off a little but it's been a bad week and my mood tends to 'leak' into threads like this sometimes.

> It's very hard, if not impossible to do in the general
> case for a general purpose language. Any useful features
> need to be (or maybe more correctly should be) applicable
> to a wide range of problems.

I'm wondering if we may not be thinking about the same things here. I guess where I'm coming from is that I'm not against the high-capabilities of C++ (although I think some things could be disallowed but I'll address that later) but more that there are so many ways to accomplish the same thing. What I've been trying to say (badly) is that a language with the power of C++ but with a little spring-cleaning would be better. Maybe D fits this description. I'll try to get a chance to look at it.

Here's an example of something I don't like in C++: pointer arithmetic. It's not allowed in Java and most high-level languages. I'm sure there are cases where using it can optimize operations. But it seems to me that the compiler or runtime should be able to use this approach and much more safely. In Java 1.5, they introduced a for each type construct:

for (int i : intArray) {
    // do something with i
}


It seems to me that the compiler or runtime can optimize this really well. Say it knows that the data will be contiguous. It can essentially use pointer arithmetic and potentially even drop the bounds checking (assuming the spec allows for this which I'm not sure it does.) In this way, we get our cake an eat it too. You get the raw speed without the pitfalls.

Another example is not currently in Java but is described here: http://www.research.ibm.com/people/g/gupta/escape.ps

With this runtime optimization, stack allocation, thread local allocation can be used, and synchronization dropped depending on the situation during execution. And this can be done with libraries which were written without knowing whether these optimizations would be OK. These are probably not new ideas but the are good ones all the same.

> > > Ok. Abstractions leak all the time. Because of that I
> > have
> > > specific needs from time to time to get closer to the
> > > metal than these abstractions allow. Taking that
> > ability
> > > away from me impairs my ability to solve problems.
> >
> > Perhaps. Perhaps you just haven't realized there is a
> > much better approach. A lot of the times that I've
> seen
> > people drop down to the metal to solve issues, there was
> a
> > better (faster, less memory, more flexible) solution
> > achieved by adding an abstraction.
>
> I don't disagree with that at all. Unfortunately 'A lot'
> doesn't cover 'All'.

Yes and I think that there needs to be a way to address those things. Python and Java both address this, although binding to native code in Java is a big pain (one of the bad things about Java.)

> You're not a big fan of templates, so
> you'll probably hate this, but here is an optimization
> that I like a lot, not only because it also doesn't look
> any nastier than regular ol' C++. You get brutally
> efficient optimization that doesn't look any different
> than the normal language syntax and this is better than
> you can do in a lower level language like C to boot. So
> maybe this supports your argument more than mine?
> http://www.cantrip.org/emptyopt.html

This seems like something that would be the job of a runtime or a compiler. There's some mention in that page of why the compiler can't in C++. In Java, I don't think the JIT can do that, but will unroll loops and I believe remove them if they are filled with no-ops, which is sort of a similar idea.

> > > How so? I'll assume with your quick response you
> didn't
> > > get through the entire paper. Lisp was create
> > specifically
> > > as a notation to express functions, which is how we
> > > express processes for a computer. Seems completely
> > logical
> > > to me.
> >
> > I'm fairly familiar with the idea of LISP. Just because
> I
> > think the idea was good doesn't mean I like that
> > particular execution of it. You're not arguing that
> this
> > idea leads only LISP, are you?
> >
>
> I'm not arguing that anything leads invariably to LISP. At
> least, not its syntax, which what I'll assume you mean by
> "that particular execution". But the ideas aren't new and
> the languages that I hear people talk about (python and
> ruby, mostly) that are going down the path you describe
> credit at least some of their design to LISP. Invariably
> overstates the case, but there sure is a high
> correlation.

I don't even know what we were arguing about. I think that the functional paradigm is a great idea but that LISP is that idea taken to an absurd conclusion. This is just my opinion, obviously. I don't think LISP's failure to become a dominate language is because this idea was a bad one, it's just that LISP seems strange and requires twisted reasoning for most developers. Languages that combine the functional and OO paradigms have the most promise, I think.

> > Give me an an example of the kind of thing you are
> talking
> > about that you do on a regular basis. Maybe you'll
> > convince me.
>
> I used to help work on a database application that was
> responsible at times for rolling up 10's to 100's of
> gigabytes of financial data from leaf level data entry
> nodes to summary levels for executives. Given the constant
> changes to financial rules across the globe (the software
> is sold worldwide), there are constant tweaks to the
> rollup process. Given the large amounts of data that are
> processed we need all the control we can get when running
> this process. The object models and runtimes of more
> modern languages bring this process to a grinding halt. In
> order to handle this amount of data there are "tricks" all
> over the place to conserve memory and shave CPU cycles.
> For small consolidations that take seconds or minutes,
> this isn't a big deal. Some of the tweaks, however, were
> put in place to cut consolidations down from days to hours
> or, in the best cases, minutes. Performance is a huge deal
> for this app because nobody wants to start rolling up
> their database Friday, leave for the weekend and have
> maybe a 50/50 shot that it will be done when they come in
> Monday morning.
>
> It has to run and it has to run in a reasonable amount of
> time and given the need to properly apply the financial
> rules (order of calculations matter, relationships of
> certain members in the database change the calculations
> depending on financial rules covering partially and wholly
> owned subsidiaries based on country, etc.) you don't have
> a lot of wiggle room with the algorithms. You have some
> but not much because the numbers have to be right. The
> only practical alternative is to make the computations
> take less time.

OK this is a good example. This may not have applied at the time you were working on this, but could parallel processing helped here or is the process necessarily sequential? It's ball is just getting rolling on this, but with the 16 core chips that are coming, this is going to become more and more important and easier to take advantage of. You still have to plan it out in Java, but it's definitely easier than I remember threads being in C++ and from what I've read lately (in this thread?) that's still the case. Using good high-level Object abstractions make retrofitting for threading a lot easier too.

Merriodoc Brandybuck

Posts: 225
Nickname: brandybuck
Registered: Mar, 2003

Re: "No sliver bullet" is in the fine print Posted: Dec 7, 2006 8:36 PM
Reply to this message Reply
> Firstly, I want to apologize for being a little less than
> civil in this thread. I think the technical term for this
> is being 'kind of a dick'.
>

<sarcasm>I, of course, was a perfect gentlemen. </sarcasm>

> I mean, you did piss me off a little but it's been a bad
> week and my mood tends to 'leak' into threads like this
> sometimes.
>

Join the club. It's called "caring about what you do". At least, that's what I tell myself. I don't think you can do this for a while without having a few closely held beliefs and prejudices. The challenge is to separate the two. It's hard.

> > It's very hard, if not impossible to do in the general
> > case for a general purpose language. Any useful
> features
> > need to be (or maybe more correctly should be)
> applicable
> > to a wide range of problems.
>
> I'm wondering if we may not be thinking about the same
> things here. I guess where I'm coming from is that I'm
> not against the high-capabilities of C++ (although I think
> some things could be disallowed but I'll address that
> later) but more that there are so many ways to accomplish
> the same thing. What I've been trying to say (badly) is
> that a language with the power of C++ but with a little
> spring-cleaning would be better. Maybe D fits this
> description. I'll try to get a chance to look at it.
>

I think that's D to a T.

> Here's an example of something I don't like in C++:
> pointer arithmetic. It's not allowed in Java and most
> t high-level languages. I'm sure there are cases where
> using it can optimize operations. But it seems to me that
> the compiler or runtime should be able to use this
> approach and much more safely.

C++ references are what most people should use in these cases. A lot of people don't, but we had that argument already. They aren't quite as abstracted as you like, but they make somethings that are easy to screw up with pointers much harder. In most cases the compiler compiles the two down to exactly the same code, so you don't lose anything by using references. I still find it amusing that Java has no pointers yet one of the most oft complained about exceptions is a NullPointerException.

> In Java 1.5, they
> introduced a for each type construct:
>
>
for (int i : intArray) {
>     // do something with i
> }

>
> It seems to me that the compiler or runtime can optimize
> this really well. Say it knows that the data will be
> contiguous. It can essentially use pointer arithmetic and
> potentially even drop the bounds checking (assuming the
> spec allows for this which I'm not sure it does.) In this
> way, we get our cake an eat it too. You get the raw speed
> without the pitfalls.
>

Sounds like STL iterators with a lot prettier syntax. I think the only reason STL iterators seem hard at all to people is the syntax is so God awful. I know it frightened me the first time I saw it. Perl, python, VB and just about every other language with associative arrays has this construct and has had it for a long time.

> Another example is not currently in Java but is described
> here:
> http://www.research.ibm.com/people/g/gupta/escape.ps
>
> With this runtime optimization, stack allocation, thread
> local allocation can be used, and synchronization dropped
> depending on the situation during execution. And this can
> be done with libraries which were written without knowing
> whether these optimizations would be OK. These are
> probably not new ideas but the are good ones all the
> same.
>

I just browsed it. I'll have to read that when I'm awake. I had a long day at work and went to my first Python User's Group meeting. I forgot how mentally draining it can be to spend 3 hours with some really smart people.

> > > > Ok. Abstractions leak all the time. Because of that
> I
> > > have
> > > > specific needs from time to time to get closer to
> the
> > > > metal than these abstractions allow. Taking that
> > > ability
> > > > away from me impairs my ability to solve problems.
> > >
> > > Perhaps. Perhaps you just haven't realized there is
> a
> > > much better approach. A lot of the times that I've
> > seen
> > > people drop down to the metal to solve issues, there
> was
> > a
> > > better (faster, less memory, more flexible) solution
> > > achieved by adding an abstraction.
> >
> > I don't disagree with that at all. Unfortunately 'A
> lot'
> > doesn't cover 'All'.
>
> Yes and I think that there needs to be a way to address
> those things. Python and Java both address this, although
> binding to native code in Java is a big pain (one of the
> bad things about Java.)
>

I tried binding to native code in java once. That was enough for me. It was almost a decade ago and it may be easier now, but with the amount of C# and VB I do, native code binding on windows is easy. I've worked for all Windows shops (I play with linux at home from time to time) and we've always used MS tools.

> > You're not a big fan of templates, so
> > you'll probably hate this, but here is an optimization
> > that I like a lot, not only because it also doesn't
> look
> > any nastier than regular ol' C++. You get brutally
> > efficient optimization that doesn't look any different
> > than the normal language syntax and this is better than
> > you can do in a lower level language like C to boot. So
> > maybe this supports your argument more than mine?
> > http://www.cantrip.org/emptyopt.html
>
> This seems like something that would be the job of a
> runtime or a compiler. There's some mention in that page
> of why the compiler can't in C++. In Java, I don't think
> the JIT can do that, but will unroll loops and I believe
> remove them if they are filled with no-ops, which is sort
> of a similar idea.
>

The compiler can't, but you can, stick it in a library and never have to write it again. If the compiler can do it, great. I'll take the help. To me this is just such a useful feature that I would rather deal with the cruft when I need this sort of power. I'm sure, at some point, something better will come along. I may be old and retired by then, however.

> > > > How so? I'll assume with your quick response you
> > didn't
> > > > get through the entire paper. Lisp was create
> > > specifically
> > > > as a notation to express functions, which is how we
> > > > express processes for a computer. Seems completely
> > > logical
> > > > to me.
> > >
> > > I'm fairly familiar with the idea of LISP. Just
> because
> > I
> > > think the idea was good doesn't mean I like that
> > > particular execution of it. You're not arguing that
> > this
> > > idea leads only LISP, are you?
> > >
> >
> > I'm not arguing that anything leads invariably to LISP.
> At
> > least, not its syntax, which what I'll assume you mean
> by
> > "that particular execution". But the ideas aren't new
> and
> > the languages that I hear people talk about (python and
> > ruby, mostly) that are going down the path you describe
> > credit at least some of their design to LISP.
> Invariably
> > overstates the case, but there sure is a high
> > correlation.
>
> I don't even know what we were arguing about. I think
> that the functional paradigm is a great idea but that LISP
> is that idea taken to an absurd conclusion. This is just
> my opinion, obviously. I don't think LISP's failure to
> become a dominate language is because this idea was a bad
> one, it's just that LISP seems strange and requires
> twisted reasoning for most developers. Languages that
> combine the functional and OO paradigms have the most
> promise, I think.
>

No doubt. This is one of the reasons I like C++. It has the ability to reasonably use most available paradigms in a reasonable manner. I think it is definitely the jack of all trades master of none language. Functional programming requries twisted thinking regardless. LISP just throws it right in your face. Plus, you still can't do anything like LISP macros in a language other than LISP. I've never had the need to use them, mind you, but that's the rumor.

> > > Give me an an example of the kind of thing you are
> > talking
> > > about that you do on a regular basis. Maybe you'll
> > > convince me.
> >
> > I used to help work on a database application that was
> > responsible at times for rolling up 10's to 100's of
> > gigabytes of financial data from leaf level data entry
> > nodes to summary levels for executives. Given the
> constant
> > changes to financial rules across the globe (the
> software
> > is sold worldwide), there are constant tweaks to the
> > rollup process. Given the large amounts of data that
> are
> > processed we need all the control we can get when
> running
> > this process. The object models and runtimes of more
> > modern languages bring this process to a grinding halt.
> In
> > order to handle this amount of data there are "tricks"
> all
> > over the place to conserve memory and shave CPU cycles.
> > For small consolidations that take seconds or minutes,
> > this isn't a big deal. Some of the tweaks, however,
> were
> > put in place to cut consolidations down from days to
> hours
> > or, in the best cases, minutes. Performance is a huge
> deal
> > for this app because nobody wants to start rolling up
> > their database Friday, leave for the weekend and have
> > maybe a 50/50 shot that it will be done when they come
> in
> > Monday morning.
> >
> > It has to run and it has to run in a reasonable amount
> of
> > time and given the need to properly apply the financial
> > rules (order of calculations matter, relationships of
> > certain members in the database change the calculations
> > depending on financial rules covering partially and
> wholly
> > owned subsidiaries based on country, etc.) you don't
> have
> > a lot of wiggle room with the algorithms. You have some
> > but not much because the numbers have to be right. The
> > only practical alternative is to make the computations
> > take less time.
>
> OK this is a good example. This may not have applied at
> the time you were working on this, but could parallel
> processing helped here or is the process necessarily
> sequential? It's ball is just getting rolling on this,
> but with the 16 core chips that are coming, this is going
> to become more and more important and easier to take
> advantage of. You still have to plan it out in Java, but
> it's definitely easier than I remember threads being in
> C++ and from what I've read lately (in this thread?)
> that's still the case. Using good high-level Object
> abstractions make retrofitting for threading a lot easier
> too.

This isn't my problem anymore :-) For the past few years they've taken the scale out instead of up approach for horrendous databases. Customers will buy 3 or 4 servers and run their rollups in smaller chunks in parallel. I can't imagine what hell a total rewrite of that app would be and it would have to be a total rewrite. If you think C++ is a frankenstein, I hope you never, ever see code like this stuff.

Threading in C++ still isn't great (all platform dependent) and the committee is trying to address this for the next version. This is worth a read if you care to spend a few minutes on it http://www.artima.com/cppsource/threads_meeting.html. I think I had to read it 3 times before digesting it all. Concurrency is hard :-( In the general case I think good threading libraries are going to gravitate toward Erlang. Erlang makes several assumptions that makes threading much easier to abstract and just about everybody I know that has ever looked at Erlang and done concurrent programming in it has been reasonably happy, which is quite a statement when talking about concurrent programming. I've never been happy doing that stuff.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: "No sliver bullet" is in the fine print Posted: Dec 8, 2006 6:12 AM
Reply to this message Reply
> Join the club. It's called "caring about what you do". At
> least, that's what I tell myself. I don't think you can do
> this for a while without having a few closely held beliefs
> and prejudices. The challenge is to separate the two. It's
> hard.

Yeah, but I've been so much better lately about not getting heated. I don't feel good about how I was acting. Anyway, I don't really believe some of the things I wrote in this thread, like that your skills might become obsolete. Pretty stupid statement, really.

> C++ references are what most people should use in these
> cases. A lot of people don't, but we had that argument
> already.

Right. We already hashed that out. But do you believe there are cases where the developer must use pointer arithmetic to get the job done?

> They aren't quite as abstracted as you like, but
> they make somethings that are easy to screw up with
> pointers much harder. In most cases the compiler compiles
> the two down to exactly the same code, so you don't lose
> anything by using references. I still find it amusing that
> Java has no pointers yet one of the most oft complained
> about exceptions is a NullPointerException.

That's a really commonly held misconception, even with Java pros. Java does have pointers, it just doesn't have pointer arithmetic. If you look at the language spec, (you need to forget the C++ terms for a second) is defines a reference this way:

An [i]object[/i] is a [i]class instance[/i] or an array.

The reference values (often just [i]references[/i]) are
[i]pointers[/i] to these objects


Rephrasing that, you get: 'the value of a reference is a pointer.' And that's exactly the case. One of the things I like about Java is that you can only do a few things with pointers: assign them, check for equality, and dereference them. You can't see what the numerical value is. Partly this is so that runtimes can be flexible in their management of memory but it also makes it impossible to point a pointer to a bad address.

> Sounds like STL iterators with a lot prettier syntax. I
> think the only reason STL iterators seem hard at all to
> people is the syntax is so God awful. I know it frightened
> me the first time I saw it. Perl, python, VB and just
> about every other language with associative arrays has
> this construct and has had it for a long time.

Right and that's what sucks about Java. It's kind of slow in terms of features and generics should have been included from the start without erasure.

> I tried binding to native code in java once. That was
> enough for me. It was almost a decade ago and it may be
> easier now, but with the amount of C# and VB I do, native
> code binding on windows is easy. I've worked for all
> Windows shops (I play with linux at home from time to
> time) and we've always used MS tools.

No, it's not easier. It's done very rarely in the Java world. I had some bad experiences with it in the past also. It's not something I've needed much, though.

> The compiler can't, but you can, stick it in a library and
> never have to write it again. If the compiler can do it,
> great. I'll take the help. To me this is just such a
> useful feature that I would rather deal with the cruft
> when I need this sort of power. I'm sure, at some point,
> something better will come along. I may be old and retired
> by then, however.

And what you are doing makes perfect sense in this context. But what I'm saying is that it's clearly possible for this to be done automatically. This is the kind of advancement that developers should be embracing, IMO.

> > I don't even know what we were arguing about. I think
> > that the functional paradigm is a great idea but that
> LISP
> > is that idea taken to an absurd conclusion. This is
> just
> > my opinion, obviously. I don't think LISP's failure to
> > become a dominate language is because this idea was a
> bad
> > one, it's just that LISP seems strange and requires
> > twisted reasoning for most developers. Languages that
> > combine the functional and OO paradigms have the most
> > promise, I think.
> >
>
> No doubt. This is one of the reasons I like C++. It has
> the ability to reasonably use most available paradigms in
> a reasonable manner. I think it is definitely the jack of
> all trades master of none language. Functional programming
> requries twisted thinking regardless. LISP just throws it
> right in your face. Plus, you still can't do anything like
> LISP macros in a language other than LISP. I've never had
> the need to use them, mind you, but that's the rumor.

Well, I kind of think of those things like owning a bazooka. If I really need to destroy something a bazooka will really help but I'm not going to acquire one.

On the other hand, I'm trying to learn Scala, which, from what I understand about LISP, has very LISPish aspects to it. It's a cool language but a little different than what I am used to.

> This isn't my problem anymore :-) For the past few years
> they've taken the scale out instead of up approach for
> horrendous databases. Customers will buy 3 or 4 servers
> and run their rollups in smaller chunks in parallel.
> I can't imagine what hell a total rewrite of that app would
> be and it would have to be a total rewrite. If you think
> C++ is a frankenstein, I hope you never, ever see code
> like this stuff.

I've seen some bad bad code. You can write really bad code in Java too. I think I mentioned it before but the biggest problem in Java is that there are some really popular techniques that (IMO) are terrible and just cause bloat and spaghetti code. I'm of the opinion that good code is the exception. I guess I agree with BS on that point, anyway.

> Threading in C++ still isn't great (all platform
> dependent) and the committee is trying to address this for
> the next version. This is worth a read if you care to
> spend a few minutes on it
> http://www.artima.com/cppsource/threads_meeting.html. I
> think I had to read it 3 times before digesting it all.
> Concurrency is hard :-( In the general case I think good
> threading libraries are going to gravitate toward Erlang.
> Erlang makes several assumptions that makes threading much
> easier to abstract and just about everybody I know that
> has ever looked at Erlang and done concurrent programming
> in it has been reasonably happy, which is quite a
> statement when talking about concurrent programming. I've
> never been happy doing that stuff.

Erlang does have a good model. Java's is very usable but takes a little bit of know-how to get it to work. You end up using Erlang style designs in a lot of cases. I guess In terms of threading Java is to Erlang as C++ is to Java for general imperative programming.

Actually this is one of those examples of where trying to over optimize things hurts people. Some developers will attempt to use statics a lot in Java in order to save on memory and make the code faster. But if you want to go back and make it multi-threaded, you end up having to put locks in all over the place and even if you get it working, you have all kinds of contention issues. If you avoid mutable statics and create a new Object for each standalone piece of logic, you can easily multi-thread with no locks or just a few in key places. I'm writing code right now that I don't intend to multi-thread (for now) but if I need to, it should be fairly trivial to do so (unless I've made a blunder or two on my late nights.)

Flat View: This topic has 212 replies on 15 pages [ « | 12  13  14  15 ]
Topic: Pantheios 1.0.1 full release approaching; beta 17 just released Previous Topic   Next Topic Topic: John Ousterhout on What Limits Software Growth

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use