Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Future Improvements (https://forums.graalonline.com/forums/forumdisplay.php?f=10)
-   -   _indexof2 (https://forums.graalonline.com/forums/showthread.php?t=48056)

TribulationStaff 09-18-2003 03:36 AM

_indexof2
 
Make a second version of all the _indexof functions such that they are CaSE seNsItIVE.

Kaimetsu 09-18-2003 09:00 AM

Hmm. I'm sure it has many uses, but I can't seem to think of any...

TribulationStaff 09-18-2003 06:38 PM

Well, the base 64 system Stefan created to deal with storing tiles is case sensitive.

Kaimetsu 09-19-2003 04:30 AM

Quote:

Originally posted by TribulationStaff
Well, the base 64 system Stefan created to deal with storing tiles is case sensitive.
So?

Goboom 09-19-2003 05:02 AM

Quote:

Originally posted by Kaimetsu
Hmm. I'm sure it has many uses, but I can't seem to think of any...
The only thing I can think of is maybe a password system thing or some sort of tile editor type deal, may be wrong but hey I think outside the box.

TribulationStaff 09-19-2003 06:15 AM

Quote:

Originally posted by Kaimetsu


So?

So Jagen asked me to script the conversion for him, and the most efficient way I could think of included indexof to calculate the values of the letters.

-Ramirez- 09-19-2003 06:42 AM

Quote:

Originally posted by Kaimetsu
Hmm. I'm sure it has many uses, but I can't seem to think of any...
It could be quite useful for the upcoming 3.1 that has editboxes and things.

Kaimetsu 09-19-2003 07:08 AM

Quote:

Originally posted by TribulationStaff
So Jagen asked me to script the conversion for him, and the most efficient way I could think of included indexof to calculate the values of the letters.
That's the most efficient way you could think of? Shame on you.

TribulationStaff 09-19-2003 08:01 AM

I am positive indexof is a far cry more efficient that a ton of ifs trying to figure out the decimal value of the letter.

Kaimetsu 09-19-2003 08:13 AM

Quote:

Originally posted by TribulationStaff
I am positive indexof is a far cry more efficient that a ton of ifs trying to figure out the decimal value of the letter.
You wouldn't need 'a ton' if you coded it correctly.

TribulationStaff 09-20-2003 06:37 AM

Still, far better 1 line as opposed to 64 virtually identical if clauses

I can create a string, call it this.values, and arrange all the characters such that their position in the string is their decimal value. However, for this to work right, indexof needs to differentiate between G and g.

Since I don't have access to v3 engine, I can't do a switch statement, which would still be quite a bit longer. So, I am stuck with
NPC Code:

if (strequals(A,#e(blah)))
{
this.decimal+=blah;
}


over and over again

Kaimetsu 09-20-2003 06:47 AM

Quote:

Originally posted by TribulationStaff
Still, far better 1 line as opposed to 64 virtually identical if clauses
I already said you wouldn't need many. Three, perhaps? Maybe four.

Quote:

I can create a string, call it this.values, and arrange all the characters such that their position in the string is their decimal value. However, for this to work right, indexof needs to differentiate between G and g.
Yes, or you could use an efficient method.

TribulationStaff 09-21-2003 03:17 AM

Would you care to explain how three to four ifs could allow me to convert one of 64 characters into their decimal equivalents?

Secondly, how is it at all inefficient to condense those ifs into a single indexof?

Kaimetsu 09-21-2003 03:36 AM

Quote:

Originally posted by TribulationStaff
Would you care to explain how three to four ifs could allow me to convert one of 64 characters into their decimal equivalents?
You'd obviously need a little more code as well; the if-statements would merely divide the characters into ranges. After that, it would be a simple matter of arithmatic.

Quote:

Secondly, how is it at all inefficient to condense those ifs into a single indexof?
Please tell me you're not one of those people who thinks that shortness of script == efficiency.

TribulationStaff 09-21-2003 03:45 AM

So, you admit, you just aren't adding three ifs, you are adding other things. And these "ranges" how would you define them?

As for the length of the script, no, I think it is a lot more efficient to say "where is it located?" than several "is it this? No? Well is it that?"

indexof may start to be a less efficient piece of code when used 10000 times; but, from what I have seen of differences in efficiency at this level of iteration, I doubt that it's going to be a problem.

Kaimetsu 09-21-2003 03:55 AM

Quote:

Originally posted by TribulationStaff
So, you admit, you just aren't adding three ifs, you are adding other things.
It's not an 'admission'. Obviously it would require more than three ifs; if there's no code inside the structures then what would be the point? The difference is that the code inside would be simple and efficient.

Quote:

And these "ranges" how would you define them?
Primary two: A-Z and a-z

Quote:

As for the length of the script, no, I think it is a lot more efficient to say "where is it located?" than several "is it this? No? Well is it that?"
Then you don't really understand scripting yet. Searching a string for a value is the act of repeatedly checking values.

Quote:

indexof may start to be a less efficient piece of code when used 10000 times; but, from what I have seen of differences in efficiency at this level of iteration, I doubt that it's going to be a problem.
1) Efficiency isn't based on scale. Your approach is less efficient, even if the difference between singular executions is only a couple of nanoseconds.
2) When used 10,000 times, huh? Tell me, what are you going to do with this base64 stuff? Could it be that you intend to iterate through 4096 tile specifications?

TribulationStaff 09-21-2003 04:23 AM

Quote:

Primary two: A-Z and a-z
And how will you tell if something is in these ranges without something that is case sensitive?

Quote:

2) When used 10,000 times, huh? Tell me, what are you going to do with this base64 stuff? Could it be that you intend to iterate through 4096 tile specifications?
Well, let me put it this way. Let us say that each time I use it, a nanosecond or three elapses. That is 1E-9 seconds. 1E4 times that nanosecond is still less than a second. Not bad for a only seldom, in computer time, used bit of code.

Kaimetsu 09-21-2003 04:28 AM

Quote:

Originally posted by TribulationStaff
And how will you tell if something is in these ranges without something that is case sensitive?
Hint: Every letter has an ASCII value

Quote:

Well, let me put it this way. Let us say that each time I use it, a nanosecond or three elapses. That is 1E-9 seconds. 1E4 times that nanosecond is still less than a second. Not bad for a only seldom, in computer time, used bit of code.
*shrugs*

If you want to try to justify bad code then be my guest. Perhaps you don't realise the greater consequences.

TribulationStaff 09-21-2003 04:39 AM

Quote:

Hint: Every letter has an ASCII value
Isn't that exactly what indexof would use? Except for the fact that, as is, indexof uses either the toupper or tolower of the characters to ignore case.

It really sounds as if you want to do something very similar to what I am doing except in pieces rather than just in one step.

Kaimetsu 09-21-2003 05:01 AM

Quote:

Originally posted by TribulationStaff
Isn't that exactly what indexof would use?
Yep. But there's more than one way to use something.

Quote:

It really sounds as if you want to do something very similar to what I am doing except in pieces rather than just in one step.
Either because you don't understand what indexof does or you can't see what I'm suggesting.

Indexof examines each character of the source string, looking for a match between it and the argument you provide. One by one. Like 64 little ifs.

That's not what I'm suggesting.

Once you've divided the string into ranges, you can do all the numerical manipulation with a couple of elements of arithmatic.

TribulationStaff 09-21-2003 05:21 AM

Quote:

Once you've divided the string into ranges, you can do all the numerical manipulation with a couple of elements of arithmatic.
I'm not seing how you are going from letters to arithmatic. You'd still need some sort of conversion.

Kaimetsu 09-21-2003 05:22 AM

Quote:

Originally posted by TribulationStaff
I'm not seing how you are going from letters to arithmatic. You'd still need some sort of conversion.
To a computer, letters are just numbers.

TribulationStaff 09-21-2003 05:38 AM

Ah. I see ASCII value. Hrm.

Yeah you could do it that way.

Doesn't seem very versatile. My way, to change the system, you just change the string. Your way, you'd have to rearrange all the ifs. Sure, I'm being hypothetical here, but there it is.

Kaimetsu 09-21-2003 05:40 AM

Quote:

Originally posted by TribulationStaff
Yeah you could do it that way.

Doesn't seem very versatile. My way, to change the system, you just change the string.

Mm-hmm. You planning on redefining base64 any time soon?

TribulationStaff 09-21-2003 06:10 AM

No, but suppose I want to create my own encryption system? It would be a piece of cake to tweak the code I already have.

You might say I am the scripting world's answer to Junkyard Wars (Scrapheap Challenge in UK). I love cannibalizing code.

Kaimetsu 09-21-2003 07:19 AM

Quote:

Originally posted by TribulationStaff
No, but suppose I want to create my own encryption system? It would be a piece of cake to tweak the code I already have.
That's not a particularly good justification. If you forever cannibalise from the past simply to save yourself effort then:

1) Your scripts will be less efficient as a result.
2) You won't consider all the possible approaches; you'll automatically choose one that involves some previous script.

