Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
ToxicFrog
Apr 26, 2008


abraham linksys posted:

:confused: This is basically "client-side templating 101." Though really, "reconstruction of data" shouldn't be needed if you have an API that's spitting out a format your JS/templates consume, and it can get ugly if it's an ad-hoc implementation and not based on one of many libraries that do this.

It's done so that no duplication of effort is required when making web applications that have lots of front-end interaction. You generally don't want to have to have both server- and client- side templates doing the same thing.

(of course if this is a mostly static page with no rich interactivity then yeah it's way more effort than it's worth :v:)

Yeah, that's the thing - this is an ad-hoc implementation, not reused (or reusable) anywhere. Client-side interactivity consists of choosing which table to display and which column to sort by, both of which can trivially be done by rendering the data straight into the page as a table and then adding five lines of JS that invoke the library we already have specifically for doing this. (The "reconstruction of data" part occurs because there's a bunch of derived information that is already calculated in Python, but rather than rendering that into the template they just insert the raw data and then JS duplicates all of the existing Python logic to derive that information again).

We have a perfectly good server-side templating system, and we have existing JS libraries for sortable tables and select-a-div-from-a-dropdown. This service implements something that normally involves ~50 lines of template and ~5 lines of JS using ~30 lines of template, ~300 lines of JS, and multiple extra layers of indirection (all of which must be modified if you want to, say, add a new column to the table).

Adbot
ADBOT LOVES YOU

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
So, Verizon has a large system internally called "DTI" that is one of the tools that field techs and support call technicians use to diagnose issues with the network. I contracted on this system for quite a while before moving on, but I still occasionally get billed part-time to help out if they can't debug issues.

They recently started moving some of their servers from Solaris/Tomcat to Linux/WebSphere and were hitting a problem: during a stress test, they hit a "too many open files" warning. A simple lsof/netstat showed that there were a lot of sockets in TIME_WAIT. I asked them what those sockets were, and they said "yes, that's the return socket where traffic goes over".

Me: "Wait, if it's the return socket, why does it have a port number of 8188"

Them: "Uh, the return socket has a well-known port of 8188."

I press a bit more, dig into some previously-untouched code, and what do I find: (paraphrasing here because the actual project spans over 200 classes, Oh, Java... I might also get the details of the Java socket API wrong, but hopefully you understand here)

Java code:
public void sendPacket(Host host, Port port, Packet packet, int total) {
    Envelope envelope = new Envelope();
    envelope.setDestinationHost(host);
    envelope.setDestinationPort(port);
    envelope.setEndPacketId(total);
    envelope.setPacketData(++packetID);
    envelope.setReturnSocket(8188);

    byte packetData[] = envelope.getBytes();
    assert(packetData.size < 256);
    outStream.send(packetData);
}

public void sendMessage(Host host, Port port, Message message) {
    SocketServer returnSocket = new SocketServer(handleReturnPacket, 8188);
    returnSocket.open();

    byte messageData[] = message.getBytes();
    int nPackets = message.size / 240; /* packet header takes 16 bytes */
    for (int i = 0; i < messageData.size; i += 240) {
        Packet packet = new Packet();
        byte packetData[240];
        System.arraycopy(packetData, messageData, i, 240);
        packet.setData(packetData);
        sendPacket(host, port, packet, nPackets);
    }
}

public void handlePacket(InputStream is) {
    Envelope envelope = new Envelope();
    envelope.recvFromStream(is);
    bufferUntil(envelope, envelope.getEndPacket());
    returnSocket.close();
}
So, yes, for every message they wanted to send, they split it into packets, gave each one an ID, and opened a socket for the incoming packets back on a well-known port. The server would then take all these packets, buffer them until they had a message, and then if it wanted to reply, open a socket connection back to the originating server, that information being in the packet header, splitting across data the same way.

In other words, they reinvented TCP on top of TCP.

I hate that people learn the word "packet" when it comes to networking. YOU DO NOT NEED TO CARE ABOUT PACKETS. The abstraction layer TCP gives you is a bidirectional stream of bytes. grr.... this isn't the first time I've seen this, either.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
http://docs.unity3d.com/Documentation/ScriptReference/GameObject.html

Unity documentation doesn't use real links. The links are of the form <a onclick="loadPage('GameObject-activeInHierarchy'); return false;" href="">activeInHierarchy</a>, which means that middle clicking on them to open them in the background does not work.

Why would you even do that?

