Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 721 722 [723] 724 725 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 890243 times)

strainer

  • Bay Watcher
  • Goatherd
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10830 on: April 17, 2018, 10:20:59 pm »

I like being able to do this in Lua:
Code: [Select]
a,b,c = c,a,dand doing multiple return values in the same manner.

I also think it looks sweet without structural braces and with its -- comments.

The 1+indexing was the bravest design choice, being different rubs against that considerable pressure to undiversify everything. If Lua didnt have >1 indexing, I would probably never have appreciated its so easy to accommodate.
Logged
Klok the Kloker !

milo christiansen

  • Bay Watcher
  • Something generic here
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10831 on: April 17, 2018, 10:52:42 pm »

Multiple assignment and multiple returns are pretty trivial to implement, they are not special to Lua in any way (for example, Go supports both).

Comments and braces are a matter of taste, Lua isn't wrong or anything.

1-based indexing however, is simply obnoxious. Nobody else does it that way, and for very good reasons.
Logged
Rubble 8 - The most powerful modding suite in existence!
After all, coke is for furnaces, not for snorting.
You're not true dwarven royalty unless you own the complete 'Signature Collection' baby-bone bedroom set from NOKEAS

strainer

  • Bay Watcher
  • Goatherd
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10832 on: April 18, 2018, 08:17:02 am »

Surprisingly, about a third of languages do it that way:
ALGOL 68, APL, AWK, CFML, COBOL, Fortran, FoxPro, Julia, Mathematica, MATLAB, PL/I, RPG, Sass, Smalltalk, Wolfram Language, XPath/XQuery

Logged
Klok the Kloker !

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10833 on: April 18, 2018, 08:51:49 am »

It's common in languages aimed at mathematicians, since vectors are 1-indexed, not zero-indexed.

So, when you're implementing math-related vector functions you can actually have some mental overhead and room for error because you're converting all vector/matrix indexes by subtracting 1. 1-indexing avoids that. However, you also want it to run fast, first and foremost, so you don't want your code converting from 1-index to 0-index by subtracting or adding 1 every time it does an operation that takes an idex. So the trade-off is to make every vector be a size "n + 1" array, and just throw away the 0th element. More memory needed, but you get the fast speed of 0-indexing while allowing the code to also conform to 1-indexed math notation.

it's a trade-off between memory, effort for the CPU and effort for the developer - having all 0-index locations empty is a trade-off that prioritizes processing speed, like 0-indexing does, while allowing 1-indexing for mathematicians, at the expense of wasting memory. e.g. this is a classic "3 options, pick 2" scenario. You can have fast access (like 0-indexing), compatibility with maths notation (1-indexing) and memory efficiency (no wasted bytes). But not all three at once.
« Last Edit: April 18, 2018, 09:12:33 am by Reelya »
Logged

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #10834 on: April 18, 2018, 09:09:27 am »

It's not even just a memory/cpu thing, it's also just about how you view indexing a set of data as expressed by a function:

Is list::at(n) getting the nth element of the list, or the element n places into the list?

Personally I think it does make more conceptual sense to view indexing a list in the latter way when dealing with tables and sets of data, but that's pretty subjective.
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10835 on: April 18, 2018, 09:15:21 am »

I don't know about that being "conceptually" better than 1-indexing for lists.

For arrays, 0-indexing makes technical sense, since you have the pointer to allocated memory and "pointer+index" gives you a memory location of item "index". It makes "conceptual" sense only for the reason that it's more efficient for the CPU to do this operation. But, it's not conceptually all that good for the 100th element to be element #99: it's just better for some low-level technical concerns, and is therefore something you need to learn and internalize.

