It’s also just good for me to see how other people program– perhaps especially those who know their code and style will be visible. In my current position, I manage a single other tech employee, and while the county does have other programmers, we are organizationally separate from them. IT professionals (or as I usually cal l us “Geeks”) learn from each other. It’s hard to get that kind of training from college, because just a few years out of college and the tech has changed, the best practices have altered, and things are new again. We have to always keep learning, and we do that primarily from each other. Thankfully there’s an Internet full of us geeks out there to learn from. so I’m not completely isolated.
And if I pass in the string “Hello World”, I get “ello” out.
That seems reasonable to me, start and finish. It’s like an interval in math (although a closed one).
Java pretty much confounded me though, I tried both of those and neither worked, so I finally did what I should have started with, and searched the docs. Now I’d looked at it, but it was just substring(startIndex,endIndex), which matched my understanding so I hadn’t looked further. But when I read it today, I realized that endIndex is actually not inclusive in the Java implementation. Which means that the proper code for Java is:
Of course, in Java I also have to make sure my string is at least 7 characters long before invoking that. JS and PHP will do something intelligent (returning “”, for instance, or just returning what is there, and not necessarily 4 full characters). Which makes me wonder sometimes at the mindset of the Java people. I’m not saying boundary checking is bad — it’s necessary. But it could have been in the function, and built into the language instead of elsewhere. I guess this makes sense because substring length = endIndex – startIndex. But somehow it seems counter-intuitive to me.
Ultimately though, it’s what it is. Languages all do the same thing, or so my college COBOL professor said, “Input, Processing, Output. Learn that and you have the key to all languages.” Most things are just syntactical sugar, so program with your help docs handy and you can do pretty much what you want with any language. You’ll just stumble occasionally, which is one more reason why you keep learning and testing your skills.