AJXB Posted January 18, 2017 Share Posted January 18, 2017 "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
John Smith Posted January 18, 2017 Share Posted January 18, 2017 Numerical looping is 2 times faster than pairs, while pairs is slightly faster than ipairs. 1 Link to comment
AJXB Posted January 18, 2017 Author Share Posted January 18, 2017 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
Noki Posted January 19, 2017 Share Posted January 19, 2017 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 2 Link to comment
John Smith Posted January 19, 2017 Share Posted January 19, 2017 https://springrts.com/wiki/Lua_Performance#TEST_9:_for-loops Link to comment
Captain Cody Posted January 20, 2017 Share Posted January 20, 2017 On 1/18/2017 at 21:22, Noki said: Yada Yada Wasn't it Simple01 the lad talking about this? Link to comment
Simple0x47 Posted January 21, 2017 Share Posted January 21, 2017 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
AJXB Posted January 22, 2017 Author Share Posted January 22, 2017 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
Simple0x47 Posted January 22, 2017 Share Posted January 22, 2017 I'm not mad. Just being poetic with scripting. Link to comment
AJXB Posted January 23, 2017 Author Share Posted January 23, 2017 18 hours ago, Simple01 said: I'm not mad. Just being poetic with scripting. This cracked me up lmfao, poetic? *claps* 2 Link to comment
Blast3r Posted January 23, 2017 Share Posted January 23, 2017 (edited) @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 January 23, 2017 by Blast3r Link to comment
Simple0x47 Posted January 23, 2017 Share Posted January 23, 2017 A proof is coming, stay tuned. Link to comment
Captain Cody Posted January 23, 2017 Share Posted January 23, 2017 (edited) Hahahha that's the funniest thing I heard all day you cannot beat my streamer plain and simple. Heck only thing stopping me from being able to stream the entire map without missing objects is fps. Edited January 23, 2017 by CodyJ(L) Link to comment
Simple0x47 Posted January 23, 2017 Share Posted January 23, 2017 One thing. No system is perfect, there's always a fail. Link to comment
Captain Cody Posted January 23, 2017 Share Posted January 23, 2017 My Streamer may not be perfect, but it's the best one in MTA made so far. It's made with breaking previous limits in mind which is successfully has done. Link to comment
Simple0x47 Posted January 23, 2017 Share Posted January 23, 2017 49 minutes ago, CodyJ(L) said: My Streamer may not be perfect, but it's the best one in MTA made so far. It's made with breaking previous limits in mind which is successfully has done. If it's that good I hope there's no freezing times. Link to comment
Captain Cody Posted January 23, 2017 Share Posted January 23, 2017 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
Simple0x47 Posted January 24, 2017 Share Posted January 24, 2017 That sounds very good. Let's make later when I'll finish mine a comparation. I'm pretty curious to see the difference. Link to comment
MTA Anti-Cheat Team Dutchman101 Posted January 24, 2017 MTA Anti-Cheat Team Share Posted January 24, 2017 Please stay ontopic, talk about the subject: pairs vs ipairs instead of a personal competition. Link to comment
Noki Posted January 28, 2017 Share Posted January 28, 2017 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
Simple0x47 Posted January 28, 2017 Share Posted January 28, 2017 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
Captain Cody Posted January 28, 2017 Share Posted January 28, 2017 Haha I'm very guilty of the readability thing. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now