Rottbott
Jul 27, 2006
DMC

Suspicious Dish posted:

I hate that people learn the word "packet" when it comes to networking. YOU DO NOT NEED TO CARE ABOUT PACKETS. The abstraction layer TCP gives you is a bidirectional stream of bytes. grr.... this isn't the first time I've seen this, either.
Sometimes you actually want a packet though.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Rottbott posted:

Sometimes you actually want a packet though.

In TCP? Nope. The abstraction layer that TCP gives you is a bidirectional stream of bytes. These are built using packets, but there's no reason to sneak under the hook. If you want datagram messaging, you can use UDP, but that does not guarantee reliability or ordering or anything else.

Dren
Jan 5, 2001

Pillbug

Suspicious Dish posted:

Java code:
public void sendPacket(Host host, Port port, Packet packet, int total) {
    Envelope envelope = new Envelope();
    envelope.setDestinationHost(host);
    envelope.setDestinationPort(port);
    envelope.setEndPacketId(total);
    envelope.setPacketData(++packetID);
    envelope.setReturnSocket(8188);

    byte packetData[] = envelope.getBytes();
    assert(packetData.size < 256);
    outStream.send(packetData);
}

public void sendMessage(Host host, Port port, Message message) {
    SocketServer returnSocket = new SocketServer(handleReturnPacket, 8188);
    returnSocket.open();

    byte messageData[] = message.getBytes();
    int nPackets = message.size / 240; /* packet header takes 16 bytes */
    for (int i = 0; i < messageData.size; i += 240) {
        Packet packet = new Packet();
        byte packetData[240];
        System.arraycopy(packetData, messageData, i, 240);
        packet.setData(packetData);
        sendPacket(host, port, packet, nPackets);
    }
}

public void handlePacket(InputStream is) {
    Envelope envelope = new Envelope();
    envelope.recvFromStream(is);
    bufferUntil(envelope, envelope.getEndPacket());
    returnSocket.close();
}

Won't nPackets truncate unless message.size is a multiple of 240, causing the header to contain an EndPacketId that is 1 short?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
As I said, the actual code is 20 classes tall (and some of them look like this); that's just some made up stuff that gets the spirit of it.

Dren
Jan 5, 2001

Pillbug

Suspicious Dish posted:

(and some of them look like this);

Holy poo poo.

:suicide:

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Suspicious Dish posted:

As I said, the actual code is 20 classes tall (and some of them look like this); that's just some made up stuff that gets the spirit of it.

:gonk:

I actually made that face when I saw that code. If any code cried out for refactoring, that would be it!

EntranceJew
Nov 5, 2009

Wheany posted:

http://docs.unity3d.com/Documentation/ScriptReference/GameObject.html

Unity documentation doesn't use real links. The links are of the form <a onclick="loadPage('GameObject-activeInHierarchy'); return false;" href="">activeInHierarchy</a>, which means that middle clicking on them to open them in the background does not work.

Why would you even do that?

Apparently this is really popular for whatever reason. I don't know. I do know that the other places I have seen this done uses the javascript links inside their help files as well. Maybe that is why?

Bobbin Threadbear
May 6, 2007

Wheany posted:

http://docs.unity3d.com/Documentation/ScriptReference/GameObject.html

Unity documentation doesn't use real links. The links are of the form <a onclick="loadPage('GameObject-activeInHierarchy'); return false;" href="">activeInHierarchy</a>, which means that middle clicking on them to open them in the background does not work.

Why would you even do that?

I wonder if they did that with the intention of hindering scraping of their website? I can't think of another reason you would do that.

ephphatha
Dec 18, 2009




code:
get_parmeter
gently caress this code base.

PrBacterio
Jul 19, 2000

Ephphatha posted:

code:
get_parmeter
gently caress this code base.
Oh the fun you would have with the code base at my place of work. If even that (comparatively) insignificant little spelling mistake is enough to set you off I'd like to see your reaction to the kind of stuff I deal with every day :allears:

Flaming June
Oct 21, 2004

"Latitude" apparently has three t's in it, I have found.

ephphatha
Dec 18, 2009




PrBacterio posted:

Oh the fun you would have with the code base at my place of work. If even that (comparatively) insignificant little spelling mistake is enough to set you off I'd like to see your reaction to the kind of stuff I deal with every day :allears:

Oh, it's not this one occasion. Every program that abbreviates the word parameter uses the abbreviation "parm". This is the first time I've seen the full word spelled that way though.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
Some C# code bases I've seen have "parms" variables littered across it. My guess is that they actually wanted to say "params" but couldn't because that's a C# keyword.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Bognar posted:

Some C# code bases I've seen have "parms" variables littered across it. My guess is that they actually wanted to say "params" but couldn't because that's a C# keyword.

Except you can use keywords as variable names by prefixing them with "@". You shouldn't, but you can.

Opinion Haver
Apr 9, 2007

I've always hated 'klass'.

Scaevolus
Apr 16, 2007

Suspicious Dish posted:

In TCP? Nope. The abstraction layer that TCP gives you is a bidirectional stream of bytes. These are built using packets, but there's no reason to sneak under the hook.

Performance concerns constantly motivate peeking under the hood. The internet would collapse in a storm of congestion without Nagle's algorithm, yet latency-critical applications need ways to forcibly flush.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Scaevolus posted:

Performance concerns constantly motivate peeking under the hood. The internet would collapse in a storm of congestion without Nagle's algorithm, yet latency-critical applications need ways to forcibly flush.

Sure, abstractions are leaky and if you're implementing any serious realtime system you need to understand the congestion/latency tradeoff. But that's something you can really only can be taught once you already understand TCP.

Building your own packet protocol and bidirectional stream-of-bytes transport that opens a new listening socket on every message on top of TCP is crazy. TCP gives you exactly that. They clearly don't understand TCP well enough to poke start to under it.

That's why I feel like ever mentioning the word "packet" to people beginning to learn basic network programming is a serious disservice. Poke at that later, but for now, it's like a file that you can read from and write to and it magically pops out on the other side!

HORATIO HORNBLOWER
Sep 21, 2002

no ambition,
no talent,
no chance

Opinion Haver posted:

I've always hated 'klass'.

clazz :barf:

pseudorandom name
May 6, 2007

dass

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Gonna start using this in my reflection code from now on.

Goat Bastard
Oct 20, 2004


This is the worst

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
cIass

Rottbott
Jul 27, 2006
DMC

Suspicious Dish posted:

In TCP? Nope. The abstraction layer that TCP gives you is a bidirectional stream of bytes. These are built using packets, but there's no reason to sneak under the hook. If you want datagram messaging, you can use UDP, but that does not guarantee reliability or ordering or anything else.
I know all that. I'm not defending building TCP on top of TCP. What I mean is, sometimes what you actually want to send is a packet with a clearly defined start and end (e.g. you are sending a bunch of small unrelated messages). You could use UDP (I do), but you might also want reliability, which you then have to do yourself. So you might end up making a packet based protocol on top of a stream based protocol on top of a packet based protocol...

it is
Aug 19, 2011

by Smythe
I'm leading :siren:MY BOYFRIEND:siren: through the first CS class in the major and we're in a unit dealing with loops. He has to draw an ascii figure that looks like:
pre:
#================#
|      <><>      |
|    <>....<>    |
|  <>........<>  |
|<>............<>|
|<>............<>|
|  <>........<>  |
|    <>....<>    |
|      <><>      |
#================#
with the idea that it is scalable. So they want something like
code:
for(int i = 1; i <= -2 * spaces + (lines * 2); i++) System.out.print(" ");
System.out.print("<>");
for(int i = 1; i <= lines * line; i++) System.out.print(".");
System.out.print("<>");
for(int i = 1; i <= -2 * spaces + (lines * 2); i++) System.out.print(" ");
System.out.println("|");
and he's basically got it, but he's wrapping the System.out.print("<>") calls in a loop from 1 to 1. It's cute but I don't know if my responsibility as a teacher is to say "loops of length 1 are bad" or if I should let him get more comfortable with loop syntax and logic and then work on improving his style.

Nippashish
Nov 2, 2005

Let me see you dance!

it is posted:

code:
for(int i = 1; i <= -2 * spaces + (lines * 2); i++) System.out.print(" ");
System.out.print("<>");
for(int i = 1; i <= lines * line; i++) System.out.print(".");
System.out.print("<>");
for(int i = 1; i <= -2 * spaces + (lines * 2); i++) System.out.print(" ");
System.out.println("|");

Code review style feedback is always a good idea, maybe ask him what the purpose of a loop from 1 to 1 is.

Additionally, it most definitely is your responsibility as a teacher to write example code like you'd write real code and not, as you've done here, like you're painting a mural.

distortion park
Apr 25, 2011