TribulationStaff 09-21-2003 07:41 AM

Clearly I don't cannibalize everything, or I wouldn't need new functions. I just like cannibalizable code. Everything worth coding has multiple uses.

Kaimetsu 09-21-2003 07:49 AM

Quote:

Originally posted by TribulationStaff
Clearly I don't cannibalize everything, or I wouldn't need new functions. I just like cannibalizable code. Everything worth coding has multiple uses.
Even if that were true, it's antithetical to the practice of coding something more poorly just so that it can be reused.

TribulationStaff 09-21-2003 07:52 AM

Wait a second. Are you straw-manning?

In your opinion, more poorly. Yes. In the opinion of the computer science world, sure. In my mind, more versatile is better than more precise. I am willing to sacrifice efficiency on a small scale to make the script more useful

Kaimetsu 09-21-2003 08:07 AM

Quote:

Originally posted by TribulationStaff
Wait a second. Are you straw-manning?
Not at all. A strawman is an aesthetically-similar-but-different argument or stance. I'm not making any pretense regarding your position on this issue, I'm merely describing it in my own words. To call a practice poor isn't straw-manning, it's just analysing.

Quote:

In your opinion, more poorly. Yes. In the opinion of the computer science world, sure. In my mind, more versatile is better than more precise. I am willing to sacrifice efficiency on a small scale to make the script more useful
As would most computer scientists, but the difference is that your code is much less efficient. You seem to be misinterpreting the main issue here. Coding efficiently isn't merely about making a single routine run 0.01 seconds faster. It's about challenging oneself to find better ways to solve a problem, to analyse his own code from an objective standpoint. If you don't do that then, as has been shown in this thread, you don't consider all the options.