For lists, 0-indexing only makes sense in that it then conforms to array notation (and remember, array notation is incompatible with mathematician's vector notation, thus translating between them incurs some real-world cost). In real life we refer to the "first element of the list", the "second element of the list" and so on, which is 1-notation. There is no such thing as the "nothingth element of the list" that makes "conceptually" more sense. 1 notation for lists/sets and most containers makes more logical sense, at a human level.

Theoretically, 1-indexing has some real advantages to teaching coding. There's enough to learn with coding without having to learn to adjust real-world counting that starts at one with computer counting that starts at zero. And of course, if they want to go further with maths they might then be confused as to why math textbooks use incompatible concepts with linear algebra than the computer science textbooks do.
« Last Edit: April 18, 2018, 09:30:17 am by Reelya »
Logged

strainer

  • Bay Watcher
  • Goatherd
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10836 on: April 18, 2018, 10:45:19 am »

Thanks Reelya for explaining.

A loosely related idea - Ive determined to call the singular of indices "an indicie" - since "index" has gotten loaded with overlaying meanings, so it can refer to:
  One of the indices
  The full set of indices.
  The verb to locate by indices.
  Any variable which refers to indices.
 
The clarity of "table > key : value" terminology can be a relief here.

Until the entire lexicon gets refactored I'll just have to keep trying to follow what was meant.
« Last Edit: April 18, 2018, 11:44:06 am by strainer »
Logged
Klok the Kloker !

milo christiansen

  • Bay Watcher
  • Something generic here
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10837 on: April 18, 2018, 11:53:13 am »

ALGOL 68, APL, AWK, CFML, COBOL, Fortran, FoxPro, Julia, Mathematica, MATLAB, PL/I, RPG, Sass, Smalltalk, Wolfram Language, XPath/XQuery

You will note that none of those languages would be used for any serious application development work nowadays (baring some weird exceptions).

Theoretically, 1-indexing has some real advantages to teaching coding.

Yeah... No. That ends up teaching something they will have to unlearn later.
Logged
Rubble 8 - The most powerful modding suite in existence!
After all, coke is for furnaces, not for snorting.
You're not true dwarven royalty unless you own the complete 'Signature Collection' baby-bone bedroom set from NOKEAS

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10838 on: April 18, 2018, 12:04:05 pm »

COBOL, Fortran, RPG, Sass, XPath/XQuery

You will note that none of those languages would be used for any serious application development work nowadays (baring some weird exceptions).

Weird exceptions... like being a frontend dev (Sass), doing ETL involving xml feeds (XPath), or any kind of work involving financial or legacy applications (the others).
Logged

milo christiansen

  • Bay Watcher
  • Something generic here
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10839 on: April 18, 2018, 12:25:23 pm »

Name one person who would willingly touch COBOL.

FORTRAN is mostly for math stuff, not at all mainstream.

XPath/XQuery? XML. Nothing more needs to be said. (XML is a remarkable example of bad design, everything XML can do can be done better with something else.)

I had never even heard of RPG before, which says quite a lot about it when you consider how many languages I have been exposed to at one time or another.

SASS really has no excuse, since it is intended to be used in the same apps as JavaScript, which is 0 based. So I'll chalk that up to plan ol' bad design as well.

Out of that list, it is remarkable that you can only find 3 (if you count Lua) that are commonly used today.
Logged
Rubble 8 - The most powerful modding suite in existence!
After all, coke is for furnaces, not for snorting.
You're not true dwarven royalty unless you own the complete 'Signature Collection' baby-bone bedroom set from NOKEAS

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10840 on: April 18, 2018, 12:31:11 pm »

Name one person who would willingly touch COBOL.

FORTRAN is mostly for math stuff, not at all mainstream.

XPath/XQuery? XML. Nothing more needs to be said. (XML is a remarkable example of bad design, everything XML can do can be done better with something else.)

I had never even heard of RPG before, which says quite a lot about it when you consider how many languages I have been exposed to at one time or another.

SASS really has no excuse, since it is intended to be used in the same apps as JavaScript, which is 0 based. So I'll chalk that up to plan ol' bad design as well.

Out of that list, it is remarkable that you can only find 3 (if you count Lua) that are commonly used today.

This whole thing comes across as quite condescending. I only mentioned those five (not three) because they're the ones I have experience with.

None of the rest of your post is contributing anything besides "RAR RAR I dislike this language therefore it isn't mainstream."

The fact of the matter is, if you're working in an enterprise environment, you put this shit aside. XML is horrible? Too bad. Enterprise. SASS has no excuse? Too bad, it's what we use. No one would willingly touch COBOL? I guess you hate money.
« Last Edit: April 18, 2018, 12:33:21 pm by Mephisto »
Logged

Araph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10841 on: April 18, 2018, 01:06:07 pm »

Theoretically, 1-indexing has some real advantages to teaching coding.
Yeah... No. That ends up teaching something they will have to unlearn later.
To be fair, everyone learns things they have to unlearn later.

While I agree that 0-indexing is preferable, I don't think letting students start arrays at 1 is particularly egregious. I've found it's usually not an issue to tell them to count from 0 right off the bat, though.
Logged

EnigmaticHat

  • Bay Watcher
  • I vibrate, I die, I vibrate again
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10842 on: April 18, 2018, 02:58:58 pm »

I think if we had a time machine 1 would be better, because that’s how people think.  But starting at 0 is the standard and memorizing one standard is easier than 2 standards.
Logged
"T-take this non-euclidean geometry, h-humanity-baka. I m-made it, but not because I l-li-l-like you or anything! I just felt s-sorry for you, b-baka."
You misspelled seance.  Are possessing Draignean?  Are you actually a ghost in the shell? You have to tell us if you are, that's the rule

Trekkin

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10843 on: April 18, 2018, 03:25:49 pm »

FORTRAN is mostly for math stuff, not at all mainstream.

Quite a lot of programming involves "math stuff" at some point, particularly in a scientific context. It's admittedly not what I'd code mobile games in, if that's what you're calling mainstream, but it's hardly marginal.

EDIT: Also, what Mephisto said. Yes, XML is horrible. Switching our software over would be more horrible, so nobody cares, beyond watching for an over-willingness to complain about languages to screen out unsuitable programmers. (That may sound more hostile than I meant it to. I simply mean that, insofar as a given application is concerned, the best language is the one that gets the results out the door fastest. Often that's the language in which the project has already been mostly coded, and it's good to be able to recognize that.)
« Last Edit: April 18, 2018, 03:48:10 pm by Trekkin »
Logged

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #10844 on: April 18, 2018, 03:46:32 pm »

I don't know about that being "conceptually" better than 1-indexing for lists.

A List of T can be thought of to be made of two parts: a Head of T and a Tail that is a List of T. List T = T ++ List T. So then your index is a count of how many times to recurse in your operations, like:
So to pseudohaskell it:
at :: N -> List T -> T
at = n -> (head ++ tail) -> at (n - 1) tail
at = 0 -> (head ++ tail) -> head

Or to put it in another way, N is how many steps to the right of the head you are accessing. A measure of distance, same as how an index on an array is an index of how many bytes to the right to move in the memory.

Incidentally, languages like Haskell and Python seem to be picking up speed for the mathematical stuff over FORTRAN, at least for newer more greenfield work. Functional patterns as a whole are really entering the mainstream. With LINQ in C#, Streams in Java, ReactiveX in...every language ever apparently (but Angular adopted them as first class citizens) and with React/Redux is a common combo (also a pretty nifty combo, React/Redux is pretty a nice pattern for building UIs). The newer type systems are starting to get the stronger guarantees, or ways to add them. C++ is even getting std::optional, which is basically a maybe monad! I would love to never need to see a naked null reference again :)

I do wish that the mathematicians hadn't got to name everything first, if only because sentences like "A monad is a monoid in the category of endofunctors" really don't help explain it xD
« Last Edit: April 18, 2018, 05:30:37 pm by MorleyDev »
Logged
Pages: 1 ... 721 722 [723] 724 725 ... 796