• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

I've been trying for hours but I just can figure this out.

Here is a breakdown of what I'm trying to do.

I am working with VB scripting in Excel to do the following:

I want to scan a string so that it will select the quantity in a cell and automatically subtract 1.

So if I am pulling something out of inventory I can scan a specific bar code that will subtract 1 from the inventory quantity but set up for multiple items. Any help would be appreciated.

Post some sample data. For example:

Code:
        A                  B                  C
1      Test           =MYFUNC(A1,A2)
2       12
3

Do I understand that the value of B1 should be 11 if some condition is true about A1?
 

Snipes424

Member
Post some sample data. For example:

Code:
        A                  B                  C
1      Test           =MYFUNC(A1,A2)
2       12
3

Do I understand that the value of B1 should be 11 if some condition is true about A1?

Here is an example of the spreadsheet

Code:
	3'	25	25	45
	4'	36	25	45
	5'	91	25	90
	6'	36	25	90
	7'	27	25	80
	8'	21	25	40
	10'	35	25	40
	15'	41	25	40
	20'	48	25	50

I want to change the values in the second column where it's "n-1" every time I scan specific barcode.

So for example if I wanted to select the second column second row. I would write something like
Code:
 ActiveSheet.Cells(2,2).Select

But first, how do I select it using a barcode scanner? And how do I change it so it's "n-1"?
 

Chris R

Member
Well your barcode scanner is probably setup to read a string value and press "enter" when it scans something.

So take that value the barcode scanner is giving you, look up the row, and change the cell value.
 
Here is an example of the spreadsheet

Code:
	3'	25	25	45
	4'	36	25	45
	5'	91	25	90
	6'	36	25	90
	7'	27	25	80
	8'	21	25	40
	10'	35	25	40
	15'	41	25	40
	20'	48	25	50

I want to change the values in the second column where it's "n-1" every time I scan specific barcode.

So for example if I wanted to select the second column second row. I would write something like
Code:
 ActiveSheet.Cells(2,2).Select

But first, how do I select it using a barcode scanner? And how do I change it so it's "n-1"?

I would do this a little differently. I would make another sheet or something that has 2 columns. A is barcode number and B is times scanned. Your VBScript detects when a barcode is scanned, finds the corresponding row in this table, and adds 1 to the number of times that barcode has been scanned (or adds a new row if it wasn't there yet).

Then in the data above, do 25 - VLOOKUP() on the barcode table, to subtract the number of times it's been scanned.


Next you're going to ask how to detect when a barcode is scanned and update that table. And i have no idea, because that's pretty domain specific and depends on what excel library you are using to communicate with your barcode scanner
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Can anyone explain why the following js code gives different scope results? What should I do to manipulate the global array inside the for loop?

I need to do a complete rotation of the array and also keep each rotation.

It should end up looking like this:

This is an interesting problem. It has something to do with JS for loop scope and how it handles assignment, but I haven't nailed down the cause yet.

What's happening inside though is that the table array is being appended with new arrays (like it should), but each time it's appended all of the previously added arrays change their values to the most recent one.

I'm assuming .push(row) is only pushing a reference to row into the table array, rather then the row object itself.
 

Gurrry

Member
So after trying to learn C# exactly a year ago, and having to stop all projects due to school... I started learning JS and Unity about a month ago. And as of today, im nearing in on finishing my first project.

I have a big project I am working on, but I wanted to make something for mobile that I can learn from and just have fun with. I used alot of free art from various websites for gamedev art. And I hope to actually finish it today.

Its really stupid and simple. Enemies fall from the sky, you tap them to kill them. Tap enough of the same color enemy = get a power up. Use power ups to kill more enemies/gain health.

However, im having issues putting the final polish on. I cant get audio to play on mousedown, and I also worry that when I try and put this on my android that aspect ratio is going to be fucked. Right now it looks more like 16:9, so I worry when a phone or tablet goes vertical, its going to be all screwy.

Anyway, I just wanted to post this and say if you have a passion for making games. The best thing to do is to just DO IT. Dont wait to goto school and learn traditionally. Just get inside an engine, learn some language, and trial and error.
 

Kelsdesu

Member
Are there any resources online for assembly that you guys can recommend? Im going to have to take it again but I want to have a grasp next go around.
 

Koren

Member
I learned i86 assembly before even internet was a thing, so my suggestions may not be the best ones... At this time, I used a book listing all the instructions and basic structure of the language, and a giant (and well-known) french version of a book of 1500 pages calling itself "the bible" *.

I've barely needed books in the last fifteen years, even when I teached it, but I've still grabbed a couple ressources which were useful, and that you may find interesting.

One is "the Art of Assembly Programming"

The other "Programming from the Ground up".

Both are available for free online if I'm not mistaken.

_________

(*) Just out of curiosity, I think it was the french version of this book (if I'm not mistaken, at least it's the correct author, and lenghty enough) :
http://www.amazon.com/dp/1557553041/?tag=neogaf0e-20
a great read at this time, but obviously probably awfully out of date (granted, assembly still has a common base, but VESA programming by shifting a memory window may not be the most useful thing nowadays ;) )
 