This was annoying.
code:
      do i=1,numatms

        if(atmnam(i)(1:1).eq."K")then
          atmnam(i)="K"
        else if(atmnam(i)(1:2).eq."Ti")then
          atmnam(i)="Ti"
        else if(atmnam(i)(1:2).eq."Cl")then
          atmnam(i)="Cl"
        else if(atmnam(i)(1:2).eq."Ag")then
          atmnam(i)="Ag"
        else if(atmnam(i)(1:1).eq."I")then
          atmnam(i)="I"
        else if(atmnam(i)(1:1).eq."C")then
          atmnam(i)="C"
        else if(atmnam(i)(1:1).eq."N")then
          atmnam(i)="N"
        else if(atmnam(i)(1:1).eq."O")then
          atmnam(i)="O"
        else if(atmnam(i)(1:1).eq."H")then
          atmnam(i)="H"
	else if(atmnam(i)(1:1).eq."F")then
          atmnam(i)="F"
        endif

      enddo
Works fine normally if your element isn't on that list, say "Hg". If on the the other hand you happen to have some helium in your model you get a very frustrating bug. I'm sure doing it this way made sense at the time to someone but it doesn't anymore so I commented the whole thing out.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

it is posted:

I'm leading :siren:MY BOYFRIEND:siren: through the first CS class in the major and we're in a unit dealing with loops. He has to draw an ascii figure that looks like:
pre:
#================#
|      <><>      |
|    <>....<>    |
|  <>........<>  |
|<>............<>|
|<>............<>|
|  <>........<>  |
|    <>....<>    |
|      <><>      |
#================#
with the idea that it is scalable. So they want something like
code:
for(int i = 1; i <= -2 * spaces + (lines * 2); i++) System.out.print(" ");
System.out.print("<>");
for(int i = 1; i <= lines * line; i++) System.out.print(".");
System.out.print("<>");
for(int i = 1; i <= -2 * spaces + (lines * 2); i++) System.out.print(" ");
System.out.println("|");
and he's basically got it, but he's wrapping the System.out.print("<>") calls in a loop from 1 to 1. It's cute but I don't know if my responsibility as a teacher is to say "loops of length 1 are bad" or if I should let him get more comfortable with loop syntax and logic and then work on improving his style.

I want to throw curly braces at you like batarangs, especially because you're teaching someone how to code by example.

As to your actual question, I'd ask him why he's got loops of length one, and if it's because he thinks that he has to have a loop you should explain that he doesn't. Be sure to ask, though; he might surprise you with "Well, what if the teacher wants <><><> tomorrow?" in which case he'll make an excellent enterprise developer :3:

Hughlander
May 11, 2005

Scaevolus posted:

Performance concerns constantly motivate peeking under the hood. The internet would collapse in a storm of congestion without Nagle's algorithm, yet latency-critical applications need ways to forcibly flush.

No it wouldn't Nagling is really only useful for interactive terminal sessions. What percent of total traffic is that? These days almost all traffic has an entire packet worth of data or it's entire payload sent from a program at one time. In either case Nagle isn't invoked.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Hughlander posted:

No it wouldn't Nagling is really only useful for interactive terminal sessions. What percent of total traffic is that? These days almost all traffic has an entire packet worth of data or it's entire payload sent from a program at one time. In either case Nagle isn't invoked.

One of the biggest gains of SPDY over HTTP is not that it's compressed, but it uses a multiplexed socket for all its resources.

TCP handshakes are decently expensive, and HTTP does one for every single resource, so we had to invent weird hacks like script concatenation and sprite sheeting to do more with one TCP socket.

The modern web really run into Nagle.

Impotence
Nov 8, 2010
Lipstick Apathy

Suspicious Dish posted:

One of the biggest gains of SPDY over HTTP is not that it's compressed, but it uses a multiplexed socket for all its resources.

TCP handshakes are decently expensive, and HTTP does one for every single resource, so we had to invent weird hacks like script concatenation and sprite sheeting to do more with one TCP socket.

The modern web really run into Nagle.

What do you think about Google's new protocol (already being used), quic?

Hughlander
May 11, 2005

Suspicious Dish posted:

One of the biggest gains of SPDY over HTTP is not that it's compressed, but it uses a multiplexed socket for all its resources.

TCP handshakes are decently expensive, and HTTP does one for every single resource, so we had to invent weird hacks like script concatenation and sprite sheeting to do more with one TCP socket.

The modern web really run into Nagle.

