Skip to main content

Bug Tracker

Side navigation

#12365 closed enhancement (invalid)

Opened August 21, 2012 05:01PM UTC

Closed August 21, 2012 06:22PM UTC

Last modified September 22, 2012 10:04PM UTC

Change all obj++ to ++obj where applicable

Reported by: info@paulmicha.com Owned by: info@paulmicha.com
Priority: undecided Milestone: None
Component: misc Version: 1.8.0
Keywords: dbr Cc:
Blocked by: Blocking:
Description

Can you guys please change every instance of something such as i++ to ++i ? and keep obj++ only where it makes sense to use it.

Attachments (0)
Change History (19)

Changed August 21, 2012 05:06PM UTC by dmethvin comment:1

owner: → info@paulmicha.com
status: newpending

Might be an interesting exercise. Can you do that and let us know if it makes any performance difference?

Changed August 21, 2012 05:37PM UTC by rwaldron comment:2

There is no discernible performance difference, but there is a behavioral difference—this is just asking for unnecessary potential bugs.

Changed August 21, 2012 06:22PM UTC by timmywil comment:3

component: unfiledmisc
resolution: → invalid
status: pendingclosed

agreed, this is not valid.

Changed August 22, 2012 01:14AM UTC by info@paulmicha.com comment:4

I would estimate a performance increase of roughly 0.01%. But thats not the point - Its about good programming practice. Think about your clients - There is a high probability of them learning something new when they see this.

Take your code seriously. Yes there is a risk of breaking functionality, but with about 5 minutes time and care you could change this without any risk.

Think about the clients please.

Changed August 22, 2012 12:46PM UTC by ajpiano comment:5

What part of "good programming practice" dictates that prefixing the increment operator is uniformly superior to postfixing it, except "where it makes sense"? With over are currently 94 instances of "++" in jQuery Core, I am fairly certain that going through, determining where it might be "appropriate," changing them all, and testing would take more than 5 minutes.

You can rest assured that we do take the code seriously, which is why with millions of users and installs, we can't just make a frivolous change like this in the name of unidentified clients "learning something new." It's also unclear who the "clients" in question here are, but most of the clients I work with in my day job are aware of the principle that "If it ain't broke, don't fix it," which applies here.

Changed August 22, 2012 04:10PM UTC by info@paulmicha.com comment:6

understood. will not comment any further.

i would like to point out however that the prefix increment operator is superior to postfixing, especially when incrementing objects of non primary type.

besides the fact that it is more efficient to prefix, given the fact that you have millions of users, its your moral obligation and responsibility to provide the absolute best solution in terms of functionality and semantics.

Changed August 22, 2012 04:35PM UTC by rwaldron comment:7

Replying to [comment:6 info@…]:

understood. will not comment any further. i would like to point out however that the prefix increment operator is superior to postfixing, especially when incrementing objects of non primary type.

The prefix and postfix increment operators are nearly identical, differing only in which side the operand value is derived from and which value is returned. Prefix operand is the UnaryExpression, postfix is LeftHandSideExpression. Prefix returns the new value, postfix returns the old value.

In the case of for loops, since incrementing generally occurs in what is referred to as the second optional expression, there is no behavioural difference as the incrementing expression is still evaluated to completion before continuing to the next iteration.

besides the fact that it is more efficient to prefix,

You keep saying this, but have yet to provide any proof.

given the fact that you have millions of users, its your moral obligation and responsibility to provide the absolute best solution in terms of functionality and semantics.

Knock off the soapboxing and bring facts to the table or don't post at all.

Changed August 22, 2012 04:58PM UTC by info@paulmicha.com comment:8

For proof: My apologies, I thought you already knew why it is more efficient. Thats why I didn't provide any proof.

When using obj++ a copy is made of the object before incrementation to be used in the expression. Then the object is incremented.

With prefix, no copy call is invoked.

So again, for primary types there is a very small performance increase. However, for objects such as iterators in c++, there is a notable difference.

In summary, for your incrementations in loops, the performance increase wont be noticable.. but when people learn that it should be used over postfix, then they start using it for user defined object incrementation which is why I am stressing this.

I also wanted to commend all of you on a beautiful product.