A good coder isn't somebody who uses a hammer and crowbar to wedge his old code into somewhere it doesn't fit. A good coder designs each solution to fit a single problem, and draws on old creations only when they match the design he crafts beforehand.

TribulationStaff 09-21-2003 07:02 PM

Lol. This is why I am a mathematician instead of a computer scientist. But you have to admit, I don't do too badly for only taking one class.

On the other hand, I wouldn't exactly call it hammering a square peg into a round hole. It's more like I like to use clay pegs.

Let me give you an example. I coded a window display routine for SA. This code allowed Soul to make the window any size he wanted, within reason. After finishing that, I realised that the script had other potential. I converted it from an image tiler to a tile tiler. In the matter of about two minutes I had created a whole new use for the same script.

Kaimetsu 09-22-2003 05:04 AM

Quote:

Originally posted by TribulationStaff
Lol. This is why I am a mathematician instead of a computer scientist. But you have to admit, I don't do too badly for only taking one class.
Well, programming is all about practice. Any talented programmer teaches himself 90% of what he knows.

Quote:

Let me give you an example. I coded a window display routine for SA. This code allowed Soul to make the window any size he wanted, within reason. After finishing that, I realised that the script had other potential. I converted it from an image tiler to a tile tiler. In the matter of about two minutes I had created a whole new use for the same script.
That's not the same thing. That's taking inspiration from something you've previously made, and turning it into something more. I'm talking about coding using a design implicitly created with the goal of being portable - especially when the code involved is so tiny.


All times are GMT +2. The time now is 03:24 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.