[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - daily programming thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 15
File: mongodb.png (27 KB, 413x484) Image search: [Google]
mongodb.png
27 KB, 413x484
NoSQL edition
>2016
>using SQL
Nice job Pajeet

Old thread
>>54784717
>>
first for my wife's son and his passion for OOP
>>
>>54788666
satan's thread? satan's thread
>>
>>54788666
>using a "database" that doesn't provide ACID
>>
>>54788666
second for web scale
>>
>>54788666
thank you for not posting a fag thread.
>>
can someone tell me how to make a function that takes the area of rectangle and outputs it into main?
>>
Working on using elaboration of implicit arguments, including sizes for termination/productivity checking, and universe levels during bidirectional type checking instead of having a complex, separate unification algorithm.
>>
Signs you're a code monkey
>don't know fuzzy logic
>don't know about linear programming
>can't into convex optimization
>can't prove program is correct
>can't prove complexity of program
>doesn't know lisp, haskell and prolog
>thinks java is a perfectly acceptable language
>>
signs you're a smug tard:
>>54788718
>>
>>54788697
I can't believe we used to have those old databases that would never scale to my ten-thousand (!) customers a day
>>
kill yourself retarded hasklel rust sperg
>>
something is wrong with the case statements.
int computerchoice()
{
srand(time(0));
int compchoice = srand()2;

return compchoice;
}

int main()

{
int player_choice = 0;

cout << "Enter 1 for paper, 2 for rock, and 3 for scissors: " << "\n";
cin >> player_choice;

int comp_number = player_choice();

switch(player_choice);
{
case 0:

if (player_choice == 1)
cout << "You picked paper and I picked paper. It is a tie! \n";
if (player_choice == 2)
cout << "You picked rock and I picked paper. You lose! \n";
if (player_choice == 3)
cout << "You picked scissors and I picked paper. You win! \n";
break:
case 1:

if (player_choice == 1)
cout << "You picked paper and I picked rock. I lose! \n";
if (player_choice == 2)
cout << "You picked rock and I picked rock. It is a tie! \n";
if (player_choice == 3)
cout << "You picked scissors and I picked rock. You win! \n";
break;
case 2:

if (player_choice == 1)
cout << "You picked paper and I picked scissors. I lose! \n";
if (player_choice == 2)
cout << "You picked rock and I picked scissors. You win! \n";
if (player_choice == 3)
cout << "You picked scissors and I picked scissors. It is a tie! \n";
break;

default(player_choice != 1 || player_choice != 2 || player_choice != 3);
cout << "I don't recognise that input! \n";
}
>>
>>54788771
lmaoing at your life desu


sorry for shitposting
>>
>>54788771
>break:
>>
>>54788771
7/10 if bait
>>
>>54788666
Looks like you messed up the thread title OP.
It was meant to be "/wdg/ - Web Development General"
>>
>>54788666
>mongoloid database
HA!
>>
>>54788809
>implying only ruby artisans use databases
>>
>>54788718
>Signs you're a useless CS student.
>>
>>54788782
I don't understand why you said desu?
>>
File: 747.jpg (34 KB, 600x450) Image search: [Google]
747.jpg
34 KB, 600x450
>>54788718
>>can't prove program is correct

If you are a functional programmer, your programs ARE the proofs. :^)
>>
>>54788875
t b h (to be honest) is filtered to desu, autists like me use nigger speak ironically and mootykins filtered it because he's a meme
>>
>>54788875
It's the jap filter
>>
desu
>>
>>54788771
anon, what the fuck are you doing?

lemme enumerate the code so other people can show you some errors:
 1 int computerchoice()
2 {
3 srand(time(0));
4 int compchoice = srand()2;
5
6 return compchoice;
7 }
8
9 int main()
10
11 {
12 int player_choice = 0;
13
14 cout << "Enter 1 for paper, 2 for rock, and 3 for scissors: " << "\n";
15 cin >> player_choice;
16
17 int comp_number = player_choice();
18
19 switch(player_choice);
20 {
21 case 0:
22
23 if (player_choice == 1)
24 cout << "You picked paper and I picked paper. It is a tie! \n";
25 if (player_choice == 2)
26 cout << "You picked rock and I picked paper. You lose! \n";
27 if (player_choice == 3)
28 cout << "You picked scissors and I picked paper. You win! \n";
29 break:
30 case 1:
31
32 if (player_choice == 1)
33 cout << "You picked paper and I picked rock. I lose! \n";
34 if (player_choice == 2)
35 cout << "You picked rock and I picked rock. It is a tie! \n";
36 if (player_choice == 3)
37 cout << "You picked scissors and I picked rock. You win! \n";
38 break;
39 case 2:
40
41 if (player_choice == 1)
42 cout << "You picked paper and I picked scissors. I lose! \n";
43 if (player_choice == 2)
44 cout << "You picked rock and I picked scissors. You win! \n";
45 if (player_choice == 3)
46 cout << "You picked scissors and I picked scissors. It is a tie! \n";
47 break;
48
49 default(player_choice != 1 || player_choice != 2 || player_choice != 3);
50 cout << "I don't recognise that input! \n";
51 }


line 17: player_choice is NOT A FUNCTION, but an int.
line 12, you set player_choice as 0, and never modify it... why are you switch()'ing over it? and, in the switch, you are checking player_choice MANY TIMES.
>>
>>54788899
Wait, it's still active? I thought it was removed a while ago, although I'm not an underage cringy teenage who uses niggerspeak (ironic shitposting is still shitposting).

Testing:
desu
senpai
baka
>>
>>54788924
Oh it is, thank you Hiro.
>>
>>54788875
nihongo ga wakanai?????? baka gaijin tbqh
>>
>>54788924
lowercase cuck is not filtered any more
>>
>>54788919
>line 12, you set player_choice as 0, and never modify it
He does, on line 15. But his code is so retarded I find it hard to believe he's not baiting.
>>
>>54788970
what about uppercase KEK
>>
>>54789012
oh, right, didn't see that.
but yeah, it's probably bait, and I fell for it
>>
>>54788713
triangleArea width height = (width * height) / 2
>>
>>54789020
Why is uppercase cuck filtered anyway? like what's the point?
>>
fixed it
int computerchoice()
{

srand(time(0));
int compchoice = rand();2;

return compchoice;
}

int main()

{
int comp_number;
int player_choice = 0;

comp_number = computerchoice();

cout << "Enter 1 for paper, 2 for rock, and 3 for scissors: " << "\n";
while(cin >> player_choice)

switch(player_choice)
{
case 0:

if (player_choice == 1)
cout << "You picked paper and I picked paper. It is a tie! \n";
if (player_choice == 2)
cout << "You picked rock and I picked paper. You lose! \n";
if (player_choice == 3)
cout << "You picked scissors and I picked paper. You win! \n";
break;
case 1:

if (player_choice == 1)
cout << "You picked paper and I picked rock. I lose! \n";
if (player_choice == 2)
cout << "You picked rock and I picked rock. It is a tie! \n";
if (player_choice == 3)
cout << "You picked scissors and I picked rock. You win! \n";
break;
case 2:

if (player_choice == 1)
cout << "You picked paper and I picked scissors. I lose! \n";
if (player_choice == 2)
cout << "You picked rock and I picked scissors. You win! \n";
if (player_choice == 3)
cout << "You picked scissors and I picked scissors. It is a tie! \n";
break;

default:(player_choice != 1 || player_choice != 2 || player_choice != 3);
cout << "I don't recognise that input! \n";
break;
}
>>
>>54789133
Just stop.
>>
>>54789133
you're just not cut out for this bud
>>
>>54789150
actually the third option doesn't work.
>>
File: 1462158485548.jpg (33 KB, 512x512) Image search: [Google]
1462158485548.jpg
33 KB, 512x512
>>54789133
>
int compchoice = rand();2;

>
cout << "Enter 1 for paper, 2 for rock, and 3 for scissors: " << "\n";

>
while(cin >> player_choice)

>That entire switch block
>
default:(player_choice != 1 || player_choice != 2 || player_choice != 3);
>>
I have an extremely stupid question about c++, but I'm a total newfag learning and my brain cannot process this. Any help would be appreciated:

In simple-english, how do forward declarations work? I mean, sure it declares a function before using it so the compiler doesn't throw errors at you. But why and how do forward declarations make it possible to call a function from another file? You are declaring a function exists, sure, but you aren't really giving said function any body, so how does the program know what the function is supposed to do? Does the compiler see this declaration and then checks the entire code and files for said function?
>>
>>54789267
https://en.wikipedia.org/wiki/Linker_(computing)
>>
>>54789133
I'll assume you are a noob programmer, and that this is not bait.
you don't need those "if (player_choice == N)" checks, when you are already checking for that in the switch.
>>
>>54789133
(defun rock-paper-scissors (player1 player2)
(labels ((rockp (hand)
(equal hand 'rock))
(scissorsp (hand)
(equal hand 'scissors))
(paperp (hand)
(equal hand 'paper)))
(cond ((equal player1 player2) 'tie)
((and (rockp player1) (scissorp player2)) 'player1-wins)
((and (paperp player1) (rockp player2)) 'player1-wins)
((and (scissorsp player1) (paperp player2)) 'player1-wins)
(t 'player2-wins))))
>>
In new C/C++ programs, are there any good reasons to use Digraphs?
>>
>>54789318
import rps
rps.run()
>>
>>54789318
This is worse than his.
>>
File: yodabait.jpg (147 KB, 500x378) Image search: [Google]
yodabait.jpg
147 KB, 500x378
>>54789321
>>
>>54789321
Sure, if your keyboard doesn't have the correct symbols.
>>
File: redis-white.png (5 KB, 240x80) Image search: [Google]
redis-white.png
5 KB, 240x80
Giving a shoutout to redis.

Redis is an in-memory key-value storage server typically used as a database and for caching and queuing.
It feels simple at first but its actually really powerful.

Think of it as a better memecached

- Very fast
- BSD License
- Supports things like strings, sets, lists, hashes, Pub/Sub, Transactions...
- Very easy to scale (easy to use clustering / data replication).
- Considered to be one of the cleanest C projects out there (code wise)
- Adopted by lots of companies & communities
- Commercial support
- Extendable with "modules" which are also written in C, like the 3rd party "password" module that allows you to store pw hashes.
- Lots of clients

I have used Redis as the backed for chat applications, machine-to-machine communications (my software and someone else's), background worker queuing (sidekiq: emails, transactions, ...) and also as general database.

I just realized its my favourite piece of software.
>>
>>54789356
>memecached
>>
>>54789356
redis (C) is best used on IBM (TM) machines. my company's revenue stream more than doubled after our switch to this system.
>>
>>54789373
>memecached
I did not write this on purpose, fml im spending to much time here.
>>
How can I make the numfactors function more efficient? I know there is a lots less stupid way to do it but I'm not seeing it. Project euler problem 12.

Ta

trianglenums = [sum [1..x] | x <- [1..]]

isqrt x = floor . sqrt $ fromIntegral x

over500factors n
| numfactors > 500 = True
| otherwise = False
where numfactors = 2 * length [x | x <- [1..isqrt n], n `mod` x == 0]

divisors = filter $ over500factors

main = print $ head $ divisors trianglenums
>>
what is a good environment to code in python? sublime text? or is there a good framework with debugger, unit testing and shit

please avoid shitposting about how terrible python is and just answer the question
>>
>>54789439
>more efficient?
By using OCaml.
>>
>>54789450
PyCharm
>>
>>54789456
thanks for that answer family it was very helpful

:^)
>>
>>54789439
JFC anon, stop abusing comprehensions and learn to write more succinctly (using point-free, not switching on a bool only to return the bool, etc.).

As for your problem, I think numfactors isn't the real issue. For one, you're trying to sum an infinite list in trianglenums - that's non-terminating.
>>
>>54789115
Hiroshima is ridiculously bad at regex. For instance, many variations of /reddit/ are spamfiltered, but any punctuation after it is OK. Same with how only cuck in fullcaps or nocaps have filters, not any other caps.
>>
>>54789439
>
trianglenums = [sum [1..x] | x <- [1..]]

learn2math
>>
>>54789462
thanks, trying it out
>>
>>54789505
Hmm, maybe that's not it. I guess technically you're not ever summing an infinite list, only at the limit.

I think, still, your problem is in trianglenums. There's a much more efficient way to calculate the sums than that, not to mention that you can get an approximation (overestimated) of the square root at the same time.
>>
>>54789563
both lowercase and uppercase cuck used to be filtered since moot's time with the ben garrison /pol/ thing or whatever when cuck became a meme, then hiroshima nagasiki unfiltered 'cuck' on anon's request in /qa/
>>
>>54789505
But haskell is lazy so because I only ask for the first element in divisors it will only take enough from trianglenums to get the first one.

I know it works, it just takes about 5 seconds to run when I know it can be a lot faster cause my C version takes 0.6 seconds

In regards to me abusing list comprehensions, I know I use them a bit too much, but I'm not sure how better to do it.

Of course the numfactors should probably be written without a list comprehension I just can't think how.

Maybe I should read a bit more of the thing I was using to learn as I don't know that much yet but I wanted to do some actual programming to get used to the syntax and how it all works.

>>54789567
Is this better?

trianglenums = [x*(x+1) `div` 2 | x <- [1..]]
>>
>>54789647
The list comprehension in numfactors can be done with filter and trianglenums shouldn't be doing any list processing (other than producing an infinite sequence) in the first place.
>>
>>54789439
trianglenums = [sum [1..x] | x <- [1..]]

Performs like this:
take 10000 trianglenums
--output
(4.45 secs, 8,384,577,824 bytes)


tri a x = a : tri (a+x) (x+1)
trianglenums' = tri 1 2

Performs like this:

take 10000 trianglenums'
--output
(0.24 secs, 72,713,656 bytes)
>>
>>54789647
Here's an example of how much you can condense stuff:
-- don't actually continue using this, just get an approximate at the same time that you calculate the "triangle number"
isqrt = floor . sqrt . fromIntegral

over500factors n = 2 * length (filter isFactor [1..isqrt n]) > 500 where
isFactor x = n `mod` x == 0
>>
The C cleanup attribute is pretty based

#include <stdio.h>

void f(char **c)
{
puts(*c);
}

#define cleanup(f) __attribute__((cleanup(f)))

int main(void)
{
cleanup(f) char *c = "hello world";
}
>>
Once i inject my dll in a process and get my code running, how can i find a specific imported function and hijack that so i can read its function arguments and then execute that function as it would have executed before?
>>
>implement cellular automaton
>no idea what to do with it

What are some good things to do with wire world?
>>
Can anyone post link to some decently written, serious, open source video game repo?
And by 'serious' I mean something definetly more profound than flappy birds.
>>
>>54789702
That function is a lot better than mine, thanks.

What do you mean by get an approximate of a square root when you calculate the triangle number though?

>>54789682
That triangle number function is really cool, I would have never thought of that. How did you get the time to do that? I can't really tell if yours is faster than this one just by eye
>>54789647
>>
Hey guys I really suck at error handling.

Does anyone have any helpful links that explain worthwhile patterns for handling errors and making sure things fail fast when I need them to?

I don't care about the programming language the articles/posts/whatever are written in
>>
>>54789843
there are shitloads of free and/or open source games out there, anon
>>
>>54789743

I was tinkering with that the other day.

free_me(strf) char *buf = ...


Would be nice if these attributes were standardized.
>>
>>54789892
But I got the impression that most of them are java or python entry level "penguin eating fish" amateur exercises. I'd like to see some decent code and good practices.
>>
this overrides the print() function in python and works perfectly:
http://pastebin.com/RgXc7Rz5

But it doesn't work when I import it as a helper.py.
How can I import it without breaking functionality?

from helper import print doesn't work and neither does import helper / helper.print()
>>
>>54789743
I prefer Go's "defer"

>inb4 defer existed before Go!!1
Go wasn't made to be original, quite the contrary. It takes some good things from many langs.

>>54789954
then google it: "FOSS games"
>>
>>54789843

https://github.com/CRYTEK-CRYENGINE/CRYENGINE
>>
>>54789844
n = x(x - 1)/2 = 0.5(x^2 - x)
n < 0.5x^2
n^0.5 < 0.5^0.5 * x

So your approximate square root can be (0.5^0.5 * x).

Though I'm sure that the normal square root is fast enough that the fewer iterations will more than compensate for it, now that I think about it.
>>
>is casting too expensive in games?
>what about using 'new' or 'delete' instead of allocating memory?
>should I use stack everywhere I can?
>should I utilize binary operations everywhere I can?
>>
>>54790017
if you're not writing games in assembly you're doing it wrong
>>
>>54790017
It's 2016, none of those things are expensive unless you're doing it hundreds of thousands of times per second.
>>
File: moot.jpg (85 KB, 1024x512) Image search: [Google]
moot.jpg
85 KB, 1024x512
>>54790017
Who are you quoting?
>>
test
>>
>>54790063
Well, the part about heap memory is an issue because it can lead to fragmentation and bad cache usage. Though I'm assuming the question was really talking about something stupid like new vs. malloc which wouldn't make a difference.
>>
>>54790085
did it work?
>>
>>54790115
>fragmentation and bad cache usage
It's fine anon.
Don't try to optimize shit until it shows up as a bottleneck in profiling.
>>
>>54790085
retest
>>
>>54789356
Redis actually serves a purpose (mongo does not, there is literally no use case for mongo where either redis or a relational database would be a better solution) but redis should not be used as a database like that. It's a key-value store, treat it as such.
>>
>>54790115
>fragmentation and bad cache usage
memory fragmentation is really underrated, like my issues with google chrome grinding to a halt until i restart it is probably caused by memory fragmentation, you can't just teach a monkey to use malloc and free and expect to get optimal performance
>>
>>54790118
yes >>54790144
>>
>>54790151

mongos use case is hey i dont wanna think about modeling data

ive used it to get up and running then eventually projected from it

i agree with your point though. i have no clue why its so popular
>>
>>54790085
how much disk space would it take to create and store 99.99% of the tripcodes?
>>
how are secure tripcodes more secure than plain tripcodes? is there some secret sauce on the server that salts the tripcode and if the secret sauce gets known it's easy to bruteforce secure tripcodes too?
>>
>>54790142
It's not hard to optimize for that. That's mostly a question of what data structure you use.
>>
>>54790237
11x92^1018 bytes

>>54790284
pretty much
the old secure tripcode salt was literally just appending "LOLOLOLOLOL" to the end of the password string
>>
>>54790324
>11x92^1018 bytes
there are no (known) attacks on the algorithm? what's the algorithm? I have no idea, t-b-h
>>
>>54790469
Google it.
>>
alias termacs='emacs -nw'

10/10 would recommend
>>
>>54790577
how about
;; in your init
(require 'server)
(unless (server-running-p)
(server-start))

and
alias e='emacsclient -t'
>>
>>54790577
or
$ vim
>>
>>54789843
Check unreal engine 4 on github. Also check the id games that have been released
>>
>>54788666
Jag e mongo, du e också mongo
>>
>>54789843
http://fabiensanglard.net/doom3/
>>
rate MY code
int computerchoice()
{
srand(time(0));
int compchoice = srand()2;

return compchoice;
}

int main()

{
int player_choice = 0;

cout << "Enter 1 for paper, 2 for rock, and 3 for scissors: " << "\n";
cin >> player_choice;

int comp_number = player_choice();

switch(player_choice);
{
case 0:

if (player_choice == 1)
cout << "You picked paper and I picked paper. It is a tie! \n";
if (player_choice == 2)
cout << "You picked rock and I picked paper. You lose! \n";
if (player_choice == 3)
cout << "You picked scissors and I picked paper. You win! \n";
break:
case 1:

if (player_choice == 1)
cout << "You picked paper and I picked rock. I lose! \n";
if (player_choice == 2)
cout << "You picked rock and I picked rock. It is a tie! \n";
if (player_choice == 3)
cout << "You picked scissors and I picked rock. You win! \n";
break;
case 2:

if (player_choice == 1)
cout << "You picked paper and I picked scissors. I lose! \n";
if (player_choice == 2)
cout << "You picked rock and I picked scissors. You win! \n";
if (player_choice == 3)
cout << "You picked scissors and I picked scissors. It is a tie! \n";
break;

default(player_choice != 1 || player_choice != 2 || player_choice != 3);
cout << "I don't recognise that input! \n";
}
>>
>>54790781
this code is so retarded, please stop posting it
>>
>>54790781
does it even work?
>>
>>54790806
    int compchoice = srand()2;

I don't think so
>>
>>54789321
Yes if you're using a foreign keyboard.
Otherwise no.
>>
>>54790853
>Yes if you're using a foreign keyboard.
not even then
>>
>>54790781
sure is a bunch of repetition there
I wonder why people have created the phrase 'DRY'...
>>
>>54790867
Many foreign keyboards (especially non-latin) don't have the symbols to type some symbols.

I mean, you could memorize the alt-commands for them, but I feel like that's more trouble if you have <: equaling [.
>>
>>54790935
even in the worst scenario i think it'd be better to just deal with it and use keyboard shortcuts or macro keys or at least auto-clean the source code after writing it

digraphs could be completely removed in future versions of the standard
>>
File: 1383547691708.png (10 KB, 327x173) Image search: [Google]
1383547691708.png
10 KB, 327x173
>>54789743
>>
>>54789743
what the hell is that and what does it do?
>>
>>54791080
i'm guessing it calls the cleanup function after the variable goes out of scope
>>
>>54791080

Calls a cleanup function on the var at the end of its scope.
>>
File: vag.jpg (28 KB, 413x484) Image search: [Google]
vag.jpg
28 KB, 413x484
I'm not the only one who saw a vagina in this logo, am I?
>>
>>54791112
Get in here nigga, they're after your freedoms
>>/pol/75391462
>>
>>54789743
That's pretty cool, but you're not using it for the intended purpose.

Should have shown it off with a malloc and free.
>>
>>54791142
Ah fuck
>>>/pol/75391462
>>
>>54791115
That's a strech. Still looks like an upside down leaf.
>>
>>54791115
ohhhhh fuck it's True
>>NOOOOOOOOOO
Get new glass
>>
>>54791142
>>54791167

The first picture in that thread is one I designed and posted on /k/ two years ago. Not sure how it got around so much, but apparently people liked it. My work is already done.
>>
>>54791115
>>54791188
get your minds out of the gutter
>>
>>54791210
the one with the well balanced breakfast?
>>
>>54791210
>As long as liberals exist, guns are necessary.
U wot m8? It was liberals that gave you the right to a gun. Fuck the cucks calling themselves liberals today.
>>
>>54790017
>is casting too expensive in games?
casting is free. Assembly has no type. The type system just tells you what's wrong during compilation
>what about using 'new' or 'delete' instead of allocating memory?
Same thing. new is effectively a call to malloc with a cast.
>should I use stack everywhere I can?
Depends. Allocating memory is expensive, but reusing memory is cheap.
If you have a loop where you call "new" in it, it's better to allocate sizeof(YourType) memory and just cast it every time in the loop, calling a pseudo-constructor to re-initialize all the variables to their default values, such as memset if all your variables are null. The performance difference compared to having hundreds of stack variables can be negligible.
>should I utilize binary operations everywhere I can?
No. Most of the times, things will be optimized for you.
 x * 5 //usually gets converted to (x << 2) + x. 

This automatically happens, you don't need to worry about it.
>>
>>54791282
>muh clasical liberalism
fuck off sarcuck of kekold
>>
>>54791266

Yep.
>>
>>54791327
>casting is free
it can be relatively expensive
>>
>>54791282
>It was liberals that gave you the right to a gun.

My right to own a gun is from our divine creator. Classical liberals just reinforced it in writing the Bill of Rights.

Modern liberals are scum, but they have successfully hijacked the term.
>>
>>54791336
What? I guess you could call me a libertarian. But I have a secret love of monarchy.

>>54791388
>My right to own a gun is from our divine creator.
No. YOU protect your right through threat of force. That's the real, and that's how it should be.
>>
>>54791413
>No.

God won't be happy to hear this. He's on the phone and he's quite cross with you.
>>
>>54791382
Not in C.
I think the only thing is dynamic_cast from C++, which uses RTTI. That is expensive.

But
char* c = "hello world";
int i = (int)c;

Doesn't even generate any additional assembly. It's simply a move instruction.
>>
bigloo or chicken scheme?
>>
>>54791479
If you use Bigloo, you won't have to worry about Indians.
>>
>>54788718
Luckily you have your own custom language to bring to the company.
>>
is there a way to create a linux service that works on all distributions?

i've created an init.d file but all the tutorials i look at are outdated. the /etc/init.d/functions file seems to have been moved to /lib/lsb/init-functions.d on ubuntu.
the initlog command is missing even though all the things ive seen online use it.
>>
>>54791462
>Not in C.
yes, in C
>>
>>54791583
Linux distributions aren't standardized. The whole "freedom to hack" philosophy from the GNU and whatnot. "It'll never happen."
>>
>>54791631
so what do i do if i want to distribute my program that uses a daemon?
do i write an init script for every distribution imaginable?
>>
>>54791695

Release it with a very cryptic readme and wait for the community to fix it. It's the free software philosophy.
>>
>>54791604
When?
>>
>>54791695
Yep. Or just for the frequently used ones to get the ball rolling. Then let freetards do your work for you.
>>
Is multithreading and handling multiple cores better in Java than C?
>>
>>54791729
Probably worse, to be honest, because at least in C you have const and stuff isn't hidden from you.
>>
>>54791729
Is Java easier to use than C? There's your answer. Neither have some really useful way to handle multithreading like Go or Haskell.
>>
>>54791757
Yes, Java has ExecutorServices, ForkJoinPools amongst other things.
>>
>>54791725
hmm... i bet deploying on windows will be easier... though i intend for it to work on both.

so i guess i would write some sort of installation script that checks your distribution & version, then installs it.
but for sake of sanity & time i'd only support the newer versions of ubuntu/red hat/debian or whatever.

this is a lot more painful than i'd imagined it would be.
>>
>>54791729
it's really easy in java, but it's easy in C too if you know C well, just use synchronized blocks, volatile, AtomicBoolean, and in C use pthread and mutexes, fuck all those meme shits
>>
>>54791754
Uhh what? Java has the keyword 'final' which is pretty much the same as const. And how is that relevant to multithreading?
>>
>>54791766
Seems like things you can get from a library in C, or write yourself. That's my point. Java and C aren't different enough to matter in that regard. Just because one has some convenience functions set up doesn't make it easier as soon as you get to something more complex than making a simple calculation parallel.

>>54791781
This is probably correct though. And it is important. but it goes back to what's easier beside multithreading, Java or C?
>>
>>54791790
>AtomicBoolean
or AtomicInteger etc
>>
>>54791790
>good multithreading is using mutexes
Good multithreading is about avoiding sharing in the first place. C has more in place to help with that than Java. Having a ton of shared state and then patching it up with mutexes is horrible for performance.

>>54791794
It's not NEARLY as strong a condition as const, especially since almost everything in Java is a reference and final doesn't "go through" references.

Const is good for multithreading because it helps with the "multiple reads OR unique writes" without any extra machinery.

OP, can you pick any language, not just C or Java? Because both are useless when it comes to multithreading.
>>
just got the idea to make a tool that automatically displays the distance of people on okcupid from you because currently i have to plug it into google maps and click directions to see the distance. how should i go about doing this? only languages i know are java and C++ and minimal C
>>
>>54791327
>casting is free. Assembly has no type
(int)2.0
>>
>>54791870
anything non-trivial requires sharing

>C has more in place to help with that than Java
no it doesn't

you should minimize the amount of shared state but that's just common sense, doesn't really have anything to do with the language
>>
>>54791879
sounds like a job for greasemonkey and javascript.
figure out what page you want to modify, find the names of the elements you want to get the info from and go from there.
then you can have it automatically calculate it and insert it into the page.
>>
>>54788666
NOTICE; PostgreSQL does NoSQL better then mongoDB does.
>>
>>54791870
>It's not NEARLY as strong a condition as const

Const can be casted away.
>>
>>54791940
>anything non-trivial requires sharing
Not really, if you're using multithreading just to, say, accelerate a task rather than distribute it.

I already said that C has const while Java has final, which isn't as powerful.
>>
>>54791954
>just to
that's a trivial use of multithreading
>>
>>54791962
If you're writing a distributed application you shouldn't even be thinking at the thread level of abstraction.
>>
>>54791954
>I already said that C has const while Java has final, which isn't as powerful.
fuck off idiot

>>54791970
>>>/g/wdg
>>
>>54791790
>>54791813
>>54791870
>he thinks C has good multithreading support
Hahahaha oh wow.
>>
>>54791993
Better than Java, I said. Aside from Java's more extensive standard library.
>>
>>54791993
it has everything you need, other languages have meme abstractions on top of it at best

>>54791999
kill yourself retard
>>
>>54791970

If you're writing a distributed application, you should be using erlang.
>>
>>54791942
thanks for the direction
>>
>>54792005
>other languages have meme features
>other languages have meme abstractions
Didn't you used to spout about "Cmen"? Because you are one now.
>>
http://blog.wix.engineering/2015/12/10/scaling-to-100m-mysql-is-a-better-nosql/

MySQL > *
>>
>>54792021
the multithreading constructs in C and java are all you need, go and haskell bring nothing to the table except for giving smug delusional spergs like you a false sense of superiority
>>
>>54792054
Did I say anything about Go or Haskell?
>>
>>54792060
so you're just talking shit and have nothing "better" to suggest
>>
>>54792083
If you need to work at the thread level, which is more or less part of systems programming, I recommend something like Rust, which has type system features to prevent data races and the like.

For larger stuff, you should not even think about threads, and just use something like software transactional memory, which is available in plenty of languages, so you might as well pick something that's in general just nicer to use than C or Java.
>>
>>54788666
idk why people are pushing document stores, it's a fucking shit way to store data.
mongodb is especially crap, mandatory 64 bit oids, 48 bytes (!?) of overhead per entry, index limitations, limited bit-wise operators, buggy/non-existent drivers, incorrect implementation of the MMF system causes it to sit at 100% memory usage on some systems.
but hey, it's "web scale" so none of that matters.
>>
>>54792083
>>54792126
Applications that can go higher-level than threads (most) could also make good use of asynchronous programming.
>>
>>54791870
>It's not NEARLY as strong a condition as const
const in C is pretty much useless, it has practically no guarantees about anything.
>>
Holy shit it worked

>>54788666
>>54791943
PostgreSQL master race
>>
>>54792270
I always thought const was super important in C as everybody kept reminding me to use it when I started learning it. But then I found out that it does literally nothing but bitching when I try to change a const value. I always thought there were some crazy smart optimisations possible, but apparently there is no such thing.
>>
>>54792444
>crazy smart optimisations
that's what constexpr is for
>>
>>54792545
>C++

lmoa ok
>>
>>54791604
nice argument to back up that claim
>>
>>54788718
have 1 and a half years of college to go
missing fuzzy logic, convex optimization, lisp/haskell/prolog
feels good man
>>
>>54792619
>what are casts to/from float
>what are casts between different sized types
>what are sign extensions
>>
>>54792664
now it wasn't that hard, was it?
>>
>>54792444
const is a guarantee in a function signature that you're not going to modify anything the arguments point to.
>>
>>54791729
>Java or C
Just use Ada like a sensible person. Far better multithreading support than either.
>>
>>54791729
>Java
>No OpenMP
>>
I'm curious, besides people asking for help, what kind of people post in these threads?

I'm a full time developer (delphi, php, java, vba) and have no desire to discuss work outside of work and hide these threads every time.
>>
>>54792879
>(delphi, php, java, vba)

My condolences.
>>
>>54792888
>Here's $40 an hour to add in features and fix bugs for this company's 15 year old Access program.
>No thanks, I don't like VBA.
>>
>>54792879
People who sperg at each other over small details of C or Haskell. Language elitism. Politics occasionally. No one here is actually passionate about programming, or anything for that matter.
>>
By making the function 'diffSplit', I was able to pretty much chain the solution.
I had to break the chain to account for no targets being found, but if you didn't care about that crashing the program, it could all be chained
/*
Given a string of repeating characters and a list of targets,
find the longest consecutive string of target letters in the
given string.

findConsecutive("AAAZZGYYYYYYYYQ", ["G", "Q", "Z"]);
// returns 2, because two Z's
*/

var str = "HAACCCVVVHGJJJDKDNWIEUDNDNDDDLLLWEEJJJTTTIIILWWWWITUENXXNGXGFFFFFFZ";
var targets = ["A", "B", "C", "W", "R"];

function differenceSplit(arr){
var ret = [];
for(var i = 1, l = arr.length, curr = [arr[0]]; i < l; i++) {
if (arr[i] != arr[i - 1]) {
ret.push(curr);
curr = [arr[i]];
}
else
curr.push(arr[i]);
}
return ret;
}
Array.prototype.diffSplit = function () {
return differenceSplit(this);
};

var result = str
.split('')
.diffSplit()
.filter(x => targets.includes(x[0]))
.sort((h,b) => h.length < b.length ? 1 : h.length > b.length ? -1 : 0)
.slice(0, 1);

/*
If targets = [], or none of the targets are found in the search string,
then calling result[0].length will crash the program because of a
dereferencing null error. So in order to account for both those
situations, result.length must be checked.
*/
if (result.length)
console.log("Longest consecutive character: "
+ result[0][0] + ", "
+ result[0].length + " times.");
else console.log('No targets found.');
>>
>>54792905

I have principles.
>>
Any C connoisseurs around? Halp!
>>54785521
>>
>>54792879
trust me
nobody would want to discuss any
>delphi, php, java, vba
>>
>>54792879
i'm a developer with only a few years of experience. trying to get on my feet. most of /g/ is shit however i do learn things by osmosis. but if you take anyone's opinion for granted you'll find yourself in trouble.
>>
>>54793009
How is the string stored? Null terminated, or can it contain arbitrary bytes with a specified length. I'd suggest casting the function to a char* and sending that with a length of 4. If it has to be a null terminated string you'll have to cast the function pointer to uint64_t, sprintf it, send that, unmarshal, cast and dereference. That would be an enormous source of bugs. God forbid you have to do that.
>>
>>54793092
>God forbid you have to do that
It's C, so he probably has to do that. Also you forgot to take into account 32/64 bit point size differences, should he want to use the same code on different architectures.
>>
>>54793135
Simple.
char* meme(void* ptr)
{
char* out = malloc((size_t)(8*sizeof(char*)*log(2)/log(10)));
sprintf(out, "%zu", (size_t)ptr);
return out;
}

There is a %p option, but I'm not sure how much space it uses. I've never touched it.
>>
>>54793262
>Simple
>char* meme(void* ptr)
that's a void pointer, not a function pointer
>8*sizeof(char*)*log(2)/log(10)
dafuq
>(size_t)ptr
that doesn't look portable
>>
Can someone explain Markov chains to me and why they're useful outside of dumb parody text generators?
>>
>>54793092
Null terminated. Not arbitrary bytes, just text. Also, casting to uint64_t can fail for multiple reasons; but sprintf has to be involved somehow, I figure.
>enormous source of bugs
Yeah, that's why I'd like to do it an a standards approved way.
>>
>>54793262
%p is in hex so length is 2+bits/4

>>54793299
>that's a void pointer, not a function pointer
Do you not know how to cast son? There are an infinite (well not really) number of function type signatures, this handles all of them.
>8*sizeof(char*)*log(2)/log(10)
Max length in decimal of an integer representing the pointer.
>that doesn't look portable
size_t is an unsigned integer the same size as a pointer. So, it is.
Fortunately, %p is a better option.
char* meme(void* ptr)
{
char* out = malloc(3+sizeof(char*)*2);
sprintf(out, "%p", ptr);
return out;
}
>>
>>54793344
See
>>54793355
Use %p
>>
>>54792947
Yeah, your principles are making being a VBA developer financially atractive by diminishing supply, so they're actually helping to spread VBA
you can't escape the market forces
>>
>>54789356
Hazelcast is pretty bitchin', too.
>>
>>54793340
Markov chains are useful in random process simulations.
>>
>>54793398

I was kidding, lad.
>>
>>54790151
It all depends on your data-persistence requirements. If you can tolerate incremental writes and the chance of data loss, then Redis is great. Otherwise, it's not the correct choice for your application.
>>
>>54793355
>Do you not know how to cast son?
the standard doesn't say, son
>Max length in decimal of an integer representing the pointer.
maybe on your preferred implementation
>size_t is an unsigned integer the same size as a pointer.
not really
>>
>>54793340
I think they are useful to calculate things that are modeled by Markov chains desu
Like, yesterday I was observing a game where you play paper-rock-scissors against an opponent until someone wins 3 times in a row. I wondered, assuming it's completely random, what's the expected value of games played until it ends? Then I noticed it could be modeled as a Markov chain and gave up on spot since I don't remember how they work
>>
>>54791404
why
>>
>>54793368
%p can't print function pointers
>>
>>54793522
>Then I noticed it could be modeled as a Markov chain and gave up on spot since I don't remember how they work

They're state machines, fambly.
>>
>>54793469
riffle?
>>
File: 1464017366239.jpg (140 KB, 500x667) Image search: [Google]
1464017366239.jpg
140 KB, 500x667
>>54793854
>>
Sas agapw :3
>>
>>54789133
HAHAHAHHAHAHHAHA WTF
>>
>>54788666
satan pls go
>>
>>54789843
doom3, doom2, doom1, 0ad, wesnoth, etc.
>>
>>54788666
#include <stdio.h>

int main(){

int c = 5, d;
d = ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c;

printf("%d\n", d);

return 0;

}
>>
>>54788718

>don't know fuzzy logic
I actually don't hear this term tossed around too much, but the concept I think is something any programmer can work with.

>don't know about linear programming
This was an elective for me in my undergrad years, and I found it rather boring. I'm sure it has plenty of uses outside of my areas of interest though.

>can't into convex optimization
Don't think my BS in Computer Science covered that. There's only so much you can cover in a Bachelor's Degree, and only so much that can be covered in classes on a quarterly system.

>can't prove program is correct
I can and I have done so in the past. That said, if a program grows in size, it's a bit more difficult to make a proof about the entire program... although writing proofs about parts of the program can be easier.

>can't prove complexity of program
Anyone who can't do this has no business programming.

>doesn't know lisp, haskell and prolog
Most people could get away with only knowing one of these. I know scheme and some Prolog. I don't particularly care for Haskell. The parts of it that are good already exist in other languages, with much more readable syntax.

>thinks java is a perfectly acceptable language
In a pinch, it's not terrible. It doesn't have the inconsistencies of PHP and Javascript, and performance-wise, there's much worse out there. That said, there aren't really any areas -- with the exception of Android development where it's pretty much mandatory -- where Java would be my first choice of languages.
>>
I'm reading TAPL, and having trouble with coinduction. Does anyone know resources which explain it better?
>>
>>54794197
implying java is mandatory on android
>>
>>54792879
>>54792905

>I'm a full time developer (delphi, php, java, vba) and have no desire to discuss work outside of work

You use some of the shittiest of languages that have been created for programming, and taken seriously. It is not a surprise that you do not enjoy programming enough to discuss it outside of work.

>>54794229

Other JVM languages can be used with the Android ABI, but then you are walking around mostly blind. Documentation for Android development with languages other than Java is rather poor. Native development is possible to an extent, but you still need to use the JNI to deal with anything regarding graphics.

From a practical standpoint, unless you need the performance increase from native development, Java is the only language worth using on Android.
>>
>>54788771
>break:
Funniest thing I've seen all day.
>>
I'm reading up on some solutions to the Josephus problem and I've come across this
while (people.size() > 1)  {
axe+= 3;
axe%= people.size();
people.remove(axe);
System.out.println(people);
}

what does that 'axe+/%' mean?
>>
>>54794345

I see no instances of the string 'axe+/%'. In fact, I don't see the division operator '/' anywhere. All I see is that you're incrementing axe by 3, and then setting it too the modulo of itself with people.size()
>>
>>54794095

You just gave me a headache
>>
File: BF0E.jpg (988 KB, 2964x1840) Image search: [Google]
BF0E.jpg
988 KB, 2964x1840
Reading through the Intel Developer's Manual
Why? idk
>>
>>54794345
axe += dick means axe = axe + dick
axe %= dick means axe = axe % dick
>>
File: 180px-Zeiger.png (14 KB, 180x239) Image search: [Google]
180px-Zeiger.png
14 KB, 180x239
Can someone explain to me why there's some people who find pointers to be difficult?

It's among the simplest ideas in the world and analogies exist everywhere. A telephone number to a specific phone. A lottery ticket to a specific price. A valet ticket to your car.

I can't really get my head around what makes them complicated for people. It seems everywhere you go there's effort dedicated towards teaching people pointers. As if a pointer would even need to be taught?

It's all very natural concepts. They should be covered in maybe a page of text at most.

You also hear people argue about "the application of pointers". But is there really anyone who thinks that makes any sense? We don't get static memory addressing anymore. It's all virtual. There's no real application of normal pointers that would be difficult.

Stuff like unique_ptr in C++ or the likes can be a bit complicated but they're all very simple ideas really. Reference counted pointers is probably the most complicated I can think of but it's not really that complicated either.

Are people retarded? Did you ever have trouble with pointers?
>>
>>54794948
I had trouble understanding why you'd want to use pointers since it seemed like they functioned almost exactly like regular variables until I dug deeper into C
>>
>>54794984
That's fair I suppose. If you don't know about pass by value or anything like that they'd make very little sense.
>>
>>54794948
I agree anon.
I found this guy:
https://www.youtube.com/watch?v=GiAhUYCUDVc
Philip Buuck. UI developer for unreal (not really a small fry programmer like what you'd find explaining the basics of a language through tutorials or whatever). Look at how he presents this.
I'm certain he doesn't get confused that much by pointers but he feels it's necessary to assert that pointers are hard for the audience. Why really?
They're simply not difficult.
>>
>>54794948
it's difficult for first year students who are still trying to grasp assignments, declarations, functions and other basic stuff.
then you start moving pointers around and have to deal with null pointers and other language specifics and altogether its overwhelming at the start.
pointers are a simple idea, but in practice not something you master in a day.
>>
>>54795168
Not to mention that mastering heap allocation, something that often goes hand in hand with pointer usage, is hard as fuck.
>>
>>54795472
>mastering heap allocation
>allocate all the memory your program needs
>write a few different allocators to use that memory
>be done
If you allocate new memory (regularly) after initialization you should really have to have some damn good reasons to do so. I doubt fresh programmers would actually have to concern themselves.

A pool allocator or a block allocator is enough for almost any application. And they're really simple.
>>
>>54794948
>Can someone explain to me why there's some people who find pointers to be difficult?

I think it's the C syntax that gets people.
>>
Using MySQL for my app atm--thinking of switching over to NoSQL.

All the blogs I read are SUPER pro NoSQL, but cs bloggers bandwagon harder than any instagram girl/seahawk fan.

Anyone have expericen with NoSQL vs MySQL?
>>
I heard C is better than Java.
>>
>>54795537

C syntax for pointers isn't that hard.
C syntax for function pointers is trickier.
>>
>>54795623
Yes.
>>
>>54795588
What do you want to know specifically?
>>
>>54795537
Actually, C syntax is probably the best for learning pointers because it's so explicit.
>>
>>54795623
I don't know what Java would be better than.. I'm sure there's something but it doesn't hold up to most of its promises.
>>
>>54788771
HAS to be bait
>>
>>54789133
computerchoice() is fucked anyway, but you should be using comp_number as the switch case
>>
>>54795667
How fast it is.

On app open I commonly insert a row and query content from a different table. Takes 300ms - 700ms depending on load. Longer than I would like.
>>
>>54795624
>C syntax for pointers isn't that hard.

No, but using the same symbol for declaration and referencing doesn't help. I get that it was part of Ricthie's master plan (make the decl & usage look the same, pointy thing on pointer) but people went and fucked that up by putting the pointy thing next to the type, rather than the declarator.

>C syntax for function pointers is trickier.

Surprisingly, a lot of C courses gloss of function pointers. Shameful, really.
>>
>>54795987
Depends on your data, it's structure, etc. but generally well below 100 ms even for big join queries. Don't fall for the MongoDB meme though. If you want NoSQL, look into RethinkDB, Riak and CouchDB and pick the best fit for the job.
Thread replies: 255
Thread images: 15

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

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.