Open Side Menu Go to the Top

08-18-2016 , 10:42 PM
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
08-18-2016 , 10:56 PM
Quote:
Originally Posted by RustyBrooks
What? I like the first example and hate your last one. This is the problem with these standards imo, it's not like there's an objectively best/correct one.
in this particular example, i agree. i'm fine with either way.

but as a general rule, some things being more objectively more readable than others is possible. define readable, you say? well, actually making it objective might be hard, but you can imagine people hooked up to eye trackers or MRIs, and the results are probably going to lean strongly one way in some cases.

in the meantime, we have our gut feel as a proxy for objectivity, and fun religious wars!
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-18-2016 , 11:09 PM
Quote:
Originally Posted by suzzer99
wat
Not clear enough?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-18-2016 , 11:12 PM
Did you mean copy/paste?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-18-2016 , 11:44 PM
Quote:
Originally Posted by RustyBrooks
What? I like the first example and hate your last one. This is the problem with these standards imo, it's not like there's an objectively best/correct one.

Quote:
Originally Posted by suzzer99
Do you also like ketchup on hot dogs? Maybe we can find a correlation.

I like the first example and ketchup on hot dogs. Correlation confirmed.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-19-2016 , 12:22 AM
Ketchup is okay on a hot dog as long as there's 3 times as much mayo and mustard. I really don't care too much about indentation styles as long as it's consistent.

On another note, Bash on Ubuntu on Windows is amazing.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-19-2016 , 01:08 AM
My attempt at objectivity...

A?



or B?

** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-19-2016 , 01:26 AM
Clearly B.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-19-2016 , 01:44 AM
get a new editor
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-19-2016 , 02:03 AM
That was inspired by this fun read: http://robertheaton.com/2014/06/20/c...out-your-eyes/

SiQ, I code in Notepad++ with 18pt Comic Sans. No difficulties here.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-19-2016 , 02:05 AM
That article is very good.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-19-2016 , 02:30 AM
Having to code in comic sans would be a great punishment for a dev who submitted bad code.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-19-2016 , 02:34 AM
lol

Is there a fixed-width comic sans? If not double lol.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-19-2016 , 03:38 AM
Quote:
Originally Posted by RustyBrooks
That video is pretty good as far as standup programming comedy goes
The last example was presented the best but isn't really a WAT imo. Casting string plus number to a string is reasonable due to the semantic meaning of the + operator. There's no such meaning when it comes to strings for minus thus the result seems fine.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-19-2016 , 03:57 AM
Quote:
Originally Posted by daveT
That was inspired by this fun read: http://robertheaton.com/2014/06/20/c...out-your-eyes/

SiQ, I code in Notepad++ with 18pt Comic Sans. No difficulties here.
Lolol
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-19-2016 , 10:55 AM
Quote:
Originally Posted by suzzer99
Did you mean copy/paste?
yes
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-20-2016 , 12:35 AM
Code:
if (propertyDef.type && (propertyDef.type === 'integer' || propertyDef.type === 'number')) {
  outputBody = outputBody + "   this." + property + " = " + model + "." + property + " ? " + model + "." + property + " : " + property + " !== null && " + property + " !== undefined ? " + property + " : 0;\r\n";
} else if (propertyDef.type && propertyDef.type === 'boolean') {
  outputBody = outputBody + "   this." + property + " = " + model + "." + property + " ? " + model + "." + property + " : "  + property + " ? " + property + " : " + "false;\r\n";
} else if (propertyDef.type && propertyDef.type === 'array') {
  var arrayOf = propertyDef.items['$ref'].replace('#/definitions/', '');
  outputBody = outputBody + "   this." + property + " = " + model + "." + property + " ? " + model + "." + property + " : "  + property + " ? " + property + " : []; // of '" + arrayOf + "';\r\n";
} else if (propertyDef.type && propertyDef.type === 'object') {
  outputBody = outputBody + "   this." + property + " = " + model + "." + property + " ? " + model + "." + property + " : "  + property + " ? " + property + " : {};\r\n";
} else if (propertyDef['$ref']) {
  needsModelFactory = true;
  var nestedObject = propertyDef['$ref'].replace('#/definitions/', '');
  outputBody = outputBody + "   this." + property + " = " + model + "." + property + " ? " + model + "." + property + " : "  + property + " ? " + property + " : new modelFactory." + nestedObject + "();\r\n";
} else if( propertyDef.format && propertyDef.format === 'date-time' ) {
  outputBody = outputBody + "   this." + property + " = " + model + "." + property + " ? " + model + "." + property + " : "  + property + " ? " + property + " : " + "'1985-04-12T23:20:50.52Z';\r\n";
} else {
  outputBody = outputBody + "   this." + property + " = " + model + "." + property + " ? " + model + "." + property + " : "  + property + " ? " + property + " : " + "'';\r\n";
}
Objectively good or not good?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-20-2016 , 12:58 AM
You can't tell?