Kelsdesu

Member
I learned i86 assembly before even internet was a thing, so my suggestions may not be the best ones... At this time, I used a book listing all the instructions and basic structure of the language, and a giant (and well-known) french version of a book of 1500 pages calling itself "the bible" *.

I've barely needed books in the last fifteen years, even when I teached it, but I've still grabbed a couple ressources which were useful, and that you may find interesting.

One is "the Art of Assembly Programming"

The other "Programming from the Ground up".

Both are available for free online if I'm not mistaken.

_________

(*) Just out of curiosity, I think it was the french version of this book (if I'm not mistaken, at least it's the correct author, and lenghty enough) :
http://www.amazon.com/dp/1557553041/?tag=neogaf0e-20
a great read at this time, but obviously probably awfully out of date (granted, assembly still has a common base, but VESA programming by shifting a memory window may not be the most useful thing nowadays ;) )

Thanks man. There isn't much by the way of online resources. I will definitely check those books out. Thank you.
 

Gurrry

Member
trying to build my game with unity for PC and after it exports, when i try and open it, nothing happens. endless hour glass, and I cant close the game via ctrl alt delete.

however, i was able to get it running on my android device with android sdk.

:(
 

Mr.Mike

Member
So I proctored a Introductory Programming course today, and I spent some time counting people (it's a long three hours).

There were 162 people writing the final, 23 of whom were women. The semester started with about 200 people I think?

So like, about 14% of this first year programming course. This is a course that is also required to be taken by Math and Physics students, so the proportion of women in the first year of CS at my school is probably even smaller than that sad 14%.
 

vypek

Member
Oh thats dangerous. So many good books. Will try and limit myself to 3

Yeah, I just saw the bundles they have. Like they Python one is worth $200 normally and its $25 now. All bundles seem to be $25 and save a lot of money. I feel like I'm going to end up spending a lot of money.
 

V_Arnold

Member
Can anyone explain why the following js code gives different scope results? What should I do to manipulate the global array inside the for loop?
Code:
var numbers = [1, 2, 3, 4];
var table = [
  { numbers: numbers }
];

console.log('local');

for (var n = 0; n < numbers.length; n++) {
  var row = table[n];
  
  var lastNumber = row.numbers.pop();
  
  row.numbers.unshift(lastNumber);
  
  table.push(row);
  
  console.log(table[n].numbers);
}

console.log('global')

table.forEach(function(row){
  console.log(row.numbers)
});

I might be late to the party, but I thought why not:

Code:
startingArray = [1,2,3,4];
table = [];

function createIterations(targetArray,resultTable)
{
	table.push(startingArray);

	for (var i = targetArray.length-1; i>0;i--)
	{
		pointer = i; 
		resultTable.push(
			iterateOverArray(targetArray,pointer)
			);
	}
}

function iterateOverArray(targetArray,pointer)
{
	result = [];
	for (var i = pointer; i<targetArray.length; i++)
	{
		result.push(targetArray[i]);
	}

	for (var i = 0; i<pointer; i++)
	{
		result.push(targetArray[i]);
	}
	return result;
}

createIterations(startingArray,table)

What I did was is to create the function that does the work take parameters, one the target array, one the result array (or you can easily modify it to make it work like an object with rows, subarrays or whatever). That way, you do not need to mess around with the scope at all.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Can anyone explain why the following js code gives different scope results? What should I do to manipulate the global array inside the for loop?
Code:
  var row = table[n];

Echoing what others have said, this line merely creates a reference to `numbers`, repushes it to `table`, and then each index gets shifted with every loop. You can see the nature of the problem with:
Code:
console.log(table[n+1] === table[n]);    // returns true
 
Anyone here try Scala.js? Really promising if you ask me.
I wrote a small proof of concept sharing Scala code across client and server, with Scalatra.
Worked astonishingly well!
 

Fishlake

Member
So I've been trying to teach myself the basics of SQL. My first full time position after graduation starts up in January and this is a language they told me they use a lot of.

I've already gone through code academy and am going through W3schools but I was wondering if anyone here knew any other useful sites?
 
So I've been trying to teach myself the basics of SQL. My first full time position after graduation starts up in January and this is a language they told me they use a lot of.

I've already gone through code academy and am going through W3schools but I was wondering if anyone here knew any other useful sites?

No. But I just want to say the most important thing you need to know in sql is not the query language syntax, but when and how to create indexes.
 

Fishlake

Member
No. But I just want to say the most important thing you need to know in sql is not the query language syntax, but when and how to create indexes.

I'll probably be learning all about that haha. The place I'll be working does projects that other companies can't do themselves. So they program or streamline the code that is too difficult for the clients programmers to do. It is an honor to be hired by them since they think I have what it takes.
 
So I've been trying to teach myself the basics of SQL. My first full time position after graduation starts up in January and this is a language they told me they use a lot of.

I've already gone through code academy and am going through W3schools but I was wondering if anyone here knew any other useful sites?

CodeSchool is a great site. It costs money ($30/mo unless you can find one of the many coupons, which usually knocks it down to $15/mo for 6 months or something), but it's better than CodeAcademy in every way.

They have two courses on SQL:

https://www.codeschool.com/paths/database

But the site is definitely more focused towards JS & Rails than databases like SQL.
 

V_Arnold

Member
I am jumping on that functional programming javascript bandwagon.

After a few years of hobby/casual game development (first, with my own canvas-"engine", huh, then pixiJS, and some custom input/scene handler), I started to do nodeJS apps and have all kinds of ideas...

Then I realized that most of my "oh gosh, I cant look at my old code" mistakes come from functions and objects just bleeding dependencies into each other. Functional programming seems to be a good way to get away from that mentality.

And who would have thought that those general programming and Lambda-calculus classes would once again creep into my life :D

Anyone has experience with PureScript, Haskell or just some functional approaches to javascript development?

(And I hightly doubt that my game main loops will ever be functional, but if I can learn better structuring, get into unit testing mindset and all that, the *rest* will be easier to work with :)
 

Makai

Member
I am jumping on that functional programming javascript bandwagon.

After a few years of hobby/casual game development (first, with my own canvas-"engine", huh, then pixiJS, and some custom input/scene handler), I started to do nodeJS apps and have all kinds of ideas...

Then I realized that most of my "oh gosh, I cant look at my old code" mistakes come from functions and objects just bleeding dependencies into each other. Functional programming seems to be a good way to get away from that mentality.

And who would have thought that those general programming and Lambda-calculus classes would once again creep into my life :D

Anyone has experience with PureScript, Haskell or just some functional approaches to javascript development?

(And I hightly doubt that my game main loops will ever be functional, but if I can learn better structuring, get into unit testing mindset and all that, the *rest* will be easier to work with :)
I've been using F# with Unity. I think my code is probably as stateless as possible. My game loop has a single mutable variable -> the game state record. Every frame, I pass the game state into a stateless API which returns the new game state. The game state variable is assigned this new value. My rendering code figures out what to do based on the game state variable. I encode input into the game state before passing it into the API.
 

V_Arnold

Member
I've been using F# with Unity. I think my code is probably as stateless as possible. My game loop has a single mutable variable -> the game state record. Every frame, I pass the game state into a stateless API which returns the new game state. The game state variable is assigned this new value. My rendering code figures out what to do based on the game state variable. I encode input into the game state before passing it into the API.

Oh, F#! Heard about that one too! And good things as well. What you describe sounds quite elegant, but on javascript, I would worry about garbage collection working overtime on remaking objects that frequently : D I mean, my premature optimization months were basically me going rampant on never creating anything new in the main update/render loops :D
 

Makai

Member
Oh, F#! Heard about that one too! And good things as well. What you describe sounds quite elegant, but on javascript, I would worry about garbage collection working overtime on remaking objects that frequently : D I mean, my premature optimization months were basically me going rampant on never creating anything new in the main update/render loops :D
The record is really small. I don't think it's a big deal. One of my projects is a fighting game -> Game state is the state of the left and right players. A player has an input state and a fighter state. Input state is currently depressed buttons, pad direction, and buffer for inputs on previous frames. Fighter state is a discriminated union (basically an enumeration with extra data encoded into each value (e.g. current animation frame). Altogether, this is hardly any memory.
 

Koren

Member
No. But I just want to say the most important thing you need to know in sql is not the query language syntax, but when and how to create indexes.
Would you care to elaborate a bit? I mostly now the theorical parts, but I really lack experience on the subject...
 

V_Arnold

Member
The record is really small. I don't think it's a big deal. One of my projects is a fighting game -> Game state is the state of the left and right players. A player has an input state and a fighter state. Input state is currently depressed buttons, pad direction, and buffer for inputs on previous frames. Fighter state is a discriminated union (basically an enumeration with extra data encoded into each value (e.g. current animation frame). Altogether, this is hardly any memory.

What you describe is actually very similar to how I store my fighter's states (1v1 match3rpg :D), I will give this a go soon and see how the GC handles it on mobiles and lowend pc's. (Because usually, those are the really crucial parts, better rigs easily get a gc session done within a few ms, and rendering is *not* a 10+ms operation :D)
 
Would you care to elaborate a bit? I mostly now the theorical parts, but I really lack experience on the subject...

Well I mean the syntax isn't that complicated. And sure, the way you write a query can drastically affect the performance, but that's only true if your query is poorly written to begin with. If you don't have the right indexes created, it will affect every query.

An index is basically a hash table, so that if you say SELECT * FROM FOO WHERE BAR=7, your options are either iterate over every single row in the table, looking for the value [O(n)] or use a hash table [O(1)]. If there's an index on bar, it's O(1), otherwise it's O(n). For small databases this isn't a big deal, but for tables with many rows this could be millions of searches every time you run a query.

Certain columns are obvious. Any primary and foreign key constraints should have indexes, because by definition of being a "key", you are going to be filtering on those columns. As a result most database software will warn or prevent you from creating a key with no index for that reason.

But you don't need to create indices on just 1 column. For example, if you've got columns A and B you could write the following queries:

Code:
SELECT * FROM FOO WHERE A=7
SELECT * FROM FOO WHERE B=7
SELECT * FROM FOO WHERE A=7 AND B=7

And now having an index on just A and just B isn't enough to get the fastest performance from the 3rd query.

You can summarize the performance characteristics with different index configurations as follows:

Code:
                                  Performance
Index On         Query 1        Query 2        Query 3
    A            Fastest        Slowest        Slower
    B            Slowest        Fastest        Slower
   A+B           Slowest        Slowest        Fastest


The third one is probably surprising. If you have an index on A+B, why is a query against A slow? Because it's a *combined* index. Creating an index on A+B means creating a *single* hash table where the values being hashed are tuples of the form (<value from A>, <value from B>).

The reason Query 3 is marked "Slower" instead of "Slowest" in the first and second rows is because even though there is no index on A+B, there is still an index on the individual columns. So it can narrow down the search space by using the index from A on the A conditional to limit the set of possible rows, before doing a linear scan on that result set.

So if you want all 3 of these to be fast, you need 3 indices. Of course, the amount of storage required by an index depends on how many rows are in the table, and with millions of rows in your table you can get very large indices. So there's a performance / storage tradeoff to be had.


This problem can arise in subtle ways. For example, you might write something like:

SELECT A.foo, B.bar from A INNER JOIN B on A.id = B.id

The performance of this can drop to... I don't remember, but I think M*N in the worst case scenario. The relationship between indices and joins is surprisingly complicated, and you could probably write an entire magazine article on it.

That kind of knowledge may only be useful to DBAs and not software engineers, but in any case, it doesn't change the basic premise, which is that joins are important :)

Indices aren't just hash tables of full values though. Most (all?) databases will also index every prefix of a string. This allows the index to be used with the sql LIKE operator. But you have to be careful since only prefixes are indexed, which means your index only helps you up to the first wildcard. So for example, even with an index, running the query

SELECT * FROM FOO WHERE NAME LIKE '%Bar%'

will be a full table scan, since the index is useless in this scenario. But if you write this instead:

SELECT * FROM FOO WHERE NAME LIKE 'Bar%Baz'

Then the database engine can use the index against Bar, and (hopefully) drastically reduce the search space before doing a full table scan against the rest.

I'm sure there's more to know, that's the basics that I can think of off the top of my head.
 

JeTmAn81

Member
That functional programming

zoolander-paris-fashion-1.jpg
 

Koren

Member
Cpp_is_king > I won't type a long answer because I'm on a phone, but a huge thanks for taking the time to type such a long and informative answer...

I'll have to teach a bit of database theory soon, and while I'm at mostly at ease with queries, joins and theory, I'm a complete noob in practical aspects. I've wondered about efficiency issues, but I haven't found time yet to investigate it. That's great entry points. Most things are obvious enough (or you make them sounds like it), but I hadn't encountered them.

I plan to port a flashcard program of mine to android, and I'll probably use SQL (on PC, I handled everything in pure stl lists), I'll make sure I'll keep your suggestions in mind...
 
Cpp_is_king > I won't type a long answer because I'm on a phone, but a huge thanks for taking the time to type such a long and informative answer...

I'll have to teach a bit of database theory soon, and while I'm at mostly at ease with queries, joins and theory, I'm a complete noob in practical aspects. I've wondered about efficiency issues, but I haven't found time yet to investigate it. That's great entry points. Most things are obvious enough (or you make them sounds like it), but I hadn't encountered them.

I plan to port a flashcard program of mine to android, and I'll probably use SQL (on PC, I handled everything in pure stl lists), I'll make sure I'll keep your suggestions in mind...

No problem, I'm no expert myself, i got thrown into the server team of an online game and learned most of my database knowledge on the fly out of necessity.

One other practical thing is that stored procedures are your friend. Not just because it's the best way to express non trivial database operations, but from a security perspective it's a huge win. You can set table permissions on every table to disable every single statement except CALL and SELECT, which means the database can only be manipulated through the limited set of stored procedures you provide.
 
The record is really small. I don't think it's a big deal. One of my projects is a fighting game -> Game state is the state of the left and right players. A player has an input state and a fighter state. Input state is currently depressed buttons, pad direction, and buffer for inputs on previous frames. Fighter state is a discriminated union (basically an enumeration with extra data encoded into each value (e.g. current animation frame). Altogether, this is hardly any memory.

Oh, F#! Heard about that one too! And good things as well. What you describe sounds quite elegant, but on javascript, I would worry about garbage collection working overtime on remaking objects that frequently : D I mean, my premature optimization months were basically me going rampant on never creating anything new in the main update/render loops :D

+1 for F# :)

I will also add that if the garbage collector is incremental, then frequent garbage is put in the nursery and garbage collected very quickly and cheaply.
 

Somnid

Member
No problem, I'm no expert myself, i got thrown into the server team of an online game and learned most of my database knowledge on the fly out of necessity.

One other practical thing is that stored procedures are your friend. Not just because it's the best way to express non trivial database operations, but from a security perspective it's a huge win. You can set table permissions on every table to disable every single statement except CALL and SELECT, which means the database can only be manipulated through the limited set of stored procedures you provide.

Honestly, I'd say that if you have non-trivial logic (anything not straight-forward Select From Where and Grouping/Aggregation) you're probably doing something wrong. While SQL is certainly capable of advanced things it's not very good at it. It's less likely to optimize well, it's hard to read, it's hard to version and it's hard to test. Stored procedures I'd generally avoid unless they yielded a very specific and necessary performance benefit and opt to put that logic in the application layer.
 
Honestly, I'd say that if you have non-trivial logic (anything not straight-forward Select From Where and Grouping/Aggregation) you're probably doing something wrong. While SQL is certainly capable of advanced things it's not very good at it. It's less likely to optimize well, it's hard to read, it's hard to version and it's hard to test. Stored procedures I'd generally avoid unless they yielded a very specific and necessary performance benefit and opt to put that logic in the application layer.

Like I said though, it's not just the complexity that you gain from using stored procedures, it's security. If your database is exposed to users, by allowing arbitrary queries to be run against the database you have no control over how a malicious person might try to modify your database. This actually reduces your testing burden, because you only have to test that the limited number of stored procedures you've created work.

A lot of people start out with one database engine (say PostgreSQL) and then later switch to something else (say MySQL). There are always minor syntax differences, and by having everything in stored procedures it makes the transition simple, because you don't have to worry about dynamically generated queries.

Stored procedures optimize better than regular queries because the database can cache the execution plan (think about it like compiled code versus interpreted code).

Versioning is only mildly difficult. Every time you make a change you create a .sql file that contains something like

DROP PROCEDURE FOO
CREATE PROCEDURE FOO <new code>

and check that in with a name like SchemaVersion20.sql. You can rebuild the database to any point in time by running SchemaVersion1.sql - SchemaVersionN.sql in succession.

I'm not gonna say they're the right solution for every problem, but if security is a concern (and it should be if your database is exposed to users), then there's no better way to secure a database.
 

Zoe

Member
Honestly, I'd say that if you have non-trivial logic (anything not straight-forward Select From Where and Grouping/Aggregation) you're probably doing something wrong. While SQL is certainly capable of advanced things it's not very good at it. It's less likely to optimize well, it's hard to read, it's hard to version and it's hard to test. Stored procedures I'd generally avoid unless they yielded a very specific and necessary performance benefit and opt to put that logic in the application layer.

Not everybody has access to the application layer though. My job for the past 6 months has been almost exclusively writing SQL to supplement a third party application we've rolled out.
 

Zapages

Member
Hi guys,

I have simple strange questions.

I have perl script that takes in multiple files. Unfortunately the script as it runs results in an error.

I was thinking of split each of the input files and then creating bash script something like this:

Code:
#!/bin/tcsh
cd /abc/xyz
for i in */Data.txt
do
    perl myScript.pl $i > $i.new
done

or something like this:

Code:
for i in *.txt
do
  perl myscript.pl $i > $i.new
done

Source: http://www.unix.com/shell-programming-and-scripting/110180-perl-script-multiple-files.html

But I am not sure how to do it for multiple input files for the perl scripts.

Basically, I am trying to locate what is causing the error.
 

Zapages

Member
Hi guys,

I have simple strange questions.

I have perl script that takes in multiple files. Unfortunately the script as it runs results in an error.

I was thinking of split each of the input files and then creating bash script something like this:

Code:
#!/bin/tcsh
cd /abc/xyz
for i in */Data.txt
do
    perl myScript.pl $i > $i.new
done

or something like this:

Code:
for i in *.txt
do
  perl myscript.pl $i > $i.new
done

Source: http://www.unix.com/shell-programming-and-scripting/110180-perl-script-multiple-files.html

But I am not sure how to do it for multiple input files for the perl scripts.

Basically, I am trying to locate what is causing the error.



Which error do you get?

Its an error with perl script as it executes multiple applications for bioinformatics/genome prediction. I am talking with the developers and they want me to test their script by break my data sets in smaller parts and then run the perl script to find why their perl script is failing.

Currently it is line 826 in their script and it is not executing another program in its pipeline. But the strange part is that I am able to run this other program independently without any trouble as I have it added to my Paths.

I am running this on Ubuntu BioLinux.
 

JesseZao

Member
Its an error with perl script as it executes multiple applications for bioinformatics/genome prediction. I am talking with the developers and they want me to test their script by break my data sets in smaller parts and then run the perl script to find why their perl script is failing.

Currently it is line 826 in their script and it is not executing another program in its pipeline. But the strange part is that I am able to run this other program independently without any trouble as I have it added to my Paths.

I am running this on Ubuntu BioLinux.

The people with the source code should be doing the debugging. The Line of the error would be useful for them to know.
 

Zapages

Member
The people with the source code should be doing the debugging. The Line of the error would be useful for them to know.

I can't send my data... Its about 3.5 GB in size. They want me to test it out by creating smaller chunks and going from there to test their script. Their script has been published in a scientific journal. Plus it takes about 10 hours to run 128 GB of RAM with 32 Thread (16 Core) Intel Xeon workstation.

From what I have read it takes about a couple days for it to run properly, if everything works properly.

Also they are not getting any errors on their older data and I have shared the line error with them already. :)
 

Somnid

Member
Like I said though, it's not just the complexity that you gain from using stored procedures, it's security. If your database is exposed to users, by allowing arbitrary queries to be run against the database you have no control over how a malicious person might try to modify your database. This actually reduces your testing burden, because you only have to test that the limited number of stored procedures you've created work.

A lot of people start out with one database engine (say PostgreSQL) and then later switch to something else (say MySQL). There are always minor syntax differences, and by having everything in stored procedures it makes the transition simple, because you don't have to worry about dynamically generated queries.

Stored procedures optimize better than regular queries because the database can cache the execution plan (think about it like compiled code versus interpreted code).

Versioning is only mildly difficult. Every time you make a change you create a .sql file that contains something like

DROP PROCEDURE FOO
CREATE PROCEDURE FOO <new code>

and check that in with a name like SchemaVersion20.sql. You can rebuild the database to any point in time by running SchemaVersion1.sql - SchemaVersionN.sql in succession.

I'm not gonna say they're the right solution for every problem, but if security is a concern (and it should be if your database is exposed to users), then there's no better way to secure a database.

It's not uncommon for systems to need hundreds of stored procedures, especially if you are making them each time you need a specific function. This typically becomes an unmaintainable mess where nobody knows what exists and what doesn't (people move on) but it's also a big security problem. It's very easy to look at fields or tables and decide who has or should have read and write access and deny if bad operations, if done at the procedure level especially as things get modified it's impossible to audit because you don't know what each procedure touches and why without reading through it. I find the security benefit is mostly just old DBA myth (and there's a lot of those).

Also versioning tends to get dicer than that. As soon as the schema changes (like I need to add a field) suddenly many stored procedures change and you get this fun task of figuring out which order operations need to be applied but also you need to manually modify a bunch of things and often there's not a good way to track that other than grepping though them. In a typical ORM situation (which I overall recommend but can sometimes have the reverse problem of leaning too hard on the application layer to do things) you'd just have to modify a model of some sort and you're all good.

Finally, if you do stick to simple queries those work in just about every version of SQL the same way and you can compensate in the way you generate queries, it's when you go beyond that then syntax can start diverging in larger ways.

Not everybody has access to the application layer though. My job for the past 6 months has been almost exclusively writing SQL to supplement a third party application we've rolled out.

Yeah, that's an unfortunate situation where you have to make do with what you have. Changing the stored procedures that feed into an application without the ability to access the application code sounds terrifying. These interact heavily and should be modified at the same time. It's not a thing that should be segmented among different teams.
 
It's not uncommon for systems to need hundreds of stored procedures, especially if you are making them each time you need a specific function. This typically becomes an unmaintainable mess where nobody knows what exists and what doesn't (people move on) but it's also a big security problem. It's very easy to look at fields or tables and decide who has or should have read and write access and deny if bad operations, if done at the procedure level especially as things get modified it's impossible to audit because you don't know what each procedure touches and why without reading through it. I find the security benefit is mostly just old DBA myth (and there's a lot of those).

Also versioning tends to get dicer than that. As soon as the schema changes (like I need to add a field) suddenly many stored procedures change and you get this fun task of figuring out which order operations need to be applied but also you need to manually modify a bunch of things and often there's not a good way to track that other than grepping though them. In a typical ORM situation (which I overall recommend but can sometimes have the reverse problem of leaning too hard on the application layer to do things) you'd just have to modify a model of some sort and you're all good.

Finally, if you do stick to simple queries those work in just about every version of SQL the same way and you can compensate in the way you generate queries, it's when you go beyond that then syntax can start diverging in larger ways.



Yeah, that's an unfortunate situation where you have to make do with what you have. Changing the stored procedures that feed into an application without the ability to access the application code sounds terrifying. These interact heavily and should be modified at the same time. It's not a thing that should be segmented among different teams.

I think of the stored procedures more like an API. Sure you can just not have an API and give everyone access to all the internals of your library and hope they use it in a supported way, or you can construct a well defined, well designed API that limits the ways you can use the library
 
Top Bottom