Jump to content

This is ridiculous..


AJXB

Recommended Posts

"Look
There's 3 kind of loops
Ipairs - Pairs - Numerical
If you're smart guy and you can think off a good structre.
You will use rarely Pairs.
And never or almost never Ipairs.
If you're a medium guy on scripting.
You will use Pairs most of the times, making use of numerical some times and ipairs also some times.
And in my opinion the worst one, using Ipairs most of the times, pairs some times and numerical almost never."

Some ignorant who's acting like a professional coder is saying this. please, give me your opinion on what he's saying.

Link to comment
3 hours ago, John Smith said:

Numerical looping is 2 times faster than pairs, while pairs is slightly faster than ipairs.

He isn't talking about speed, he's generally saying that numerical loops are what an "expert" coder should be using.. 

The correct answer to this is "It depends on your table, and what data do you need", you can't talk in general about this.

Link to comment

It took me a second to realise that they weren't your words, and you were quoting someone.

Numerical incremental loops (for i = 1, 100 do, while i < 100 do) are generally speaking the fastest. For tables with numerical indexes larger than 100 items, pairs was faster than ipairs, but lower than 100 ipairs was faster. And when it comes to tables with non-perfect keys (strings, not sequential, etc) pairs is the only way to go.

@John Smith, you can't really say it's X amount faster without providing context to that answer. How big was the table? Were you running any operations within the loop? As I said in the last paragraph, it all depends on what you're doing.

It really comes down to what you're doing. In most other languages, there are arrays, which have numerical indexes and there are lists, which can have non-numerical indexes. Terminology differs between language, but you get what I mean. Each has a different use scenario. However, in Lua, we're given just a table, which can be seen both as a curse and as a blessing. We can use numerical indexes and treat tables like an array, or use non-numerical indexes and treat tables like a list, or we can do both!

Personally, I don't usually iterate over tables with non-numerical indexes unless I have to. I prefer to use my tables (with non-numerical indexes) as a lookup, as opposed to something that needs to be iterated over.

This guy has no idea what he's talking about. I mean, he says "medium scripter". What the hell is that supposed to mean? He's most likely just read some statistics on a StackOverflow answer and is going around parading his newfound knowledge. This isn't a black and white issue and really depends on what you want to achieve. Yes, incremental loops are faster in every way, but sometimes it can be cleaner to use ipairs/pairs (not having to access the original table's index to lookup, breaking on the first nil pair, etc).

http://softwareengineering.stackexchange.com/questions/80084/is-premature-optimization-really-the-root-of-all-evil

  • Like 2
Link to comment

People got wrong my words. I'm talking about the mentality of programmers and scripters, because there are all kind of ways to do things but there's always a best way to choose and there's where we start to discuss about loops. The amount of loops and their type represent a scripter's way to structurize his code, and in my opinion Ipairs and Pairs can be avoided and limited just to necessary cases and these cases are very hard to be found while you're scripting from scratch so stop putting Ipairs and Pairs each 10 lines of written code.

Link to comment
13 hours ago, Simple01 said:

People got wrong my words. I'm talking about the mentality of programmers and scripters, because there are all kind of ways to do things but there's always a best way to choose and there's where we start to discuss about loops. The amount of loops and their type represent a scripter's way to structurize his code, and in my opinion Ipairs and Pairs can be avoided and limited just to necessary cases and these cases are very hard to be found while you're scripting from scratch so stop putting Ipairs and Pairs each 10 lines of written code.

 

umad?

Link to comment

@gSub

Do you think that Simple01's lessons are a mother:Oin' joke mate? Are you not aware that he has a "better" streamer than @CodyJ(L) but has never gave proof that it's better? Huh?

To add to the topic, best thing to do is simply remove all of the loops because who needs loops anyway?


I also didn't know you can be "poetic" about scripting lmao

Edited by Blast3r
Link to comment

Don't want to fill this topic with any more arguments related to this so I'll just leave it at, inital load freezes up a tad bit with United due to enormous amount of objects dffs txds etc getting loaded in. But after which you have no load times. And with maps such as gostown, VC stand alone and LC stand alone there is little to no initial loading times. If you'd like to continue this PM me or make another topic.

Link to comment
On 22/01/2017 at 01:21, Simple01 said:

People got wrong my words. I'm talking about the mentality of programmers and scripters, because there are all kind of ways to do things but there's always a best way to choose and there's where we start to discuss about loops. The amount of loops and their type represent a scripter's way to structurize his code, and in my opinion Ipairs and Pairs can be avoided and limited just to necessary cases and these cases are very hard to be found while you're scripting from scratch so stop putting Ipairs and Pairs each 10 lines of written code.

There is never a "best' way to do things. Are you going for pure code speed, or readability? There are so many factors that impact the best course of action. No single solution fits all use cases. You're going to have a very hard time working with other people and coding in the real world if you have that perspective.

On 22/01/2017 at 21:48, Simple01 said:

I'm not mad. Just being poetic with scripting.

No, you're not being poetic. If anything, you're being pathetic. Part of programming is having an open mind to new solutions and different ways of approaching a problem. You're not doing either of those.

Link to comment

Part of programming is having an open mind but at the same time having a critic view of what you're doing, and yes I go for pure code speed with an excellent readability, the thing is figuring out a great structure and work with it. That's why I'm pretty tired to see in almost every script here on MTA Forums or anywhere else Ipairs for almost everything. If you guys enjoy writing ipairs in every loop, go ahead and make some trash code.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...