I mean, if it works it works. Could certainly be refactored though...
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-20-2016 , 01:05 AM
Sorry, I'm drinking and you are obviously joking.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-20-2016 , 03:17 AM
Quote:
Originally Posted by suzzer99
Code:
if (propertyDef.type && (propertyDef.type === 'integer' || propertyDef.type === 'number')) {
  outputBody = outputBody + "   this." + property + " = " + model + "." + property + " ? " + model + "." + property + " : " + property + " !== null && " + property + " !== undefined ? " + property + " : 0;\r\n";
} else if (propertyDef.type && propertyDef.type === 'boolean') {
  outputBody = outputBody + "   this." + property + " = " + model + "." + property + " ? " + model + "." + property + " : "  + property + " ? " + property + " : " + "false;\r\n";
} else if (propertyDef.type && propertyDef.type === 'array') {
  var arrayOf = propertyDef.items['$ref'].replace('#/definitions/', '');
  outputBody = outputBody + "   this." + property + " = " + model + "." + property + " ? " + model + "." + property + " : "  + property + " ? " + property + " : []; // of '" + arrayOf + "';\r\n";
} else if (propertyDef.type && propertyDef.type === 'object') {
  outputBody = outputBody + "   this." + property + " = " + model + "." + property + " ? " + model + "." + property + " : "  + property + " ? " + property + " : {};\r\n";
} else if (propertyDef['$ref']) {
  needsModelFactory = true;
  var nestedObject = propertyDef['$ref'].replace('#/definitions/', '');
  outputBody = outputBody + "   this." + property + " = " + model + "." + property + " ? " + model + "." + property + " : "  + property + " ? " + property + " : new modelFactory." + nestedObject + "();\r\n";
} else if( propertyDef.format && propertyDef.format === 'date-time' ) {
  outputBody = outputBody + "   this." + property + " = " + model + "." + property + " ? " + model + "." + property + " : "  + property + " ? " + property + " : " + "'1985-04-12T23:20:50.52Z';\r\n";
} else {
  outputBody = outputBody + "   this." + property + " = " + model + "." + property + " ? " + model + "." + property + " : "  + property + " ? " + property + " : " + "'';\r\n";
}
Objectively good or not good?
I don't think this works - it seems to take some kind of a json schema and generates code along the lines of:

Code:
this.someField = model.someField ? model.someField : isNotNullOrUndefined(someField) : someField : defaultValueForType
Code generators are fairly tricky to write and there are enough mistakes and sloppiness, for example:

----
1. Why check for truthiness for propertyDef.type if you're going to check for specific values?
2. In the generated code, why is checking truthiness good enough for model.someField but not good enough for someField?
3. Why would someField, whatever it is, exist as a global value? This whole checking in the model first, but then looking in the global namespace, is fairly fishy given that schemas are used for validation.
4. The code generated in the definition case is wrong in the actual nested case (nestedObject could be something like "field/definitions/otherfield" in which case the generated code would look like:
Code:
new modelFactory.field/definitions/otherfield()
which is unlikely to be valid in any language. I think the intention was for the model factory to resolve definitions but in that case, why "new" as opposed to referencing an existing object from the context?
5. Why repeat the exact same logic so many times?
----

that it's hard to believe that this person has the problem under control. Given the overall sloppiness and the general improbability of code generators being the right solution for problems we typically encounter in the wild, I don't think this person is on the right track.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-20-2016 , 03:22 AM
Quote:
Originally Posted by suzzer99
Code:
if (propertyDef.type && (propertyDef.type === 'integer' || propertyDef.type === 'number')) {
  outputBody = outputBody + "   this." + property + " = " + model + "." + property + " ? " + model + "." + property + " : " + property + " !== null && " + property + " !== undefined ? " + property + " : 0;\r\n";
} else if (propertyDef.type && propertyDef.type === 'boolean') {
  outputBody = outputBody + "   this." + property + " = " + model + "." + property + " ? " + model + "." + property + " : "  + property + " ? " + property + " : " + "false;\r\n";
} else if (propertyDef.type && propertyDef.type === 'array') {
  var arrayOf = propertyDef.items['$ref'].replace('#/definitions/', '');
  outputBody = outputBody + "   this." + property + " = " + model + "." + property + " ? " + model + "." + property + " : "  + property + " ? " + property + " : []; // of '" + arrayOf + "';\r\n";
} else if (propertyDef.type && propertyDef.type === 'object') {
  outputBody = outputBody + "   this." + property + " = " + model + "." + property + " ? " + model + "." + property + " : "  + property + " ? " + property + " : {};\r\n";
} else if (propertyDef['$ref']) {
  needsModelFactory = true;
  var nestedObject = propertyDef['$ref'].replace('#/definitions/', '');
  outputBody = outputBody + "   this." + property + " = " + model + "." + property + " ? " + model + "." + property + " : "  + property + " ? " + property + " : new modelFactory." + nestedObject + "();\r\n";
} else if( propertyDef.format && propertyDef.format === 'date-time' ) {
  outputBody = outputBody + "   this." + property + " = " + model + "." + property + " ? " + model + "." + property + " : "  + property + " ? " + property + " : " + "'1985-04-12T23:20:50.52Z';\r\n";
} else {
  outputBody = outputBody + "   this." + property + " = " + model + "." + property + " ? " + model + "." + property + " : "  + property + " ? " + property + " : " + "'';\r\n";
}
Objectively good or not good?
It isn't right justified.

Many lines are over 80 chars.

The white & black balance seems a little off, so the whitespace streaks down the code, which makes it visually unappealing.

Not in Comic Sans.

So many problems would be solved if we all used languages that don't have an "else" clause in it. Just sayin'.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-20-2016 , 03:31 AM
This makes me think, it would be interesting to have a programming contest (interview question?) where you take a program that attempts to solve a fairly complex problem but fails miserably without even coming close and make it work without changing the program. We're only allowed to rewrite its dependencies, and not in a way that completely hijacks the program either.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-20-2016 , 03:44 AM
think that last clause would be pretty subjective.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-20-2016 , 04:12 AM
Lol at you guys (well candybar) taking that code to such deep levels. I'm just at the 'stop making my eyes bleed' layer of refactoring right now. I factored that block out into a function that returns a hash of ES6 template strings, and dumped it below module.exports where I don't have to look at it anymore. I'll worry about the deeper meaning fixes later.

It's some guy who I think is a pretty good dev but not super experienced with JS or node. He wrote a generator to create a node app from a swagger yaml file in 2 weeks (which is fairly impressive, but explains a lot of the sloppiness). I'm cleaning it up and modularizing it now.

I'm scared to look to see if there's something out there that does exactly what he just did. At this point it's too late to change horses, and he did this before I was on the project.

One thing he did a good job of is creating a structure to handle the custom business logic for each API. So there will be a _generated folder for the part that matches the swagger file (end points, params, data structure, error structure), and a BLL folder for custom logic and back end data access. Devs get a stub in the BLL folder which they can overwrite. But they never touch the _generated folder.

That means the API baseline code can be re-generated at any time w/o wiping out the BLL folder. Of course if your API changes too much and breaks your business logic, that's on you. Oh yeah, one other thing he did I really like is write cucumber tests for everything. Makes my job refactoring infinitely easier.

I think it's structurally a sound idea. Just need a lot of organizing. My goal is to make sure that we don't wind up with 12 different versions of microservices based on what version of the generator made them. It needs to be living code that keeps everyone on the same version of the generator and shared code lib (at least as long as we can). One of my big peeves is a generator script that has no facility to update the entities which have already been generated.

Also I want to make sure developer workflow is as simple as possible, that they only have to worry about business logic and not plumbing, etc. It's a fun challenge. I feel so much better working on actual defined problems again.

Last edited by suzzer99; 08-20-2016 at 04:24 AM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-20-2016 , 11:47 PM
anything wrong with taking a terrible, extremely low-paying job with no benefits just to get some experience?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

      
m