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.
 
  • Locked thread
JawnV6
Jul 4, 2004

So hot ...
spent my morning being outsmarted by the compiler

afternoon's not looking any smarter

Adbot
ADBOT LOVES YOU

Xarn
Jun 26, 2015

gonadic io posted:


Ask me about unethical marking practices in courseworks!!

Do tell, I am still thinking about keeping the course running after I leave uni. :suicide:

Finster Dexter
Oct 20, 2014

Beyond is Finster's mad vision of Earth transformed.

Bloody posted:

HAHA jesus christ i just looked at our main competitor's product and their interface is literally:
foo('commandName', [varargs])
their entire API consists of more than a dozen 'functions' called as strings

lol why do people do this

HoboMan posted:

guess who's got two thumbs and found out that there's an entire class of stored procedures in prod using SELECT *?

but it's ok guys they properly prefixed it at least so it's really SELECT <tableName>.*

I go back and forth on using select * vs. list of fields. I think my main motivator is laziness, i.e. if I add a column I only have to update the save procedures and all the read procedures are gtg

jony neuemonic
Nov 13, 2009

asked one of the other developers where we store the credentials for a third party service.

he handed me a post-it lmao.

Uncle Enzo
Apr 28, 2008

I always wanted to be a Wizard

jony neuemonic posted:

asked one of the other developers where we store the credentials for a third party service.

he handed me a post-it lmao.

*sends you the login & password in a plaintext email*

Finster Dexter
Oct 20, 2014

Beyond is Finster's mad vision of Earth transformed.
I don't remember if I've asked this in here or not but which is worse:

dynamic sql generation in a stored proc

dynamic sql generation in c# in my db layer

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Uncle Enzo posted:

*sends you the login & password in a plaintext email*

due to some shenanigans, our main customer recently decided to change the admin password for all the shops in their nationwide retail network

the above sentence is not missing an "s"

gonadic io
Feb 16, 2011

>>=

Xarn posted:

Do tell, I am still thinking about keeping the course running after I leave uni. :suicide:

long story short, british unis are 1) paid per pupil attending and not dropped out, 2) huge amounts of attention is paid to student satisfaction when people choose which uni to go to,

and also my uni has pretty big pressure on the lecturers to have high student satisfaction too, and not too many students getting a first or failing.

basically we decided on the grade bell curve, and then worked out a mark scheme that would let us hit it with the current crop of courseworks. 5 people marking all marked wildly inconsistently and at one point i was marking at home while getting a hj

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


At work last couple days I'm trying to teach myself server sockets in c/c++ and client sockets in c#, also boost::threads in c++ for said server (main thread listens, spawns new thread for each connection)

i'm sort of figuring this poo poo out and playing it by ear but i'm already worried that i don't know enough about what i'm doing to do the project i wanna do :(

at least i went from knowing gently caress all about either subject to successfully setting up an echo server/client over two or three work hours so i guess that's progress??????????

Ciaphas fucked around with this message at 22:29 on Dec 5, 2016

Uncle Enzo
Apr 28, 2008

I always wanted to be a Wizard

NihilCredo posted:

due to some shenanigans, our main customer recently decided to change the admin password for all the shops in their nationwide retail network

the above sentence is not missing an "s"

someone pointed out to me once that physical hardcopies can't be hacked into, and if they're in a secure location and kept there they're actually quite safe. secure being a variable term of course, but the person in question was referring to keeping a notebook in a GSA-certified personal records safe in their office in the pentagon

kind of an edge case admittedly

Powerful Two-Hander
Mar 10, 2004

Mods please change my name to "Tooter Skeleton" TIA.


Finster Dexter posted:

I go back and forth on using select * vs. list of fields. I think my main motivator is laziness, i.e. if I add a column I only have to update the save procedures and all the read procedures are gtg

one of our developera constantly uses datatables for everything with numeric references to colums so good luck figuring out what will break if you change any returned columns!

today i found a case where she had used a dataset and datatables to return what was essentially a bool

Xarn
Jun 26, 2015

gonadic io posted:

long story short, british unis are 1) paid per pupil attending and not dropped out, 2) huge amounts of attention is paid to student satisfaction when people choose which uni to go to,
Pretty much same here.

gonadic io posted:

and also my uni has pretty big pressure on the lecturers to have high student satisfaction too, and not too many students getting a first or failing.
Yup. Although our faculty likes to call itself elite, so there is some push back against passing everyone. There is still an overall trend to decrease difficulty and I can think of only one other course that actually uses up its alloted hours by ECTS credits. :v: My course is pretty weird in its grading though, as we score on 100 points scale (90+A, 80-89 B, etc), but we intentionally have 110 points that you can get during semester, because we recognize that its p. easy to lose points and unless you attend only to credit mine, you shouldn't be close to 100%.


gonadic io posted:

... at one point i was marking at home while getting a hj
:v: Worst we have done so far while marking was to get a bunch of beers, play Doom music at crazy volume and slowly slog through 40 end semester exams, trying to keep grading consistent.

Mao Zedong Thot
Oct 16, 2008


Finster Dexter posted:

I don't remember if I've asked this in here or not but which is worse:

dynamic sql generation in a stored proc

ding ding ding

CPColin
Sep 9, 2003

Big ol' smile.

gonadic io posted:

at one point i was marking at home while getting a hj

B+ semen after class

hobbesmaster
Jan 28, 2008

Uncle Enzo posted:

someone pointed out to me once that physical hardcopies can't be hacked into, and if they're in a secure location and kept there they're actually quite safe. secure being a variable term of course, but the person in question was referring to keeping a notebook in a GSA-certified personal records safe in their office in the pentagon

kind of an edge case admittedly

between snowden and the opm hack that's probably more secure than siprnet

Shaggar
Apr 26, 2006

Finster Dexter posted:

I don't remember if I've asked this in here or not but which is worse:

dynamic sql generation in a stored proc

dynamic sql generation in c# in my db layer

its bad either way. you can parameterize it in both places.

Luigi Thirty
Apr 30, 2006

Emergency confection port.



i couldn't figure out how to stream tiles in and out to wrap the screen around without murdering the frame rate with my meager amiga knowledge, so instead I figured out how to draw a 16-color tilemapped background that's as long as 255 screens and just move the graphics window up and down the length of the level. it's me, i'm the terrible programmer

i guess i need to make a level editor tool now so i'm not manually placing these drat tiles everywhere

jony neuemonic
Nov 13, 2009

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:



:shittypop:

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer
Hey, I finished a first draft of that article. Does anyone want to review it? I'm going to have my skeleton warrior university student services sociology phd-having friend review it too.

geeves
Sep 16, 2004

We've been pretty lucky it seems. An issue came up and we traced it to a weird case in which we were reading and writing only from the master DB and none of the replicas. We went back and looked at the monitoring logs and found that usage of the replicas was next to nothing. We found the issue pretty quickly.

We used to have a developer who's answer to "What is best in life?" was "TDD, writing tests and hearing the lamentations of other developers."

Well, in his goal for 100% code coverage he wrote unit tests to some DB connection classes that had bee stable for years. In fact, the only time our main DB connection util was changed in the last 2 years outside of some very minor change, was when he added the following:

code:
    public static Session getSession(boolean readOnly) throws HibernateException {
	// this block is to test if we only want to return a write session
	try {
		Field f = SessionFactoryImpl.class.getDeclaredField("properties");
		f.setAccessible(true);
		Properties p = (Properties) f.get(sessionFactory);
		if (Boolean.parseBoolean((String) p.get("only_get_write_session"))) {
			// ok: we are in unit testing we want a only get write session
			readOnly = false;
		}
	} catch (Exception e) {
		// the only_get_write_session is not set, return proceed normally
		log(HibernateUtil.class).error(e);
	}
	// get a write or read only session
	if (readOnly) {
            session = getReadSession();
        } else {
            session = getWriteSession();
        }

In mid-2015...

In the hibernate properties:

<property name="only_get_write_session">true</property>

:haw:

jesus WEP
Oct 17, 2004


Finster Dexter posted:

I don't remember if I've asked this in here or not but which is worse:

dynamic sql generation in a stored proc

dynamic sql generation in c# in my db layer
dynamic SQL is a code smell imo so theyre both real bad

in mssql you can use sp_executesql along with parameters to stop injection

don't ever use exec

Finster Dexter
Oct 20, 2014

Beyond is Finster's mad vision of Earth transformed.

St Evan Echoes posted:

dynamic SQL is a code smell imo so theyre both real bad

Agreed but as a bad programmer not sure how else to implement this very bad search filtering poo poo they want where they want to search through db rows based on any or all of about 20 different search parameters.

Chalks
Sep 30, 2009

Finster Dexter posted:

Agreed but as a bad programmer not sure how else to implement this very bad search filtering poo poo they want where they want to search through db rows based on any or all of about 20 different search parameters.

Generating a parametrised query in your code probably isn't too terrible, I assume you're not taking things like table names and field names from user supplied data.

I'm going to be needing to do a similar thing soon in order to have grouped filtering checkboxes on a product search. When generating dynamic (x and y and (a or b or c)) stuff, this seems like the only approach.

Chalks fucked around with this message at 15:11 on Dec 6, 2016

Finster Dexter
Oct 20, 2014

Beyond is Finster's mad vision of Earth transformed.

Chalks posted:

Generating a parametrised query in your code probably isn't too terrible, I assume you're not taking things like table names and field names from user supplied data.

I'm going to be needing to do a similar thing soon in order to have grouped filtering checkboxes on a product search. When generating dynamic (x and y and (a or b or c)) stuff, this seems like the only approach.

Yeah, I'm using parameterized queries. Dapper makes that simple af even with a huge set of parameters. The argument for the search function in the db layer is an object with all the params as properties, and all I have to do then is null check and build the string, then pass in the string and the original search param object into dapper and that's one line of code instead of however many to build the SqlParameter collection. It's about as elegant as I can make it, I think.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Finster Dexter posted:

Agreed but as a bad programmer not sure how else to implement this very bad search filtering poo poo they want where they want to search through db rows based on any or all of about 20 different search parameters.

WHERE

(@SearchFooEnabled = 0 OR [Foo]=@SearchFooValue)

AND

(@SearchBarEnabled = 0 OR [Bar]=@SearchBarValue)

etc etc

HoboMan
Nov 4, 2010

Finster Dexter posted:

Agreed but as a bad programmer not sure how else to implement this very bad search filtering poo poo they want where they want to search through db rows based on any or all of about 20 different search parameters.

dynamic sql is indeed the "best" way to do that

the way we do it is build the query in the sql sproc, but i don't know if i can recommend doing it that way. i would say this probably comes down to personal preference (provided you make a proper c# function to handle making the query in c# instead of just jamming some sql strings in your code somewhere)

Sapozhnik
Jan 2, 2005

Nap Ghost
if ur using java then JPA2 criteria queries are very ftw for this sort of thing

the "metamodel" classes get autogenerated from your entity classes in the background in real time, and you can bash together subexpression chunks however you please. it even has type safety! although i was confused as to why it let you like, generate an expression node that compares an integer to a string and then i remembered that sql is garbage and lets you do that.

i have to say, JPA2 is extremely needs suiting, but with one major caveat: you should only very rarely actually tell it about entity relationships. most times you want to just map the FK columns and then explicitly construct a join using criteria queries. this gets you basically all of the benefits of an orm and none of the drawbacks.

Finster Dexter
Oct 20, 2014

Beyond is Finster's mad vision of Earth transformed.

Sapozhnik posted:

if ur using java then JPA2 criteria queries are very ftw for this sort of thing

the "metamodel" classes get autogenerated from your entity classes in the background in real time, and you can bash together subexpression chunks however you please. it even has type safety! although i was confused as to why it let you like, generate an expression node that compares an integer to a string and then i remembered that sql is garbage and lets you do that.

i have to say, JPA2 is extremely needs suiting, but with one major caveat: you should only very rarely actually tell it about entity relationships. most times you want to just map the FK columns and then explicitly construct a join using criteria queries. this gets you basically all of the benefits of an orm and none of the drawbacks.

I'm in C# land, but what you're describing sounds a lot like Dapper.

The worst part of any orm is the relationship mapping and when it gets screwed up (because it always does) the orm will lay a giant runny turd on your database in the form of thousands of queries to build the object-relation trees.

jony neuemonic
Nov 13, 2009

NihilCredo posted:

WHERE

(@SearchFooEnabled = 0 OR [Foo]=@SearchFooValue)

AND

(@SearchBarEnabled = 0 OR [Bar]=@SearchBarValue)

etc etc

have done this, works great and you will hate your life way less when you have to update it later. you can save yourself the extra variables by doing something like @ButtValue IS NULL OR Butt = @ButtValue too.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

jony neuemonic posted:

have done this, works great and you will hate your life way less when you have to update it later. you can save yourself the extra variables by doing something like @ButtValue IS NULL OR Butt = @ButtValue too.

I have learnt through much pain to never use nulls if any other way of representing a missing value is available.

If I have a foreign key relationship I am forced to use nulls, and if I'm doing a left join I will always get nulls for missing rows, but other than that a default value is the way to go as it's much less likely to gently caress poo poo up. Basically the null object pattern for sql

jony neuemonic
Nov 13, 2009

NihilCredo posted:

I have learnt through much pain to never use nulls if any other way of representing a missing value is available.

If I have a foreign key relationship I am forced to use nulls, and if I'm doing a left join I will always get nulls for missing rows, but other than that a default value is the way to go as it's much less likely to gently caress poo poo up. Basically the null object pattern for sql

in that case i used null as the default for the stored proc parameters so it should be fine, but that's a good point. nulls bite.

Chalks
Sep 30, 2009

NihilCredo posted:

I have learnt through much pain to never use nulls if any other way of representing a missing value is available.

If I have a foreign key relationship I am forced to use nulls, and if I'm doing a left join I will always get nulls for missing rows, but other than that a default value is the way to go as it's much less likely to gently caress poo poo up. Basically the null object pattern for sql

What sort of issues do you encounter with nulls? Other than .net's stupid DBNull type, I've never been particularly concerned by them. I get rather irritated by code doing things like putting blank strings into fields to indicate that the value has been cleared because it can lead to really subtle bugs.

Sapozhnik
Jan 2, 2005

Nap Ghost

Sapozhnik posted:

it's me, i'm the guy writing new and trivial python 2 code in tyool 2016, because centos 7 comes with java 8 but whoa there apparently python 3 is a bit too bleeding edge

(no problem, just enable epel, right? yes, that will get you python 3. wait whoa there you want to use it to talk to a postgres database well you're just a loose cannon mister)

gently caress this poo poo so very hard

HoboMan
Nov 4, 2010

c web dev s: this page is not displaying correctly on mobile chrome. normal chrome is fine, just on a tablet it doesn't work. also, looking at the code, come chucklefuck decided that this page's html should get dynamically built using client-side javascript :suicide::suicide::suicide:

HoboMan fucked around with this message at 19:52 on Dec 6, 2016

Finster Dexter
Oct 20, 2014

Beyond is Finster's mad vision of Earth transformed.

HoboMan posted:

c web dev s: this page is not displaying correctly on mobile chrome. normal chrome is fine, just on a tablet it doesn't work. also, looking at the code, come chucklefuck decided that this page's html should get dynamically built using client-side javascript :suicide::suicide::suicide:

yeah I hate that poo poo, my platform is rife with that garbage, especially on stuff built by the guy who puts "created javascript framework" on his linkedin and quit the company to go work on a factory assembly line.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Chalks posted:

What sort of issues do you encounter with nulls? Other than .net's stupid DBNull type, I've never been particularly concerned by them. I get rather irritated by code doing things like putting blank strings into fields to indicate that the value has been cleared because it can lead to really subtle bugs.

Well here's one from less than 48 hours ago:

We had a feature that was supposed to be active from StartDate to EndDate, but actually would end on the day before EndDate. Turns out a query was doing GETDATE() <= [EndDate] in its WHERE, thus taking the time of day into account and ending prematurely. I took my time to look for the right fix (because we have to technically support as old as MSSQL2005 where the DATE type doesn't even exist) and settled on some formula involving DATEDIFF. Tested it to make sure every edge case was covered, pushed it onto a few prod environments, everything's ok. Last Sunday it gets pushed to all prod environments, and a bunch of the really old ones break.

Turns out when those columns were originally added to the schema, somebody (who may or may not be currently paying my salary) half-assed the migration and left NULLs in the pre-existing rows instead of inserting default dates. This was like seven or eight years ago and I had no idea those columns had ever not existed - the current schema has had them as NOT NULL forever. But as it happens, GETDATE() <= NULL is perfectly legal and returns false, but DATEDIFF (NULL) throws and aborts the entire query.

So yeah, if I could know exactly with 100% certainty which columns can and can not be NULL, then I'd have no major issue with NULLs. But having to code against live production dbs that have gone through all sorts of grubby hands over the years, safely dealing with NULLs requires me to wrap literally every single column name in ISNULL() boilerplate, and it's always the one time I don't that I get bit in the rear end.

HoboMan
Nov 4, 2010

Finster Dexter posted:

yeah I hate that poo poo, my platform is rife with that garbage, especially on stuff built by the guy who puts "created javascript framework" on his linkedin and quit the company to go work on a factory assembly line.

i really have no idea what to do. not only does it build it dynamically client-side, but it does it using jquery. i don't want to completely redo the page but it seems like the only option since how the gently caress do i debug this?

Finster Dexter
Oct 20, 2014

Beyond is Finster's mad vision of Earth transformed.

HoboMan posted:

i really have no idea what to do. not only does it build it dynamically client-side, but it does it using jquery. i don't want to completely redo the page but it seems like the only option since how the gently caress do i debug this?

Well, here's what I've done as I've needed to make changes, and I have to weigh the effort of this vs. the benefit from unfucking it:

I took the rendered html and saved it to a file. This file is going to become my handlebars template. Then, I go through the js and rip out all the html and just set properties on a bespoke JSON object. Every time I do that, I update my template with the handlebars calls for the properties, like {{Turd}} or whatever.

I've also done this when the html is built up by calls to web services that return html (which also bugs the poo poo out of me... don't infect my service layer with your loving markup fjhdsklafdskla).

It can take a long-rear end time based on how much html you're dealing with, but it gets things fairly de-coupled and a lot more sane to deal with when you need to edit/change the markup or the data being returned or whatever.

I like handlebars because it's loving simple and not overgrown with a bunch of bullshit you don't need. And if you have to do really wild n wooly markup you can create a custom handler for handlebars pretty quickly/easily.

Finster Dexter fucked around with this message at 21:22 on Dec 6, 2016

Adbot
ADBOT LOVES YOU

Chalks
Sep 30, 2009

NihilCredo posted:

Well here's one from less than 48 hours ago:

We had a feature that was supposed to be active from StartDate to EndDate, but actually would end on the day before EndDate. Turns out a query was doing GETDATE() <= [EndDate] in its WHERE, thus taking the time of day into account and ending prematurely. I took my time to look for the right fix (because we have to technically support as old as MSSQL2005 where the DATE type doesn't even exist) and settled on some formula involving DATEDIFF. Tested it to make sure every edge case was covered, pushed it onto a few prod environments, everything's ok. Last Sunday it gets pushed to all prod environments, and a bunch of the really old ones break.

Turns out when those columns were originally added to the schema, somebody (who may or may not be currently paying my salary) half-assed the migration and left NULLs in the pre-existing rows instead of inserting default dates. This was like seven or eight years ago and I had no idea those columns had ever not existed - the current schema has had them as NOT NULL forever. But as it happens, GETDATE() <= NULL is perfectly legal and returns false, but DATEDIFF (NULL) throws and aborts the entire query.

So yeah, if I could know exactly with 100% certainty which columns can and can not be NULL, then I'd have no major issue with NULLs. But having to code against live production dbs that have gone through all sorts of grubby hands over the years, safely dealing with NULLs requires me to wrap literally every single column name in ISNULL() boilerplate, and it's always the one time I don't that I get bit in the rear end.

Wait, the database structure has the columns as "not null" but they contain nulls? Admittedly almost all my database experience has been with Sybase products but with those if you try to set a column to not null where it contains nulls you get an exception when trying to update the structure.

Dealing with nulls in .net is the biggest pain I've found - you'd have thought that if a column contains a null then returning null would be a pretty sensible thing rather than some bizarre "DBNull" data type that seems to exist solely to irritate me. You just have to extend the data reader to return actual useful nulls instead though and then it all just works but the main reason it annoys me is because I'm apparently too dumb to ever remember this until my code crashes. Can't cast DBNull to string! Fucks sake.

In general though I like nulls. In the example you mention, I guess there's some appropriate "default date" that you can use, but it could well be the case that if no end date is specified then there's some context specific end date that you use instead (like the end of the next working week or something based on other attributes of the record). I'd much rather use a null for that instead of setting the date to 01-01-2999 and then having a special case for that magic date or whatever. With dates that seems really insane but you see people doing magic crap like that with strings and integers all the time.

Chalks fucked around with this message at 21:31 on Dec 6, 2016

  • Locked thread