But number of TCP connections has nothing to do with Nagle again. All Nagle says is that if you have less than a full packet of data you coalesce the packets until you receive an ack from the remote end or you have a full packet worth of data. If you were using HTTP to request 40 resources with Nagle or without you'd send the same number of TCP packets. Yes with SPDY, and HTTP Keepalive you'd use less over all packets, but Nagle on or off has no effect.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
By "run into Nagle" I meant run into his observation that there are still lots of TCP packets that are really small, and that TCP congestion is a serious problem.

Biowarfare posted:

What do you think about Google's new protocol (already being used), quic?

I haven't heard of it! Looks interesting, though, I'll read more about it.

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

it is posted:

and he's basically got it, but he's wrapping the System.out.print("<>") calls in a loop from 1 to 1. It's cute but I don't know if my responsibility as a teacher is to say "loops of length 1 are bad" or if I should let him get more comfortable with loop syntax and logic and then work on improving his style.

I'm teaching a buddy of mine, and he keeps saying "if loop". I think things like that are indicative that the concept hasn't completely hit home yet, so I did a bunch of practice with loops and conditionals and went over the difference and when they're each appropriate. It all seems obvious to us now years later, but its a lot to take in at first.

A loop of 1 definitely shows he's not quite got the idea, so I'd poke him on it a bit. Nothing too strong though, I like the suggestion of being socratic and just asking questions. "So why is that necessary?"

Another newbie problem he was making was turning everything into loops where they didn't need to be; sometimes he'd come up with the proper logic for something, but nest that within a loop unnecessarily.

I didn't learn debugging until later myself, but I think that's a mistake. Have you introduced him to debugging yet? Allowing him to set a breakpoint on the first instruction and just walk through the program each time he changes it can really help visualize and reinforce what the loops and control structures are doing to the flow of the program.

Dren
Jan 5, 2001

Pillbug
No experience teaching programming here but after I got my first real job out of college and learned to use gdb I was pissed that it hadn't been taught along with our c++ assignments. I'm interested as to what people's experiences with teaching a debugger alongside a language. I expect that when the school switched to java the debugger started being taught to beginners because it is tightly integrated with the IDE.

Fuck them
Jan 21, 2011

and their bullshit
:yotj:
The debugging I was taught was printf(); shenanigans since I started with C. Toward the end of my C class we finally used codeblocks' debugger to do step through, which was nice and helped me start to understand what was going on.

When I started to do Java we were pressured into using jGrasp (WHY?!?!?!?!?) and I had to on my own find out what IDEs were, why they were useful, and why the gently caress I'd ever bother using jGrasp because holy loving poo poo a lot of professors think harder is just better and are out of touch with industry. I won't even try to explain how badly we were taught OOP principles but suffice it to say that it was absolutely loving terrible. Thank gently caress that collections are easy and I had a good hand-holding with multi tier architecture, and for that matter, a perfect example of why you need IoC and loose coupling to get me up to speed.

The same jGrasp professor thought it would be a good idea to teach students to do C with PICO. Apparently vi is just too much loving effort?

I learned more from stackoverflow and CoC than school, and that's kind of a disappointment. I wish I had just picked some easy "CIS" or "MIS" degree to get the 4 year piece of parchment with a nice high GPA since I taught myself programming anyway. If I do finish my education it's just to get past HR departments that care anyway since I've been in the industry for a year now, but my god the bullshit that comes out of many schools is infuriating when you look at it from the perspective of not being a complete moron.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."

Zaphod42 posted:

I'm teaching a buddy of mine, and he keeps saying "if loop".

I've noticed this in my students on many occasions. My working theory is that it has something to do with the syntactic similarity between conditionals and loops in curly-bracket languages.

One of the strangest behaviors I have observed in lab courses is a behavior I call "soup programming", in which students read a problem description, add several loops, conditionals and variables to a procedure body and then proceed to spend half an hour rearranging those elements to try to get the result to compile, as if programming were a matter of selecting the correct ingredients and stirring. Usually when I help students who are doing this I tell them to step away from the keyboard and try to explain the problem and their approach to solving it verbally- if you can't explain something to a person you can't explain it to a computer.

Adbot
ADBOT LOVES YOU

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
The "if loop" idea sort of makes sense to me - while repeats 0 to N times, do ... while repeats 1 to N times, and if repeats 0 to 1 times. It's not a very useful way of thinking about things, but I'm not sure it's entirely wrong.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply