[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daglig programmeringstråd

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 152
Thread images: 17

File: sognefjord-norway.jpg (357KB, 1920x1080px) Image search: [Google]
sognefjord-norway.jpg
357KB, 1920x1080px
Hva jobber dere med, /g/?

Gammelt tråd: >>59515417
>>
Hey guys, need some SQL help.

I have four tables;

Suppliers(S#, SNAME, STATUS, CITY)
Parts(P#, PNAME, COLOR, WEIGHT, CITY)
Jobs(J#, JNAME, CITY)

and SPJ(S#, P#, J#, QTY) which is a table which represents shipments of parts from suppliers to jobs. S, P, and J are all foreign keys to their respective tables. I need a query that gets the name of projects with one or more red parts supplied to it. Any tips in the right direction?
>>
>>59519708
Should mention projects are synonymous with jobs in my database.
>>
Daily remainder. Macros are the future.
>>
Explain this "putting your datastructure on the heap" meme
>>
>>59519755
If you're 'datastructure' is large enough to justify calling it a 'datastructure' and not simply an 'object', then you really can't count on the stack being able to hold it. Which means either heap or bss, and bss is only suitable for that if you know at compile time exactly how big your data structure is.
>>
>>59519797
upboat
>>
File: tumblr_nzq9seNb0J1s21xzoo1_500.gif (1MB, 500x278px) Image search: [Google]
tumblr_nzq9seNb0J1s21xzoo1_500.gif
1MB, 500x278px
>MFW MY BOOK FINALLY ARRIVED
>>
>>59519822
What book?
>>
>>59519708
>SPJ
Are you channeling Haskell's creator?
>>
File: 1474949335999.gif (245KB, 500x500px) Image search: [Google]
1474949335999.gif
245KB, 500x500px
>>59519822
congratulations desu sempai
>>
>>59519755
recursive persistent data structures my dude
>>
>>59519708

SELECT DISTINCT j.jname
FROM jobs j, parts p, spj
WHERE j.j# = spj.j#
AND spj.p# = p.p#
AND p.color = 'red';
>>
First for Turing machines and other abstract computers only define "possibility", not "practicality"
>>
>>59519868
This. Total languages are much more appropriate for many tasks.
>>
>>59519868
Elaborate for the dumbs please
>>
File: 20170322_131934.jpg (1MB, 2592x1944px) Image search: [Google]
20170322_131934.jpg
1MB, 2592x1944px
>>59519834
>>59519841
>>
>>59519886
Programming in D
>>
>>59519886
>D
Trash.
>>
>>59519897
Did I ask your opinion?
>>
>>59519901
Yes.
>>
>>59519909
Point to me where
>>
>>59519885
Turing completeness says that all Turing complete languages can do everything that any other Turing complete language can do, but it doesn't say that they're good at it
>>
>>59519886
Noice
>>
>>59519909
Could I get your opinion on my book? >>59519886
>>
>>59519925
So basically some languages are better at other things than others and some languages are just outright better than others
>>
>>59519945
Text looks kinda blurry, a misprinted copy maybe?
>>
>>59519797
>He doesn't analyze how much memory he needs and sets the stack size appropriately
Sad
>>
>>59519963
>He has to analyze how much memory he needs and sets the stack size appropriately
Sad!
>>
>>59519961
Basically, most languages are shit and computer science was a mistake.
>>
>>59519962
counterfeit programming books are huge business now, thanks pajeet
>>
If caches are so fast why don't we just use those instead of RAM?
Cache btfo
>>
>>59520027
can't download cache
>>
Anyone here use discord or other IM software, it'd be cool to have people to chat to in real time whilst programming
>>
>>59520046
>proprietary software
>>
>>59520046
Fuck off
>>
>>59520046
No, there isn't a /dpt/ discord, you should probably leave right now before someone lies to you and tells you there is, getting your hopes up.
>>
>>59520046
?
>>
>>59520046
https://discord.gg/MsHme
Don't expect much from us
>>
>>59520086
LE GAYMUR CHAT XDDDDDDDDDD
>>
>>59520056
>muh freedoms
>>
Discord shill fuck off back to >>>/v/
>>
>>59520105
Excellent post
>>59520122
Cry more
>>
>>59520122
This, IRC is still king
>>
>>59520132
>>>/v/
Go back, manchild
>>
>>59520132
>over the age of 20
>playing video games
Kill yourself, basement dweller
>>
>>59520133
What are some good programming IRCs then
>>
>>59520147
What language are you using?
>>
>>59520147
#lisp on freenode
>>
>>59520154
Don't bring /v/ to IRCs please
>>
Can software and OS be joined into one relation?
>>
>>59520138
>>59520144
Keep crying bitch niggas
>>
>>59520162
This.
>>
>>59520162
>implying /v/ even know what IRC is
Those babbies only know discord
>>
>>59520154
Scala for my coursework, Python and Java for fun. Learning MySQL at the moment and it's screwing me around a bit. The MySQL IRC was dead silent for hours.
>>
>>59520147
Google around friendo, and leave your silly comments at the door.
>>
>>59520184
irc://irc.freenode.net/scala
>>
>>59520184
Go to the #scalaz channel for help with Scala.
>>
Jesus, some guys are so productive
I often get sad and jealous of them ;_;

How do they do that? Advanced forms of autism?
>>
>>59520185
yeah this was pretty normie tier stuff, sorry boys.
>>
>>59520184
Pretty sure freenode has a channel for all those languages.
>>
>>59520165
What do you think?
>>
>>59520165
OS is software
>>
>including headers for templates in c++
what a headache
>>
>>59520211
Use a productive language
>>
>>59520211
Practice will give you more understanding how you can deal with certain problems. Learn how to use your language's features.
>>
>>59520234
It is and as OS has no other relationships in this model, it should be okay to implement this as just one relation assuming that OS has no other attributes that software does not have, is this correct?
>>
>>59520211
>they're productive so something must be wrong with them
anon...
>>
>>59519688
>what job is this with, /g/
>>
Why learn about turing machines if every computer that can be constructed in the real world is a finite state machine?
>>
>>59520270
CREATE TABLE computer(
id int NOT NULL PRIMARY KEY,
name varchar(15),
specs varchar(100),
price money,
os varchar(15),
package int
);

CREATE TABLE software(
serial int NOT NULL PRIMARY KEY,
os varchar(15) NOT NULL,
package int,
FOREIGN KEY(os) REFERENCES computer(os) ON UPDATE CASCADE ON DELETE REJECT,
FOREIGN KEY(package) REFERENCES computer(package) ON UPDATE CASCADE ON DELETE CASCADE
);



How'd I go?
>>
>>59520074
>steveklabnik
lol
>>
>>59520360
>every computer that can be constructed in the real world is a finite state machine?
While you can twist your logic and say that's true, it would be one of the most stupidly unhelpful ways of thinking about it.
>>
>>59519688
>>59520421
anyone?
>>
Explain this "putting your datastructure on the stack" meme
>>
>>59520599
It's guaranteed to work in every conforming implementation of 'c'.
>>
>>59520360
They allow for mathematical definitions of 'computation', and allow us to reason about computations more abstractly. How do computations relate? What does 'complexity' of a computation mean? Are there uncomputable things? (Turing ofc showed there are, i.e. Halting problem).
>>
What is the sexiest data structure? I'd say redblack trees are pretty hot
>>
>>59520550
BRB, creating a finite state machine for every 2^64+ states on my processor
>>
>>59520636
>2^64+
There is more than that. You've got to consider the state of your storage as well, and possibly the state of the universe around it.
>>
File: swans-to-be-kind.jpg (174KB, 1200x1200px) Image search: [Google]
swans-to-be-kind.jpg
174KB, 1200x1200px
>>59520647
>mfw the entire internet is just a huge state machine
>mfw I'm just a state machine
>>
>>59520630
I like the public class
>>
Explain this "putting your datastructure in the cloud" meme
>>
>>59520713
The cloud is undefined behavior.
>>
>Doing problems from chapter 1 of K&R
>Chapter has not covered the modulo operator
>The answer to one of their problems uses modulo

Is this book badly organized or did the authors assumed that you knew what modulo was?
>>
>>59520735
Remainder = Dividend - Dividend/Divisor
That being said, fuck C
>>
>>59520735
perhaps a bit of both
>>
what's the difference between C and C++
>>
>>59520735
>not knowing what modulo means since the time you are born
>>
>>59520735
>did the authors assumed that you knew what modulo was
Probably. It's not really a book for beginners.
>>
>>59520755
C is C++ for kids
>>
>>59520755
C++ is basically a bigger language built on top of C.

Many more features and such while being somewhat (to some extent, not fully) backwards compatible with C.
>>
>>59520768
but c is lower level, closer to the hardware i thought?

i thought kids liked everything to be abstracted, pointers hidden, everything's a virtual, everything's a class, everything's a reference, do little applets and webdev

incorrect?
>>
>>59520782
C is not a low level language, kids delude themselves into thinking it is
>>
>>59520793
i didn't say it was low level, just lower level than c++
>>
File: 1487635539415.png (40KB, 1620x774px) Image search: [Google]
1487635539415.png
40KB, 1620x774px
>>59520755
C is a somewhat minimal language, with a very focused design.
C++ is a fucking clusterfuck of random disparate features thrown together.

C has a certain elegance to its design. C++ does not.
>>
File: 1489530656576.jpg (49KB, 600x381px) Image search: [Google]
1489530656576.jpg
49KB, 600x381px
>>59520801
Not much difference remain.
>>
>>59520803
>C is a somewhat minimal language
Brainfuck is more minimal
>>
>>59520755
C for CS101
C++ for CS201
>>
File: js.jpg (792KB, 3264x1836px) Image search: [Google]
js.jpg
792KB, 3264x1836px
Webshits defend this shit.
>>
>>59520755
>what's the difference between C and C++
Same difference between primary level math and honors level maths
>>
>mobile apps class at uni
>primarily android
>prof forbids is from using any non-standard libraries to do our assignments

should i just drop out because this is fucking stupid no one actually makes apps like this
>>
>>59520849
>>mobile apps class at uni
>>
>>59520849
Pajeet detected
>>
>>59520832
>unconsciously picking some parts of the whole spec of a language merely constitutes calling it "Good parts" in a way to market it for the lowest common goy
>>
>>59520863
There are a lot of really bad parts though.
>>
>>59520862
ya dog im a pajeet because i dont want to code a custom graph when 10 billion libraries already exist that could make it in one line
>>
File: images.png (4KB, 236x213px) Image search: [Google]
images.png
4KB, 236x213px
>>59520755
>>
>>59520880
You just skim over them, you don't need a jew telling you which parts to look for.
>>
>>59520886
Uni shouldn't be about teaching you to click and drag components together. It should be about teaching you to be able to make the program that can be used to click and drag components.
>>
English thread:
>>59521230
>>59521230
>>59521230
>>
>>59519886
>>59519822
R8
import core.thread;
void fibonacciSeries(ref int current) {
current = 0;
int next = 1;

while (true) {
Fiber.yield();
const nextNext = current + next;
current = next;
next = nextNext;
}
}

void main() {
int current;
Fiber fiber = new Fiber(() => fibonacciSeries(current));

foreach (_; 0 .. 10) {
fiber.call();
import std.stdio;
writef("%s ", current);
}
}

> ldc2 main.d ;and ./main
0 1 1 2 3 5 8 13 21 34
>>
>>59520366
shit
>>
>>59521331
Literal dead memes.
>>
>>59519688
globale
centre est un cercle, x vaut 311, y vaut 285, couleur vaut "rouge", plein vaut "oui", rayon vaut 50
boule est un rectangle, largeur vaut 40, hauteur vaut 20, couleur vaut "noir", plein vaut "oui"
salle est une toile, couleur vaut "blanc"

collision :
début
efface toile
projette salle & centre & boule
va vers action

action :
début
temporise
déplace boule vers sourisx et sourisy
si boule est en collision avec centre, couleur de centre vaut "jaune"
sinon, couleur de centre vaut "rouge"
va vers action
>>
>>59521413
what programming language is this

I like it
>>
>>59521431
Linotte
>>
>Note that pi was declared immediately after the array. If the compiler happened to put it in memory immediately after the array, the result is disaster. When the pointer moves past the end of the array, the last location to be set to zero will be the one holding the pointer. This will still be less than &array[ARRAY_SIZE], so the loop will continue to execute.

Please tell me the likelihood of this happening is slim. Would the fix be to make it be a post decrement (rather than pre)? Or should the pointer REALLY be declared before the array?
>>
File: SussmanAbelsonBTFO.png (7KB, 1024x768px) Image search: [Google]
SussmanAbelsonBTFO.png
7KB, 1024x768px
>>59521331
Not bad, but check mine
>>
>>59521470
That example is extremely contrived.
You would almost always put the ++ inside the third section of the for loop.
>Would the fix be to make it be a post decrement (rather than pre)?
Yes.
>>
>>59520755
0
>>
>>59521470
What's the point of that anyway if you can just call memset?
>>
>>59521660
>just call memset
You can do it even more easily with
int array[ARRAY_SIZE] = {0};
>>
>>59521688
Your code would write zeros to binary (large arrays, big binaries). memset(3) will just write some instructions.
>>
>>59521331
>>59521471
>doesn't print the entire sequence
(defun fib ()
(let ((x (list 0 1)))
(mapcar (lambda (y) (setf (cdr (last x)) (list (+ y (first (last x)))))) x)))
>>
>>59521784
No it wouldn't. A compiler is more than smart enough to know that it doesn't need to store a bunch of zeros.
>>
>>59521807
What's the run time of that for fib(100)?
>>
>>59521906
That was a shitpost. It never completes.
>>
>>59521906
Something that does terminate:
(defun fib (n)
(let ((x (list 0 1)))
(cond ((= n 0) (first x))
((= n 1) x)
(t (dotimes (i n x)
(setf (cdr (last x)) (list (+ (nth i x) (first (last x))))))))))

CL-USER> (time (fib 100))

Evaluation took:
0.000 seconds of real time
0.000000 seconds of total run time (0.000000 user, 0.000000 system)
100.00% CPU
191,056 processor cycles
0 bytes consed
>>
>>59522071
>(cond ((= n 0) (first x))
Meant to write
(cond ((= n 0) (list 0))
.
>>
File: crying_pepe.jpg (26KB, 299x289px) Image search: [Google]
crying_pepe.jpg
26KB, 299x289px
>>59521960
Don't worry. I have a cs background and I suck at programming ;_;
>>
A statically unverifiable sorting "algorithm".
with Ada.Numerics.Discrete_Random;
with Ada.Text_IO;

procedure Sort is
type Index is range 1 .. 10000;
subtype Samller_Index is Index range Index'First .. Index'Last - 1;
type Data_Array_Type is array (Index) of Integer;

package Rand_Integer is new Ada.Numerics.Discrete_Random (Integer);
package Rand_Index is new Ada.Numerics.Discrete_Random (Samller_Index);
use Rand_Integer;
use Rand_Index;

Integer_Generator : Rand_Integer.Generator;
Index_Generator : Rand_Index.Generator;

Data : Data_Array_Type;

function Is_Sorted (Data : in Data_Array_Type) return Boolean is
(for all I in Data'First .. Data'Last - 1 =>
Data(I) <= Data(I+1));

begin

Reset(Integer_Generator);
Reset(Index_Generator);

for I of Data loop
I := Random(Integer_Generator);
end loop;

while not Is_Sorted(Data) loop
declare
Index : Samller_Index := Random(Index_Generator);
Temp : Integer;
begin
if Data(Index) > Data(Index + 1) then
Temp := Data(Index);
Data(Index) := Data(Index + 1);
Data(Index + 1) := Temp;
end if;
end;
end loop;

for I of Data loop
Ada.Text_IO.Put(Integer'Image(I) & " ");
end loop;

end Sort;
>>
File: summation_of_primes.png (14KB, 542x202px) Image search: [Google]
summation_of_primes.png
14KB, 542x202px
Pic related is problem.
Why does this program
#include <stdio.h>
#include <stdlib.h>

enum {
MAX = 2000000
};

int main()
{
unsigned long long sum = 2;
unsigned long *primes = malloc(sizeof(unsigned long) * MAX);
size_t len = 1;
char isprime = 0;
int j, i;

primes[0] = 2;

for (i = 3; i < MAX; i+=2) {
isprime = 1;
for (j = 0; j < len; j++) {
if (i % primes[j] == 0) {
isprime = 0;
break;
}
}
if (isprime) {
primes[len++] = i;
sum += i;
}
}
printf("Sum = %llu\n", sum);
free(primes);
return 0;
}

so much slower than this
#include <stdio.h>
#include <math.h>

int isprime(long n)
{
int i;
for (i = 3; i <= sqrtl(n); i += 2)
if (n % i == 0)
return 0;
return 1;
}

int main()
{
int i;
unsigned long long sum = 2;

for (i=3; i < 2000000; i += 2)
if (isprime(i))
sum += i;
printf("Sum = %llu\n", sum);
return 0;
}

This first one doesn't recalculate primes while the second one does. Is memory access that expensive in C? Why does this javascript version run faster than the C one?
function isPrime(num) {
var start = 2;
while (start <= Math.sqrt(num)) {
if (num % start++ < 1) {
return false;
}
}
return num > 1;
}

function primeRange(min, max) {
var primes = [];
while (min < max) {
if (isPrime(min)) {
primes.push(min);
}
min++;
}
return primes;
}

console.log(primeRange(0, 2000000).reduce((sum, i) => sum += i));
>>
>>59522354
That's the cost of accessing memory, in general. Also you'll be thrashing the cache at upper values of 'len'
>>
>>59522517
Why would it be thrashing cache? Also, why would javascript be faster than C, despite C running with -O3?
>>
>>59522539
That array is too big to fit
>>
>>59522587
But why is Javascript faster than optimized C?
>>
>>59522613
The javascript version is pushing to a queue and not accessing the primes during the run. The C one does.
>>
>>59522587
>>59522613
On my machine:
$ gcc -std=c99 -Wall -O3 -o primes primes.c -lm
$ time ./primes
Sum = 142913828922

real 0m0.796s
user 0m0.792s
sys 0m0.000s

$ time js primes.js
142913828922

real 0m0.681s
user 0m0.680s
sys 0m0.000s
>>
>>59522354
>>59522539
>Is memory access that expensive in C?
Yes, memory access is a lot slower than you think it is.
(trimmed) Cachegrind output for the first:
Sum = 142913828922

D refs: 11,100,884,754 (11,100,723,927 rd + 160,827 wr)
D1 misses: 1,386,102,092 ( 1,386,082,903 rd + 19,189 wr)
LLd misses: 21,035 ( 1,924 rd + 19,111 wr)
D1 miss rate: 12.5% ( 12.5% + 11.9% )
LLd miss rate: 0.0% ( 0.0% + 11.9% )

LL refs: 1,386,103,038 ( 1,386,083,849 rd + 19,189 wr)
LL misses: 21,962 ( 2,851 rd + 19,111 wr)
LL miss rate: 0.0% ( 0.0% + 11.9% )

and the second
Sum = 142913828922

D refs: 180,779,490 (90,406,688 rd + 90,372,802 wr)
D1 misses: 3,470 ( 2,864 rd + 606 wr)
LLd misses: 2,567 ( 2,042 rd + 525 wr)
D1 miss rate: 0.0% ( 0.0% + 0.0% )
LLd miss rate: 0.0% ( 0.0% + 0.0% )

LL refs: 4,440 ( 3,834 rd + 606 wr)
LL misses: 3,514 ( 2,989 rd + 525 wr)
LL miss rate: 0.0% ( 0.0% + 0.0% )

Just look at how many times you're hitting memory, and how many of those are cache misses.
Considering that most numbers being checked for being prime will 'fail' fairly quickly, going through a few divisions/branches will be quicker than hitting memory so often.

>>59522613
>But why is Javascript faster than optimized C?
The compiler will not (and cannot?) optimise for cache usage. It's not the domain that compilers work in.
Mike Acton has a good talk about this: https://www.youtube.com/watch?v=GPpD4BBtA1Y
>>
>>59522636
But then what about the memory accessing? As the size of the primes list increases, wouldn't it cause the same problems as the C program?
>>
>>59522647
I forgot to put my main point for the reference to >>59522613.
You can write crap programs in a fast language. Just because C is faster than JS, it doesn't mean that a poorly written C program will always outperform a well written JS (or any language) program.
>>
>>59522669
What would you improve in the C version to make it faster than the Javascript version then?
>>
>>59522689
I don't really know what the JS JIT optimisers are up to, but I suspect they aren't actually memorising the values like you asked, and is doing something much close to the second C example.
>>
>>59519868
Only a retard would think that a model of computation can possibly define "practicality"
>>
>>59522760
SHIEEET. I just found this:https://stackoverflow.com/questions/18157322/find-the-sum-of-all-the-primes-below-two-million-project-euler-c
Specifically this:
#include <stdio.h>
#include <string.h>

#define ISBITSET(x, i) (( x[i>>3] & (1<<(i&7)) ) != 0)
#define SETBIT(x, i) x[i>>3] |= (1<<(i&7));
#define CLEARBIT(x, i) x[i>>3] &= (1<<(i&7)) ^ 0xFF;

long long sumPrimes(int n) {
int m = (n-1) / 2;
char b[m/8+1];
int i = 0;
int p = 3;
long long s = 2;
int j;

memset(b, 255, sizeof(b));

while (p*p < n) {
if (ISBITSET(b,i)) {
s += p;
j = (p*p - 3) / 2;
while (j < m) {
CLEARBIT(b, j);
j += p; } }
i += 1; p += 2; }

while (i < m) {
if (ISBITSET(b,i)) {
s += p; }
i += 1; p += 2; }

return s; }

int main(void) {
printf("%lld\n", sumPrimes(2000000));
return 0; }


Running it:
$ time ./fprimes
142913828922

real 0m0.008s
user 0m0.008s
sys 0m0.000s

I need to do more reading.
>>
>>59522071
Since when does time count processor cycles?
How does anything even count processor cycles?
>>
>>59519688
>>59519688
>Hva jobber dere med, /g/?
Not Norwegian, just learning.

Shouldn't it be:
>Hva jobber er du arbeid på?
>>
>>59523061
>How does anything even count processor cycles?
There's special instructions for that.
But usually they aren't that useful, since things may interrupt execution and the processor doesn't know about processes
>>
>>59523132
Actually, I thought about it and the verb be is unnecessary and wrong.

Shouldn't it actually be:
>Hva jobber arbeider du på?
>>
Is there a better book fo Erlang than learn you some erlang for great good?
>>
File: 1456167014514.jpg (40KB, 563x542px) Image search: [Google]
1456167014514.jpg
40KB, 563x542px
>>59523132
>>59523345
Hva jobber dere med = What are you working on/with
Hva jobber arbeider du på = What are you working working on
I'm pretty tired, sorry if the translating is wrong.
Also, "du" is singular and "dere" is multible
Thread posts: 152
Thread images: 17


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.