|
JavaScript is a scripting language. It interacts with an interpreter, such as a browser or node.js. If you want to stretch things, it's similar to a runtime, not wholly dissimilar to .NET or JRE.
Ergo: JavaScript is to browser as C# is to .NET
Now, when I said that I can't "wrap my head around" using TypeScript, I'm basically saying that I don't know why I would want to use VB.NET instead of C#, when I'm already an expert at C#. Or worse, why I would write something in VB, transpile it into C#, and then evaluate it against the runtime.
"Never attribute to malice that which can be explained by stupidity."
- Hanlon's Razor
|
|
|
|
|
that is the traditional way to look at javascript, but i find it's not nearly enough to conceptualize it that way anymore, but then like i alluded to, asm.js influenced by thinking on that.
Nathan Minier wrote:
Now, when I said that I can't "wrap my head around" using TypeScript, I'm basically saying that I don't know why I would want to use VB.NET instead of C#, when I'm already an expert at C#
Well I can think of one reason in this case - type checking, but that doesn't hold to your analogy since both C# and VB.NET do it.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
honey the codewitch wrote: Well I can think of one reason in this case - type checking,
Type safety is a compilation-level feature, as any bad cast will tell you very quickly. It has exactly zero impact on well-behaved code, it's just a development tool.
Coding against JS means handling type cases at runtime, which is the proper way to approach a duck type language.
I would argue that by trying to make the language look like something that it is not, TypeScript encourages bad code practices.
"Never attribute to malice that which can be explained by stupidity."
- Hanlon's Razor
|
|
|
|
|
That's an interesting argument. I don't necessarily agree but I do see where you're coming from.
But given my views on the JS/RTE as a "VM in disguise" we'll just have to disagree there.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
if you had a choice, would you rather port Typescript to C#, or javascript to C#?
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Why would I port them?
My front-end code would do absolutely nothing in back-end C#
|
|
|
|
|
i mean just in general.
as i said i ported a Splay tree function from typescript to C# and it went beautifully.
i was impressed by TS for that.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
In a complete hypothetical case that will almost never happen I would prefer to port TypeScript to C# rather than JavaScript.
But I'm not going to write all my front-end code in TypeScript in case I'll ever have to.
The only reason I'd use TypeScript is because some people really can't handle the dynamic nature of JavaScript.
So it's more a tool to "fix" the incompetence of others (I have a very specific someone in mind because I once had to use some JavaScript he wrote )
Who the hell has three different return types for a single function!?
|
|
|
|
|
Sander Rossel wrote: Who the hell has three different return types for a single function!?
Do you really have to ask me that? Who do you think would do something so diabolical?
Sander Rossel wrote: But I'm not going to write all my front-end code
A splay tree isn't front end specific and frankly I have no idea why someone wrote it in typescript.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
honey the codewitch wrote: Do you really have to ask me that? Who do you think would do something so diabolical? Even you know better than that!
Despite your complete lack of code sanitation I actually hold you in pretty high regard
Don't get any ideas though, I'll still prick you with my pitchfork.
That sounded better in my head
honey the codewitch wrote: and frankly I have no idea why someone wrote it in typescript. Exactly my point!
|
|
|
|
|
Sander Rossel wrote: Despite your complete lack of code sanitation I actually hold you in pretty high regard
However, that will change when you see my C# ISAM database code.
In any case, you're being sweet. I won't hex you today.
As far as writing splay trees in typescript i guess one could ask why write a database engine in c#?
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
honey the codewitch wrote: why write a database engine in c# Why not? It does the job
honey the codewitch wrote: In any case, you're being sweet. I won't hex you today. Probably because it's weekend and I don't have the energy to be mean
honey the codewitch wrote: my C# ISAM database code You still wrote it though.
|
|
|
|
|
Sander Rossel wrote: You still wrote it though.
Am writing it. Trying to do B+ trees. And once i get them working for in-memory i have to make them diskable, and you can't just use serialization. You have to keep an open file pointer and seek periodically and read/write the blocks you need. It's that kind of file I/O, so i'm still a ways off. I hope to have the B+ tree at least solidly in progress by tonight but we'll see.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
here's the main render loop for Prang Replay, my midi looper for FL Studio
void _stdcall Replay::Gen_Render(PWAV32FS DestBuffer, int &Length) {
unsigned long long p = looper.pos;
int bts = looper.beats;
float bps = looper.tempo / 60;
float spb = looper.sampleRate / bps;
unsigned long long i = 0;
midi_message midi;
vector<Loop>& loops = looper.loops;
if (1 < loops.size() && looper.rol != looper.ror) {
if(looper.rol) {
loops.push_back(*loops.begin());
loops.erase(loops.begin());
if (-1 < looper.lastPushIndex) {
--looper.lastPushIndex;
if (0 > looper.lastPushIndex)
looper.lastPushIndex += looper.loops.size();
}
looper.rol = false;
}
if(looper.ror) {
loops.insert(loops.begin(), (*(loops.end() - 1)));
loops.pop_back();
if (-1 < looper.lastPushIndex) {
++looper.lastPushIndex;
if ((int)looper.loops.size() <= looper.lastPushIndex)
looper.lastPushIndex -= looper.loops.size();
}
looper.ror = false;
}
}
else
looper.rol = looper.ror = false;
if(looper.push) {
if (0xFFFFFFFFFFFFFFFF!=looper.tapPos) { unsigned long long len = p - looper.tapPos;
i = (unsigned long long)ceil(len / spb);
i = ((unsigned long long)ceil(i / bts))*bts; bts = (int)i;
if (0 == bts)
bts = looper.beats;
}
if (bts)
{
unsigned long long bp = p;
vector<midi_event>::iterator it = looper.events.end() - 1;
vector<midi_event>::iterator cur = it;
unsigned long long bl = (unsigned long long)(spb*bts);
unsigned long long bs = bp - bl;
if (looper.events.size()) {
while ((*it).pos > bs) {
--it;
if (looper.events.begin() == it)
break;
}
while (looper.events.end() != it && it->pos < bs)
++it;
}
Loop loop;
loop.eventIndex = 0;
loop.length = bl;
loop.pos = 0;
if (looper.events.size()) {
while (it <= cur) {
midi_event ev(*it);
ev.pos -= bs;
loop.events.push_back(ev);
++it;
}
}
loops.push_back(loop);
looper.hanging = looper.keyContext; looper.lastPushIndex = loops.size() - 1;
}
looper.push = 0;
looper.tapPos = 0xFFFFFFFFFFFFFFFF;
pEditor->ParamsToControls();
}
vector<Loop>::iterator it = loops.begin();
while (it != loops.end()) {
Loop& loop = (*it);
int lec = loop.events.size();
if (lec) {
while (loop.eventIndex >= lec)
loop.eventIndex -= lec;
unsigned long long n = Length + loop.pos;
int nc = 0;
while (true) {
unsigned long long lp = loop.events[loop.eventIndex].pos;
if (lp < loop.pos)
lp += loop.pos;
if(lp<n) {
midi = loop.events[loop.eventIndex].midi;
loop.noteCounter.process_message(midi);
looper.noteCounter.process_message(midi);
midi = looper.noteCounter.filter_message(midi);
if (looper.enabled && midi.status)
PlugHost->MIDIOut_Delayed(HostTag, (int)midi);
}
else break;
++loop.eventIndex;
if (loop.eventIndex >= lec)
loop.eventIndex -= lec;
++nc; if (nc == lec) break;
}
loop.pos += Length;
if (loop.pos > loop.length)
loop.pos -= loop.length;
} else
it->pos+=Length;
while (it->pos >= it->length)
it->pos -= it->length;
++it;
}
while ((size_t)looper.eventIndex < looper.events.size()) {
midi_event e(looper.events[looper.eventIndex]);
if (Length <= e.pos - p)
break;
looper.noteCounter.process_message(e.midi);
looper.incomingNoteCounter.process_message(e.midi);
midi_message m = looper.noteCounter.filter_message(e.midi);
if(looper.enabled && 0!=m.status)
PlugHost->MIDIOut_Delayed(HostTag, (int)m);
++looper.eventIndex;
}
if(looper.pop) {
if (loops.size()) {
Loop* ploop = &(*loops.rbegin());
for (int i = 0; i < 16; ++i) { for (int j = 0; j < 128; ++j) { looper.noteCounter.note[i][j]-=ploop->noteCounter.note[i][j];
if (looper.noteCounter.note[i][j] <= 0 && ploop->noteCounter.note[i][j] > 0) {
looper.noteCounter.note[i][j] = 0;
midi_message m;
m.extra = midiOut;
m.status = 0x80 | i;
m.data1 = j;
m.data2 = 0;
PlugHost->MIDIOut_Delayed(HostTag, (int)m); }
}
}
loops.pop_back();
}
if (looper.loops.size() == looper.lastPushIndex)
--looper.lastPushIndex;
looper.pop = 0;
}
looper.pos += Length;
Length = 0;
}
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
No - it's long gone.
Is it OK if I use one of yours, instead?
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
use the above. It frightens animals and small children.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
No, but I remember what it was.
Duff's device laid on top of an if-else.
|
|
|
|
|
+1 I had to look up Duff's device. I've done it before, but i never knew it had a name.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
I believe this was the function that made me completely reevaluate my approach to parsing. Ultimately, I came up with something FAR simpler, that wasn't going to be a nightmare to change when adding another condition to the code.
bool parser::parseExecute()
{
tokStruct_ *workTokStack;
precedence_ *workPrecStack;
int numTok=0, numPrec=0;
tokStackPos = -1;
if (!setupTokStackMem(&workTokStack, ansStackAlloc) ||
!setupPrecStackMem(&workPrecStack, ansStackAlloc)) {
MsgBox("Unable to allocate memory in ExecuteToken");
return false;
}
workPrecStack[0] = PrecGet;
workTokStack[0].token = TokGet;
do {
++tokStackPos;
if (tokStack[tokStackPos].token == TokValue) {
ansStack[++ansStackPos] = valStack[tokStack[tokStackPos].varListPos];
continue;
}
if (tokStack[tokStackPos].token == Tok0DimVar) {
ansStack[++ansStackPos] = getValFromVarList();
continue;
}
if (tokStack[tokStackPos].token == TokMDimVarEnd) {
if (workTokStack[tokStackPos-1].token == TokMDimVarAssign) break;
if (workTokStack[tokStackPos-1].token != TokMDimVar) {
MsgBox("']' encountered without arrayed variable");
return moveCursorToError(origStr);
}
int Y, Z, pos, dim;
Y = varList[workTokStack[numTok-1].varListPos].Y;
Z = varList[workTokStack[numTok-1].varListPos].Z;
dim = varList[workTokStack[numTok-1].varListPos].varDim;
if (dim == 1) pos = ansStack[ansStackPos];
else if (dim == 2) pos = ansStack[ansStackPos-1] +
ansStack[ansStackPos]*Y;
else if (dim == 3) pos = ansStack[ansStackPos-2] +
ansStack[ansStackPos-1]*Y + ansStack[ansStackPos]*Y*Z;
ansStackPos = ansStackPos-dim+1;
if (varList[workTokStack[numTok-1].varListPos].varType == Int) {
ansStack[ansStackPos] =
*((int*)(varList[workTokStack[numTok-1].varListPos].varAddress)+pos);
}
else if (varList[workTokStack[numTok-1].varListPos].varType == Double) {
ansStack[ansStackPos] =
*((double*)(varList[workTokStack[numTok-1].varListPos].varAddress)+pos);
}
else {
MsgBox("Bad varType placed on ansStack");
return moveCursorToError(origStr);
}
ansStackPos++;
numTok--; continue;
}
++numTok; ++numPrec;
workTokStack[numTok] = tokStack[tokStackPos];
workPrecStack[numPrec] = precStack[tokStackPos];
if (workTokStack[numTok].token == TokLParen) continue;
while (workPrecStack[numPrec-1] >= workPrecStack[numPrec]) {
workPrecStack[numPrec-1] = workPrecStack[numPrec];
numPrec--;
switch (workTokStack[numTok-1].token) {
case TokValue: ansStack[++ansStackPos] =
*(double*)varList[workTokStack[numTok-1].varListPos].varAddress;
numTok++;
numPrec++;
tokStackPos++;
break;
case TokVarAssign: if (ansStackPos != 0) {
MsgBox("Malformed statement");
delete workTokStack;
delete workPrecStack;
return false;
}
*(double*)varList[workTokStack[numTok-1].varListPos].varAddress = ansStack[0];
numTok=numTok-2;
numPrec--;
ansStackPos--;
goto pETBreakout;
case TokAdd: ansStack[ansStackPos-1] = ansStack[ansStackPos-1] + ansStack[ansStackPos];
ansStackPos--;
numTok--;
break;
case TokSubtract:
ansStack[ansStackPos-1] = ansStack[ansStackPos-1] - ansStack[ansStackPos];
ansStackPos--;
numTok--;
break;
case TokMultiply:
ansStack[ansStackPos-1] = ansStack[ansStackPos-1] * ansStack[ansStackPos];
ansStackPos--;
numTok--;
break;
case TokDivide:
ansStack[ansStackPos-1] = ansStack[ansStackPos-1] / ansStack[ansStackPos];
ansStackPos--;
numTok--;
break;
case TokPower:
ansStack[ansStackPos-1] = pow(ansStack[ansStackPos-1], ansStack[ansStackPos]);
ansStackPos--;
numTok--;
break;
case TokSemiCol: if (ansStackPos != 0) {
MsgBox("Misformed Statement");
delete workTokStack;
delete workPrecStack;
return false;
}
ansStackPos--;
break;
case TokComma:
numTok--;
break;
case TokLParen:
if (tokStack[tokStackPos].token == TokLParen &&
tokStack[tokStackPos-1].token == TokLParen) {
numPrec++;
goto pETBreakout;
}
numTok=numTok-2;
numPrec--;
goto pETBreakout;
case TokRParen:
break;
case TokMDimVar:
int Y, Z, pos, dim;
Y = varList[workTokStack[numTok-1].varListPos].Y;
Z = varList[workTokStack[numTok-1].varListPos].Z;
dim = varList[workTokStack[numTok-1].varListPos].varDim;
if (dim == 1) pos = ansStack[ansStackPos-1];
else if (dim == 2) pos = ansStack[ansStackPos-2] +
ansStack[ansStackPos-1]*Y;
else if (dim == 3) pos = ansStack[ansStackPos-3] +
ansStack[ansStackPos-2]*Y + ansStack[ansStackPos-1]*Y*Z;
if (varList[workTokStack[numTok-1].varListPos].varType == Int) {
*((int*)(varList[workTokStack[numTok-1].varListPos].varAddress)+pos) =
ansStack[ansStackPos];
}
else if (varList[workTokStack[numTok-1].varListPos].varType == Double) {
*((double*)(varList[workTokStack[numTok-1].varListPos].varAddress)+pos) =
ansStack[ansStackPos];
}
else {
MsgBox("Bad varType placed on ansStack");
return moveCursorToError(origStr);
}
ansStackPos = ansStackPos-dim;
numTok--; continue;
default:
MsgBox("Still Programming!");
delete workTokStack;
delete workPrecStack;
return false;
}
workTokStack[numTok] = workTokStack[numTok+1];
} pETBreakout:
} while (workPrecStack[numPrec] != PrecEnd);
delete workPrecStack; workPrecStack = NULL;
delete workTokStack; workTokStack = NULL;
return true;
}
|
|
|
|
|
yeah, two stacks is complicated.
you should just need the one at most (not even that if you're borrowing *the* stack (call stack) using recursive descent.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Pfft. That's art to the stuff I've written. My stuff is so bad if I posted it here your computer would keel over in fright and refuse to reboot.
cheers
Chris Maunder
|
|
|
|
|
I'm glad i'm not the only target of Sander and his pitchfork.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Yes you are.
Speaking of which...
|
|
|
|
|
i'll turn you into a VB6 developer
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Been there done that
|
|
|
|