Jump to content
RenCorner Network

Anyone feels my pain ?


Recommended Posts

Posted

so i was studying for web services exam , and i stumble upon this while looking at some Xquery code for the first time :

 

for $p in distinct-values(document("bib.xml")//publisher)
let $a :=avg(document("bib.xml")//book[publisher = $p]/price)
return <publisher> <name>{ $p/text() }</name> <avgprice>{ $a }</avgprice> </publisher>
:returns all publishers with their average book price:
 
and then i spit my tea all over the keyboard... apparently u can return multiple times ? hell u can loop it O.o  . I've always were more into programming(java , c ...) than scripting
for multiple reasons like lack of usual punctuation and brackets and the stupid $ sign and the stupid := , but THIS , this just draws the line for me , i feel like i dont wanna code anymore :(
seems stupid i know , but i felt like i have to rewire my brain in order to accept such a thing just to pass one exam lol .
Posted

I do feel your pain. That is just wrong. though I presume what is actually happening is it returns once at the end of the for loop and hands back a list or some such containing all the values. :-p

Posted

Just think of it a python's yield I guess, it's (generally) more efficient and uses less RAM than filling an array and returning it (the return you like :P)

Posted

Just think of it a python's yield I guess, it's (generally) more efficient and uses less RAM than filling an array and returning it (the return you like :P)

how is it more ram efficient ? when u return an array ur simply returning the pointer to the first item , i doubt it can be more efficient than that Oo

Posted

But the pointer is pointing at a massive memory chunk full of whatever you're returning..

With yield you're just using the same memory (effectively) over and over to return different objects

 

Here's a fairly terrible example

/* Example one, allocate 1000 ints, initialise them and return */int* dem_ints = malloc(1000*sizeof(int));for (int i = 0; i < 1000; ++i) {    dem_ints[i] = i;}return dem_ints;/* Example two, pretend C has a yield statement :v */for (int i = 0; i < 1000; ++i) {    yield i;}
Posted

 

But the pointer is pointing at a massive memory chunk full of whatever you're returning..

With yield you're just using the same memory (effectively) over and over to return different objects

 

Here's a fairly terrible example

/* Example one, allocate 1000 ints, initialise them and return */int* dem_ints = malloc(1000*sizeof(int));for (int i = 0; i < 1000; ++i) {    dem_ints[i] = i;}return dem_ints;/* Example two, pretend C has a yield statement :v */for (int i = 0; i < 1000; ++i) {    yield i;}

still the same shit ... its not like ur gonna be using less ram . And about that "using same blocks " thing ... free() anyone ? Its the same for both , but the syntax is horrible with for{return ; } thats all im saying

even worse later as i was studying i find this shit :

return if condition() {}else {} ... its just looks bad to ma brain lol

 

anyways i did the exam today ... finished it and still had 23 minutes left :P It started out as multiple choice and bs , then he started asking for code im like :character0036:

 

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...