Changed August 22, 2012 05:23PM UTC by rwaldron comment:9

Replying to [comment:8 info@…]:

For proof: My apologies, I thought you already knew why it is more efficient. Thats why I didn't provide any proof. When using obj++ a copy is made of the object before incrementation to be used in the expression. Then the object is incremented. With prefix, no copy call is invoked.

This is not correct at all. Both operations create a copy and increment the copy by 1. Prefix returns the incremented value and postfix returns unincremented value.

So again, for primary types there is a very small performance increase. However, for objects such as iterators in c++, there is a notable difference. In summary, for your incrementations in loops, the performance increase wont be noticable.. but when people learn that it should be used over postfix, then they start using it for user defined object incrementation which is why I am stressing this. I also wanted to commend all of you on a beautiful product.

Changed August 22, 2012 07:03PM UTC by info@paulmicha.com comment:10

If you are correct, I should go back to my University and tell my prof he's wrong.

But I have a feeling he is right cause he's an amazing computer scientist..

Here's some proof (results found by using google searches)

1) Javascript specific:

http://jsperf.com/prefix-or-postfix-increment

2) http://www.parashift.com/c++-faq-lite/increment-pre-post-speed.html

++i is sometimes faster than, and is never slower than, i++.

3) http://stackoverflow.com/questions/3181211/prefix-postfix-increment-operators

It is typical that a postfix operator will be worse on performance because you have to create another copy before doing the increment (and this is why I've gotten in the habit of always using prefix unless I need something else).

With return-by-reference, you're returning an l-value reference to the current object. The compiler would typically implement this by returning the address of the current object. This means that returning the object is as simple as returning a number.

The biggest thing I dislike about the industry I work in is I am exposed to Egocentric programmers.

Changed August 22, 2012 07:14PM UTC by dmethvin comment:11

Wait, what?

Chrome http://i.imgur.com/o9dso.png

IE9 http://i.imgur.com/N7kkX.png

Firefox http://i.imgur.com/HvSKe.png

Safari http://i.imgur.com/bp7Fo.png

Postincrement wins on every run, and wins big on Chrome.

Changed August 22, 2012 07:34PM UTC by anonymous comment:12

Well then, I was wrong!

Changed August 22, 2012 08:04PM UTC by rwaldron comment:13

I'm not egocentric, I just know how to read the spec.

http://es5.github.com/x11.html#x11.3.1

http://es5.github.com/x11.html#x11.4.4

I'll await your apology.

Changed August 22, 2012 10:29PM UTC by anonymous comment:14

I apologize for not looking into the matter thoroughly before posting a ticket. Most of all, I apologize for wasting your time.

But I cannot apologize for some of the statements in my argument.

Changed September 21, 2012 03:25PM UTC by Tem Corner comment:15

Just to clarify a bit, the unnamed professor referenced here likely knew what he was talking about and may even be right. However the second I saw a reference to C++ it becomes obvious what the problem is. Assuming your professor did not study javascript in particular, that's just the problem.

I've you've learned programming it is very likely that you don't have a clue on how JavaScript works or what its strengths and weaknesses are. It looks very familiar due to its syntax, but don't be fooled. It is in no way related to Java (according to some references, the name "javascript" is in fact a joke/prank against Sun Microsystems who owns the trademark on "Java". And Netscape (who introduced LiveScript which became JavaScript) didn't get along with Sun very well).

Other than that, Java and JavaScript has absolutely no relation.

Basically anything you know about programming languages, forget about it and start writing javascript the way javascript works, its can be tough to let go of old habits, but they no longer apply in the land of javascript. Even if things appear to apply and the result is satisfying, it may very well be a coincidence.

Changed September 22, 2012 09:52PM UTC by info@paulmicha.com comment:16

very nicely put. Thanks for submitting

Changed September 22, 2012 09:58PM UTC by rwaldron comment:17

Haha, you argued with me when I gave you purely technical, spec based arguments—but when someone responds with a largely incorrect story, you thank them?

\\o/

Changed September 22, 2012 10:00PM UTC by rwaldron comment:18

keywords: → dbr

Changed September 22, 2012 10:04PM UTC by info@paulmicha.com comment:19

I retract my previous apology for wasting your time. You seem to be enjoying this.