[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/ - Daily Programming Thread

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: 320
Thread images: 23

File: daily programming thread2.webm (2MB, 600x338px) Image search: [Google]
daily programming thread2.webm
2MB, 600x338px
old thread: >>57270878

What are you working on, /g/?
>>
>>57276439
my gf(not girl) to the right
>>
File: strong typing haskell.png (33KB, 552x328px) Image search: [Google]
strong typing haskell.png
33KB, 552x328px
>>57276445
>>
>>57276455
>two genders
>>
Trying to play with a bunch of themes, only to realize anything differing too much from the default, Monokai, is autismo.
>>
File: 1457881560697.png (26KB, 722x453px) Image search: [Google]
1457881560697.png
26KB, 722x453px
Hey /g/ I'm attempting to make a bootloader, but I'm unable to get it to boot and I can't for the life of me figure out why.
Can anyone else figure out what I'm doing wrong?

mbr.py:
print("Bootloader is up!")

end = [0x55, 0xaa]


makefile:
all:
qemu-system-i386 -hda mbr.py


Pic related is what I get.
>>
>>57276455
Haskell confirmed for being hetero-normative.
Haskell is toxic and should be removed.
>>
>>57276485
haskell would permit you to be less normative but the programmer is retarded.
>>
>>57276425
>>57276432
What are downsides of placing everything in headers?
>>
>>57276487
Fuck off and shave your armpits

Two is more than enough
>>
File: windowspc.png (19KB, 581x313px) Image search: [Google]
windowspc.png
19KB, 581x313px
Is this a good way to get into Lisp as my first programming language?

http://learnlispthehardway.org/try-lisp/

But the 3rd example is broken and doesn't load.
>>
>>57276487
No, I it clearly the languages fault making the programmer to write something toxic like that.
Haskell leads discrimination. Haskell is problematic.
>>
>>57276495
case g of
Man -> 10
Woman ->7
>>
>>57276455
>Male
>Other

Can't go wrong.
>>
good laptop for a cs student?

budget of 1500 (post tax)
>>
>>57276522
macbook pro
>>
File: Thinkpad-chan.jpg (210KB, 1128x752px) Image search: [Google]
Thinkpad-chan.jpg
210KB, 1128x752px
>>57276522
My current dev machine costs $60 + 40 for a ssd.
>>
>>57276488
In a way it's a form of static linking and has all the same problems as a result.
The real reason why people do this is because C++ templates break separate compilation.
You pretty much have to put template code into header files.
And if 90% of your library is template magic then 90% of the code has to be in header files anyway and there is no point in having .cpp and .o files for the rest.
>>
>>57276533

Was gonna get one today

Saw price and specs that don't go together

>not gonna pay 1800 bucks for a shiny toaster
>>
>>57276439
Learning C and JavaScript so I don't look like an dumbass on my school's robotics tram
>>
>>57276484
bootloader has to be 512 bytes
>>
>>57276473
type Gender = String
>>
>>57276550
Get the 2015 model. It'll last and won't make you look autismo.
>>
>>57276592

I've never had a mac before and I feel nervous buying used online. The only place I'd buy from is the certified refurbished apple store. I was looking at a nice deal and it disappeared so now I'm looking yet again. Do you know where I can get good deals on a 2015 mbp?

Demand's gonna get high so I'm guessing price will get up too.
>>
> fixed length strings don't exist
Bravo C++
>>
>>57276623
std::array
>>
Good books for design patterns and when to use them?
>>
enum Boy {David, Eric, John};
enum Girl {Aimee, Lucy, Sophia};

enum Girl her = David;

Compiles fine.
C confirmed not CIS scum
>>
>>57276618
just buy a thinkpad and save the other $1400 on your future student loan payments.
>>
>>57276623
You still have to deal with char pointers all over the place.
There is no escape from the null byte.
>>
>>57276648
GoF
>>
File: 1467701877782.gif (529KB, 480x360px) Image search: [Google]
1467701877782.gif
529KB, 480x360px
I'm trying to write a class with an overloaded "<<" operator in C++, and it doesn't seem to be working. Basically, there's a 2-D array within the class where I want to print out each element when I use"<<".

When I actually use cout, it doesn't print anything... Any ideas as to why this doesn't work?

ostream& operator<<(ostream& out, Boggle& boggle)
{
for(int row = 0; row < SMALL_BOARD_SIZE; row++)
{
for(int col = 0; col < SMALL_BOARD_SIZE; col++)
{
out << boggle.getElementFromBoard(row, col) << " | ";
}
out << endl;
}
return out;
}
>>
>>57276650
Use C++ enum class instead.
>>
>>57276648
>when to use them
How about never?
>>
10 pages into a lab report for my experimental physics class... kill me /g/
>>
>>57276537
But does plain C have templates?
>>
>>57276667
By the way, I'm using
 cout << this 

In the constructor within the constructor, if that helps.
>>
File: ritchie meme.png (573KB, 587x551px) Image search: [Google]
ritchie meme.png
573KB, 587x551px
>>57276683
no :^)
>>
File: 1371889453762.png (34KB, 187x280px) Image search: [Google]
1371889453762.png
34KB, 187x280px
>>57276455
>pic related

...I need this
>>
>>57276698
plain C has preprocessor macros
and if you cannot make your abstraction work with static text replacement macros, then you shouldn't be using templates anyway
>>
>>57276698
No. There is no point to put all your shit in header files in C.
>>
File: sepples.png (72KB, 1016x98px) Image search: [Google]
sepples.png
72KB, 1016x98px
>>57276683
>sepples
>>
>>57276648
I Never Gave My Consent by Holly Archer
>>
>>57276715
Looks fine to me.
>>
>>57276665
Is this the one involving the text editor thing because I already read that.
>>
I've been wondering, what's the correct way to sync two or more threads in a realtime program?

For example, I understand Unreal Engine 4 syncs the main and render thread every frame. How would you do that normally if you were to do it that often?
>>
>>57276730
mutex locks

specifically, you want all threads to halt until they catch up.
>>
>>57276730
Non-default C++11 atomic for SPEEEED
>>
>>57276736
>specifically, you want all threads to halt until they catch up.
Yeah, that's what I want. I'm just not sure how to structure the mutexes - every thread locks a mutex of it's own at the start of a thread, then when done, attempts to lock some shared mutex the main thread controls (and then, immediately release it when they're allowed to lock it.) I'm not quite sure.

>>57276746
I'm not sure how you would use atomics in syncing two loops (as in a real time application, like a game). I can only think of using them to lock some individual piece of data multiple threads may access.
>>
>>57276484

CPU doesn't understand Python. You're going to need to implement a Python interpreter first.
>>
File: IMG_2509.jpg (1MB, 2968x1668px) Image search: [Google]
IMG_2509.jpg
1MB, 2968x1668px
>>57276493
Anyone?
>>
>>57276455
how is Haskell so perfect?
>>
>>57276493
>>57276866
SICP, its a meme for a reason
>>
>>57276886
Fantasy RPGs and roguelikeS!
>>
>>57276886
But it seems so old. Aren't there new versions of Lisp so some of it doesn't apply today without having to google some work around?
>>
Give me 1 good reason why I shouldn't just solve everything recursively.
>>
>>57277035
Performance
>>
>>57277048
>Performance
We live in a world with gigybit processors and millions of bites of ROM
>>
>>57277048
Recursion isn't slow
>>
>>57276730
Depends on what you actually need syncing.
You don't really sync threads, you sync whatever data it is that you need to share, and then it depends on what kind of data, how much if it, etc. Common ways are message passing (lock-free queues), condition variables, events or good old spinlocks.
>>
File: 1477523805762.jpg (54KB, 800x686px) Image search: [Google]
1477523805762.jpg
54KB, 800x686px
Automatic Updates for Chromium on Android. No one else has done this properly so far.

https://github.com/adolfintel/chromiumUpdater
>>
Goof morning, /dpt/.
>>
>>57277058
Imagine how much more we could accomplish with our machines if it wasn't for unoptimized software.
>>
File: 1goofy.png (192KB, 671x504px) Image search: [Google]
1goofy.png
192KB, 671x504px
still need to rewrite the data framework after it turned out to be non-practical.

>>57277134
Goof morning to you too.
>>
>>57277149
Ya I could probably watch two animes at once then
>>
for( i=0; i<Math.PI * 2; i+=1);


will [Math.PI * 2] be evaluated each loop or will the compiler put it into its own var after evaluating it once and then comparing usinhg that variable?

sorry if dumb question
>>
>>57277232
Any compiler written after the 80s will constant fold things like that away.
>>
>>57277058

Please do not operate under the assumption that your program is going to be the only program running on that machine, or even that it will be one of only a select few.

That said, tail recursion is just as fast as a for loop when decent compilers are employed, but it makes shit harder to read for anything non-trivial.
>>
>>57277301
You don't ahve to read the code the computer does that for you
>>
Posting here because noone answered in sqt:

I have binutils 2.25 on debian and binutils 2.25.1 on windows built with msys2

I also have a MSVC obj file, glow.obj which i want to link with ld into an exe.

ld -m i386pe glow.obj -o glow.exe

Gives correct output, saying unresolved symbols

ld-new.exe -m i386pe glow.obj -o glow.exe

Says "File is truncated.", doesnt do shit.
>>
I'm trying to work out (3u + 3v)^2 - 3(u - v)^2

So firstly, squaring the first polynomial gives 9u^2 + 18uv + 9v^2

then squaring the second polynomial gives u^2 + uv^2 + v^2

then multiplying that by -3 gives -3u^2 -3uv^2 -3v^2

collecting all the terms gives me an obviously wrong answer. What am I fucking up
>>
>>57276439
I took three courses last semester. I just got the final grade for the last one. I got an A in one, and two F's in the others. I can't believe this. I finished my last math course in the beginning of Spring. I thought I would just be able to coast to graduation from here, but I'm getting stomped. Now I have to finish 16 courses before next September to graduate on time. The courses I failed were operating systems and networking.
>>
>there is now a library to call JVM from Haskell
http://blog.tweag.io/posts/2016-10-17-inline-java.html

Scala in danger of coming back to life just to kill itself again
>>
>>57276439
>decide to try and make a game for a web browser
>compile java applet code and insert it into web page on my server
>can't load java in web browser because 64bit firefox doesn't support java
>switch over to IE rather than download 32 bit firefox
>ie can't find java
>reinstall java
>java says my application is a security risk and prevents it from running
>I have to go to the java control panel desktop application and list my site as an exception
>reload web page
>java still complains that what I am doing is dangerous with a warning popup

its like Oracle doesn't want you to make java applets.

I will certainly NOT be using java if this is what a user would have to go through to play a browser game. HTML5 is looking good but the lack of support for compressed files and good audio is a turn off.

is there any platform I can use to make browser games that will just werk and sound good? I really don't like javascript but it looks like thats what I need to write in.
>>
>>57277347
Why the fuck did you think a java applet is a good idea in the first place
>>
>>57277347
>its like Oracle doesn't want you to make java applets.
yeah
its not 2005
>>
>>57277326
Mind the sign when squaring the second polynomial.
>>
>>57277317
ld does not understand msvc .obj (MS COFF) files.
>>
>>57277375
It did on debian, it gave the correct unresolved symbols error, and also the documentation says that it uses libbfd which supports COFF
>>
>>57277326
(3u + 3v)^2 - 3(u-v)^2
3u^2+3v^2 - 3u^2+3v^2
= 0
>>
>>57277355
i don't like javascript but wanted to make a web game.
>>
>>57277399
You can try llvm and emscripten, but parts of js is unavoidable
>>
>>57277326
>then squaring the second polynomial gives u^2 + uv^2 + v^2
No
(u - v)^2
u2 - 2uv + v2
>>
>>57277415
perfect! thank you
>>
>>57277315

You might enjoy programming in Perl.
>>
>>57277390
ms coff is slightly different from coff (in particular when it comes to relocations)
>>
>>57277423

Ohhh I see. I'm supposed to square the polynomial there and then multiply the entire thing by -3.

I also see I made another mistake: I was multiplying uv and uv to get uv^2, when in fact I should have been adding them to get 2uv.

so 9u^2 + 18uv + 9v^2 combined with -3u^2, -3v^2, and 6uv gives the right answer of 6u^2 + 24uv + 6v^2

thanks anon-kun!
>>
>>57277499

>How can c(uck) "programmers" call themself programmers with a straight face?
Simple: Your OS, most of the networking and crypto stack, about half of all language interpreters (the other half are C++), and pretty much anything performance-oriented that you depend on every day, is written in C.
>>
>>57277468
use re 'eval';
''=~('('.'?'.'{'.('['^'+').('['^')').('`'|')').(
'`'|'.').('['^'/').'"'.('`'^'&').('['^'.').('`'|
'#').('`'|'+').('{'^'[').('`'|'/').('`'|('&')).(
"\`"| (( '&'))
).''. +( "\{"^
'['). +( "\["^
'+'). +( "\`"|
','). +( "\`"|
'%'). +( "\`"|
'"'). +( "\!"^
'+'). (( '"'))
.'}'. (( ')'))
);$:= (( '.'))
^'~'; $~ ='@'|
'(';$^=')'^'[';$/='`'|'.';$,='('^'}';$\='`'|'!';
($:)= (( ')'))
^'}'; $~ ='*'|
"\`"; $^ ='+'^
"\_"; $/ ='&'|
"\@"; $, ='['&
"\~"; $\ =','^
"\|"; $: ='.'^
"\~"; $~ ='@'|
"\("; $^ =')'^
"\["; $/ ='`'|
"\."; $, ='('^
'}';$\='`'|'!';$:=')'^'}';$~='*'|'`';$^='+'^'_';
$/='&'|'@';$,='['&'~';$\=','^'|';$:='.'^"\~";$~=
'@'|'(';$^=')'^'[';$/='`'|'.';$,='('^'}';$\='`';
>>
File: 1477477926855.jpg (73KB, 428x600px) Image search: [Google]
1477477926855.jpg
73KB, 428x600px
>>57277540
nice flag desu
>>
>>57277399
Try TypeScript
>>
>>57277540

#!/usr/bin/env perl
length q bless glob and print chr oct ord q mkdir m and print chr ord q xor x and print chr ord q q q and print chr ord uc q map m and print chr ord q qw q and print chr ord q each le and print chr ord q my alarm and print chr oct oct ord uc qw q for q
>>
>>57277035
because then you'll just have to use haskell!

I learned that today.
>>
>>57277537
And we learned why it does not work.
Programming in c is like doing alchemy now for science.

Prove me wrong. You can't: both alchemy and c are ancient and harmful. Can should have no place in a modern world
>>
>>57276650
C really only cares that their human, but not too much.
It'll gladly overwrite them with garbage.
>>
>>57277540
gross
>>
>>57277601
haitian alchemy brought us aids. I wouldn't dare compare C to that. C just makes YOUR penis look smaller in comparison.
>>
>>57277601

Right, but the only valid alternatives to C are C++ and Rust. So pick your poison.
>>
>>57277620
*you're
>>
>>57277624


C++ is objectively proven with academic study to be faster than C using a multitude of compilers and algorithms.
>>
>>57277627
>it makes you are penis look smaller
>>
File: 1468450944463.png (237KB, 500x363px) Image search: [Google]
1468450944463.png
237KB, 500x363px
>>57277636
>>
>>57277633
>>57277627
>>57277605
Shitty bait
>>
>>57277633

Fair enough. At least you picked the good poison.
>>
>>57277624
Ada is faster than Rust and quite literally as fast as C++, if you use the latest compiler.
>>
>talking to the trip
>ever
>>
>>57277656
Ada is cute. CUTE
>>
I think I might have add/adhd. If I go to the doctors, will meds help me?
>>
>>57277633
AHAHAHAHAHHAA
>>
>>57277661
ADD isn't real and meds are bad for you
>>
>>57277661
I think I'm a C(uck). Should I see the doctors?
>>
>>57277668

being a retard doesn't change science bro
>>
>>57277668
>le Hillary laugh of denial
>>
>>57277656
Ada is also physically painful to program in.
>>
>>57277703
Nicer than rust
>>
>>57277703
Because you're used to the disgusting mess known as C
>>
>""""programmers"""" without a phd in maths
>>
File: 1474325315193.jpg (44KB, 636x616px) Image search: [Google]
1474325315193.jpg
44KB, 636x616px
>>57277719
>some """people""" actually consider themselves intelligent without a phd in maths
>>
File: 1475520686707.jpg (120KB, 392x495px) Image search: [Google]
1475520686707.jpg
120KB, 392x495px
>>57277719
>>57277725
pls stop bully
>>
>>57277719
Programmers should have a PhD in EE.
>>
>>57277725
Education doesn't make you smart, only knowledgeable.
>>
>>57277469
I know but if it works on debian it should work on the windows build too
>>
>>57277703
t. I don't like change and would rather do a website in C
>>
>>57277912

Whoever said anything about websites?
>>
>>57277912
There's absolutely nothing wrong with that statement.
>>
>>57277926
your mom last night
>>
>>57277926
t. I don't understand the message
>>57277932
t. akkarin anime poster
>>
>>57277806
Typical attitude of some dropout or someone who didn't even manage to get into a decent college.

This behaviour is known from the very ancient times as "sour grapes".
But if lying to yourself is what makes you sleep better, then it's OK.

Discreet Math is extremely important in programming
>>
File: akari883.jpg (19KB, 300x360px) Image search: [Google]
akari883.jpg
19KB, 300x360px
>>57277943
you caught me lol
>>
>>57277953
don't worry, I don't hate you senpai, I actually admire that you have skill.
tee bee age
>>
>>57277943
We were talking about C programming and then you immediately switched to using C for website programming. Almost no one uses C for websites. At least not directly.
>>
>>57277952
Obviously my opinion might be biased but social interactions with primates is way too hard for me to continue college.
Anyway I definitely think math is important for programming but it doesn't mean you can't learn by yourself with the right books and papers.

Also, learning is the less efficient way to understand math.
>>
>>57276522
Dell Precision, any model.
>>
>>57277953
you are the only good tripcode
>>
I am new to bash, how can I do a for statement that loop from a range of values minus a imput argument.
For example, the input argument is 3, and the original for list is: i in {1..6}. I want to loop for 1 2 4 5 6.
>>
>>57277983
>t. I don't like change
>example is how someone would rather program websites in C (because they don't like change)
>>
>>57278019
b--but.. using C for everything is actually leggit if you care about performance.
>>
>>57278019
not liking change would imply that using C in websites is common practice, and they don't want to learn something new. C was never used for websites in any major way, so the example doesn't make sense.
>>
>>57277983
They like to think you're learning html.
>>
>>57277735
Where the fuck do these even come from?
>>
>>57278059
jp
>>
>>57278040
nope
regardless of general utility of a language in an area, some would be stubborn and rather use it (because they don't wanna change) anyways
and it's legit criticism since you bashed Ada because it wasn't like C
>>
>>57278078

I'm not bashing Ada for not being like C.
I'm bashing it for being a pain in the ass to use.
>>
>>57278010
for i in {1..6}
do
if [i -eq "$a"]; then; continue; fi
#Here goes other code
done
>>
>>57278123
Thanks, trying out now, it needed a space between [ and i, but working now.
>>
Is iq 130 enough to make something significant in programming
>>
>>57278227
no
>>
File: brain.png (6KB, 195x259px) Image search: [Google]
brain.png
6KB, 195x259px
>>57278227
IQ 150 here. It's a curse. I'm to intelligent to find a job despite over 100 confirmed Fizz-Buzz in Haskell.
>>
>>57278254
>tfw too intelligent to contribute to the thread
>>
What effect does adding more neurons have compared to adding more hidden layers to a neural network?

Also, how do people decide how many neurons and hidden layers their net will have?
>>
>>57278267
>Also, how do people decide how many neurons and hidden layers their net will have?
Trial and error.
>>
>>57277111
Yeah, I'm aware of some of those methods. Some game engines do indeed sync all of their threads at the end of each frame, and I was thinking of trying that architecture out.
For example, in my current game the render thread is far faster than the main thread, so there's no real need for it to be drawing the same frame of simulation multiple times. So I though, I could sync the threads at the end of a frame, then do stuff like cleaning up dead entities. Though thinking about it, I guess a simple mutex per thread would do there. Something like a spinlock just seems wasterful.
>>
>>57278278
Ok. What about the first question?
>>
>>57276455
I don't understand why you have to declare the type of every variable in Haskell. Why cannot it not just be inferred?
>>
>>57278341
It's good style to put type annotation on all top level functions/variables.
Also, without the type signature, it would typecheck and thus ruin the joke.
>>
>>57278341
In this example, you can see exactly why
By declaring the type of the variable, the compiler has caught an error - David is not a Girl
>>
>>57278349
>It's good style to put type annotation on all top level functions/variables.
I don't understand why. It's just needless verbosity 99% of the time.
>>
>>57278341
you don't have to
>>
>>57278418
yeah, but most Haskell code seems to do it, and it's considered best practice
>>
>needless verbosity
>i dont like knowing what type my shit is

You know it takes like 3 extra seconds in most languages, right?
>>
>>57278428
sometimes you know what type it's supposed to be, and then it helps you catch errors
>>
>>57278431
>i dont like knowing what type my shit is
Why would I not know what the type is?
>>
>>57278446
>tl;dr you're a faggot

Write a large project and leave it for a year or so, then return and try to decipher the ungodly shit you write.

Or find a large program wothout type annotations, and you'll fuckin really want type annotations
>>
>>57278391
If you don't put type decls on top level definitions, then users of those functions have to look at the implementation to know how to call it.
It's especially tricky in the presence of currying, as you can't even tell how many arguments you are supposed to pass at a glance.
If you put a type decl there, it's immediately obvious.
You don't have to put type decls on local things, because your caller doesn't give a shout about your local stuff.

The other reason are GHC extensions.
Some of the more powerful ones (GADTs, TypeFamilies etc.) break type inference,
meaning that given an expression there are multiple legal types where non of them is more general than the other.
In these cases top level definitions are needed and in practice the compiler can work out the rest (all your local stuff) from that.

Note that this isn't the case for Haskell98, here you can always assign a single most general type to any given expression.
>>
>>57278476
>you can't even tell how many arguments you are supposed to pass at a glance
0 or 1
>>
>>57278471
>Write a large project and leave it for a year or so, then return and try to decipher the ungodly shit you write.
I write good code, never had a problem with this since I was a new fag. hat doesn't even answer the question though. No matter how shitty the code I'll always know the type due to type inference.

>Or find a large program wothout type annotations, and you'll fuckin really want type annotations
I didn't say never use type annotations. But the vast majority of the time they are not needed. You need them for defining records and shit like that, but variable types? Hardly ever.
>>
>>57278489
>0 or 1

Windows api has functions that take 8+ args ya dumbdumb
>>
>>57278489
This may be true, but it certainly isn't helpful.
>>
>>57278505
haskell
>>
>>57278505
The joke went over your head.
It's about currying.
>>
>>57278500
>I write good code
>Thinks type annotations are needless verbosity
Do tell, what have you written that you'd claim to be "good code"? Also im guessing you're a python fag
>>
>>57278500
>but variable types? Hardly ever.
Sure, and no Haskell programmer does that (expect when they are doing type voodoo, then they have to).
We are talking about TOP LEVEL definitions.
>>
>>57278520
>Thinks type annotations are needless verbosity
Most of the time they are. You need them the odd time of course.

>Also im guessing you're a python fag
F# mostly. Though not as much as I'd like, can't code it in my day job.

>>57278533
>but variable types? Hardly ever.
Most haskell code I've seen does it all the time, and I was told by someone it's considered best practice to always define variable types. maybe I'm wrong though.
>>
>>57278558
>Most haskell code I've seen does it all the time, and I was told by someone it's considered best practice to always define variable types. maybe I'm wrong though.
First of all, Haskell doesn't really have "variables". They are all constants. You can have changing things with IORef, but that's beside the point.

>Most haskell code I've seen does it all the time
Post it. Most Haskell code I've seen and written only declares types for top level stuff, never for local constants or functions.
>>
>>57278584
>First of all, Haskell doesn't really have "variables". They are all constants
Constants are still variables, even though they are immutable.

>never for local constants or functions.
Maybe you're right. Some haskel fag told me the opposite was true. Happy to be corrected on this.
>>
>>57278597
>Constants are still variables, even though they are immutable.
Well, they not variable then. The name is misleading.
>>
>>57278613
you call them variables in mathematics
>>
>>57278613
They are variable. The very every time the section of code they exist in is run. They simply don;t change in value after they are initialed.
>>
What's the most popular language for developing neural networks?
>>
>>57278634
MY ANUS
>>
Making a python interpreter in C++.
I'm trying to write something that would interchangibly call an interpreted function or a built-in function, and I'm failing miserably.
My current approach is using function pointers and lambda function, and it is as frustating as it is ugly.

class Object : public Namespace {
...
public:
virtual Object& call(const Object& obj);
};


class BuiltInFunction : public Object {
...
public:
Object& call(const Object& obj);
private:
Object& (*function)(const Object&);
};

Object& BuiltInFunction::call(const Object& obj){
return function(obj);
}

class IntObject : public Object {
public:
int value;
IntObject(int value);
};

IntObject::IntObject (int value) :
Object("int"), value(value) {
//inject built-in functions on namespace
newName("__add__", *(new BuiltInFunction(
[](const Object& right)-> Object& {
IntObject* int_right = dynamic_cast<IntObject*>(const_cast<Object*>(&right));
if(int_right){
return *(new IntObject(666 + int_right->value));
}else{
return *(new Object());
}
})
));
}


First shit is, I cannot for the love of dog use the current IntObject value inside the lambda (it should be where 666 is).
Second shit is, a bunch of castings...


Please tips/ideas.
Syntax to use instead of lambda?
Use pointers instead of references?
>>
File: 1399339118262.jpg (19KB, 500x367px) Image search: [Google]
1399339118262.jpg
19KB, 500x367px
>>57278649
I guess that makes you a smart ass
>>
>>57278626
Top level "variables" aren't variable in Haskell, ever.
They have the same value in every context,
unless you shadow them (but then you refer to something different) or you do dirty tricks with unsafePerformIO.

>>57278622
>you call them variables in mathematics
You only call them that, if there value changes depending on context.
f (x) = 2 x
Yeah, x is a variable.
But pi isn't. It's a constant.

>>57278584
I didn't say I was talking about top level bindings, which I should have.
>>
>>57278687
>Top level "variables" aren't variable in Haskell, ever.
>They have the same value in every context,
oh
>>
>>57278687
>Top level "variables" aren't variable in Haskell, ever.
so their values are baked in at compile time then?
>>
Hey dpt I'm new to programming and I'm learning python what's a good project for me to try and complete.
>>
>>57278740
Usually yes but not necessarily, that's for the compiler to decide.
It could have some start up code that runs and initializes them before calling main.
It could even compile them to a thunk/initialize them lazily.

The key thing is that your code can never observe it's value changing.
If it does, that's a compiler bug.

I haven't read the standard though, so I could be wrong.
>>
>>57278805
>Usually yes but not necessarily, that's for the compiler to decide.
When would it not be a good idea to do at compile time?
>>
When including files, is there a preferred way of the following two alternatives?

Alternative 1:
#include <GL/gl.h>


Alternative 2:
#include <gl.h>


The latter would require that you set additional include directories in your IDE/makefile/whatever, but the first (I think) don't work on operating systems which don't store all of the include files in a single directory (I'm looking at you, Windows).
>>
>>57278932
>but the first (I think) don't work on operating systems which don't store all of the include files in a single directory (I'm looking at you, Windows).
If the GL directory is in the default include search directory then it will work (which it is).
Has always worked for me with both msvc and mingw.
>>
>>57278860
>When would it not be a good idea to do at compile time?
I think it's a good idea to do it whenever the compiler can, given that the value is not to big and binary size doesn't explode because of that.
Though inlining it may be even better.

But I don't think it's a simple thing to do.
All Haskell values are boxed by default.
And code that uses those constants expects the boxed representation.
In order to put in the executable as a static thing it has to do some work.
All users of this constant have to be rewritten to work with the unboxed version of the constant.
And with more complex data types it can only get worse.

I guess the compiler says "fuck it", compiles it as thunk/boxed value and hopes that
the optimizer inlines the constant everywhere it's needed and constant folds it away where it can.
If it's not used anywhere after that, then dead code elimination may remove the thunk.
>>
>>57278932
It works if you have a directory called GL. I usually always use the former style, and I don't even add libraries to the default directory on Windows, I specify the path via linker flags.
>>
>>57278059
Pixiv. There's a pool on danbooru, just use iqdb.
>>
>>57278245
>>57278254
Is it enough to make something?
>>
>>57279202
No, you need an IQ of 150+ like most /dpt/ posters.
>>
what do you cucks do in the morning?
I cant program for shit in the morning.
>>
Completely new? Fizz buzz. Variables, loops, conditions, output, and simple. If you can fizz buzz you've got the absolute basics. Then learn some abstraction techniques like functions and classes and build a basic CRUD program that can save to a file. Then pick something you want to do and is within your grasp but at least in some part outside of your knowledge. By this time you'll have an idea of how to figure out if a project meets that requirement.
>>
>>57279269
I'm pretty sure everyone /dpt/ is a PHD in some STEM field.
>>
>>57279290
Meant to reply to:
>>57278746
>>
>>57279324
>tfw 4 phds, 200 IQ
>tfw still two intelligent tu program
>>
>>57279352
programming is for the stupid though, a person with 200 IQ wouldn't be mentally stimulated doing that type of work.
>>
>>57279377
>person with high iq wouldnt be stimulated solving problems for their job
>>
File: 1475240340911.jpg (174KB, 1000x929px) Image search: [Google]
1475240340911.jpg
174KB, 1000x929px
>>57279352
>>57279324
>>
>>57279011
>All Haskell values are boxed by default.
Terrible.
>>
>>57279407
Like I said, "Programmers" dont solve problems
they just implement the solution.
>>
>>57279427
>just implement the solution
That's a "code monkey"
>>
>>57279420
fellow intelligent soul, are you to two smart to study math? i am tu smart too either
>>
>>57279444
which is essentially a programmer.
I wouldn't call myself a programmer if i was the one designing and architecturing the solution.
>>
>>57279449
not anon above, but i too browse /dpt/ and have a 200+ IQ.
IMO the way math works now is wrong. We need to start over from scratch.
>>
>>57279473
Great minds think alike. We shall start math over from scratch. I'll design the logo.
>>
>>57277719
>>57277725
>having a PhD in getting fucked in their boipuccy
>>
>>57279481
I'll write the CoC.
>>
File: 1476105146631.jpg (1MB, 1154x1500px) Image search: [Google]
1476105146631.jpg
1MB, 1154x1500px
>>57279324
>tfw to inteligent for phd
>>
var elements = document.getElementsByClassName('postContainer');
var com = document.getElementsByName('com');
var str = com[0].value;


for(var i=0; i < elements.length; i++) {
if(elements[i].getAttribute('id')[elements[i].getAttribute('id').length-1] == elements[i].getAttribute('id')[elements[i].getAttribute('id').length-2])
str += '>>' + elements[i].getAttribute('id').substring(2) + '\n';

}
str += 'checked :^)';
console.log(str);
com[0].value = str;


>>57276455
>>57276488
>>57276511
>>57276522
>>57276533
>>57276588
>>57276844
>>57276866
>>57277111
>>57277166
>>57277355
>>57277399
>>57277633
>>57277877
>>57278000
>>57278077
>>57278500
>>57278533
>>57278622
>>57279011
>>57279344
>>57279377
>>57279444
checked :^)
>>
>>57279473
Actually designing math system from scratch is fun if a world building is your hobby.

One problem is after a session of it you realize the full extent of your own autism.
>>
>>57279517
are you one of those savants that browse 4chan ive heard so much about? whats it like anon?
>>
>>57279525
> javascript
> not even ES6
kys
>>
>>57279547
Cleaning up my external HDD atm and found this somewhere on there :-)
>>
>>57279274
In contrast to you, I find I'm at my most productive in the morning programming-wise. Tend to slow down as the evening approaches, and then there's this new burst of creativity just before sleepy-time (in the summer, not now as it's dark as hell since winter's knocking on the door.)
>>
>>57279631
do you listen to any music while you work?

sometimes i binge watch anime in the background.
>>
>>57279654
Sometimes I do, especially in the evening, but not always. Its usually something that's repetitive and easy to listen to, say, house music, techno, maybe chiptunes or something of the sort.
>>
>>57279689
how do you deal with the urge to fap while you program? I can't seem to stay focused for more than an hour without having the urge to watch some hentai.
>>
>>57279707
I don't have that sort of an urge, I masturbate maybe once or twice a month.
>>
>>57279725
wow are you married?
i cant seem to find a girlfriend
>>
>>57279733
No, I'm single.
>>
>>57279739
fuck man, whats wrong with me...
>>
>>57276455

Doesn't Haskell have unions?

If you try to match a girl with a boy they have to being joined in a union first
>>
>>57279745
I don't know how old you are but at least I can say that from my teens to about 20, concentration was much harder and jacking off a much larger part of my life than after that period.
>>
>>57279757
>unions
Socialist scum pls leave
>>
>just woke up
>/dpt/
>read latest posts
>serious masturbation discussion
stay classy, /g/
>>
File: 1476087736474.jpg (47KB, 327x322px) Image search: [Google]
1476087736474.jpg
47KB, 327x322px
>languages that rely on magic built-in libraries to do things that can't be done otherwise in that language
>>
>>57279425
Well boxed in this context means something slightly different from the boxing in Java.
It has to do with Haskells laziness and how it's implemented.
If Haskell were strict by default (which it is with the StrictHaskell extension in GHC) there wouldn't be as much boxing, as there is less laziness.
>>
>>57279865
Yeah SQL is a garbage language.
>>
>>57279757
>Doesn't Haskell have unions?
Yes, it's called a Sum type.
Either is an "anonymous" Sum type of two types, just as a tuple is an "anonymous" struct/Product type of two types.
>>
Haskell:
>what if everything was contstructors
>>
>>57279865
Every language requires that.
At the very least you need a magic 'define' operator to create new definitions, and that one obviously can't be written in the language itself.
>>
>>57279865
You mean every language? Good luck writing to the console in C without using stdio
>>
>>57279925
You forgot lambdas. They're pretty important too.
ADTs + lambdas, the rest is trivial syntactic sugar.
>>
>>57279937
>what is printk
>>
>>57279937
It's easy on linux
>>
>>57279937
Are you retarded? That's just an abstracted way of accessing the API of the underlying OS. You can bypass it if you wanted to. You can even write your own console and print features in C at the hardware level for embedded devices or whatever if you were so inclined.
>>
>>57279985
Every language which doesn't have every single OS and hardware primitive reified at the language level cannot fully bootstrap itself.
For example: You cannot implement the stuff in threads.h and stdatomic.h in C.
>>
>>57280069
You can with the GNU extension for inline assembly.
>>
>>57280102
>GNU extension
not C
>assembly
not C
>>
>>57276439
I'm trying to go from "no programmer" to "has an automated program that takes data from reaver, wash and airodump/crack/play-ng and automatically works with the data without any user input". How can I start?
>>
>>57280069
Not sure what you're even trying to say there kiddo but any functionality exposed by the OS can be taken advantage of in C. If the functionality you need isn't exposed by the OS, that's an OS limitation, not an OS one.

>>57280181
Anything that can be done in assembly can be done in C.
>>
>>57280181
What if I write a C program that creates an executable binary?
Checkmate atheists.
>>
>>57280200
>Anything that can be done in assembly can be done in C.
Nah. There is a reason for the asm subtree in the linux kernel.
>>
>>57280200
>but any functionality exposed by the OS can be taken advantage of in C.
No.
>>
is Microsoft OS the greatest program ever written?
>>
>>57280300
That depends on your criteria for "great".
>>
>>57280300
Yes it's the best OS
>>
>>57280313
in terms of complexity, success, lines of code.
>>
>>57280313
full of greatness
>>
>>57280458
It's complex, objectively successful, and has many lines of code.
>>
compared to anything out of the linux foundation,
Microsoft is better at everything. It only gets shit on because it literally tries to do everything.
>>
>>57280511
What does this have to do with programming?

Piss off, you're just going to start a flame war.
>>
{
public static int pairCounter( String str )
{
int count = 0;
String s = str;
for(int i=1; i<s.length()-1; i++)
{
if(str.charAt(i-1) == str.charAt(i))
{
count++;
}
}

return count;
}
}

can someone please explain to me what this is doing ? thanks in advance.
>>
>>57280511
>install windows
>slow, nothing works, cry because muh not activated, ide are bloated mess
>install linux
>everything work out of the box, extremely fast, beautiful UI (gnome) and wtf it's free too
Is there something I don't understand or there really are shills in this board?
>>
>>57280676
you fucking idiot.
> install windows
do you know how much magic is happening when you > install windows
and yes everything does work out of the box.
theres a reason why Windows owns most of the market.
>>
>>57280676
Yeah I have no idea what the fuck he's talking about. Linux distros do essentially everything Windows does, usually better, minus some developer lock-in, except Linux is free free and made without the astronomical sums of money involved that Microsoft has.

http://blog.zorinaq.com/i-contribute-to-the-windows-kernel-we-are-slower-than-other-oper/
>>
>>57280729
is free*
>>
>>57280676
>>57280729
>never used linux for anything other than hello world and ricing
>>
>>57280702
>there's a reason why Windows is popular
2/10
>>
>>57280754
but its a fact. like it or not.
>>
>>57280748
I use Debian for gaming and I have better fps than on Windows.. U.U
>>
>>57280729
>2016
>Still no proper desktop composition
at least none that's not chocked up by the lagfest of X

The Linux kernel is better than the Windows general. Everything desktop related on linux is pretty shit.
>>
>>57278674
You need tocapture this in the lambda expression to use it within a lambda.

So your lambda should be:
[this](const Object &right) -> Object & {
...
}
>>
>>57280653
>pairCounter
counting character pairs in a string ("hello" would return 1 because "ll")

>String s = str;
This line seems totally pointless though, why not just check str.length() - 1 ?
>>
>>57280782
>C++ lambda
Well meme'd sir.
>>
>>57280702
>and yes everything does work out of the box.
No, it doesn't.
Windows 10 didn't even have fucking ETHERNET drivers for my motherboard (Asus B150M Plus) so I had to boot a Linux live cd (which did have drivers) to download the drivers.
>>
>>57280782
in haskell this is just

\this right -> ...
>>
>>57276908
SICP + Scheme
or learn Clojure
>>
>>57280820
the question wasnt about haskell though
>>
>>57280801
nigga use the CD it came with
>>
>>57280748
Actually, I use it to do most of my development. I also play games under WINE (though I also have a real Windows partition, since WINE can't perform miracles).

>>57280781
> the lagfest of X
Can be true.

Regardless, if you pick a good desktop environment your experience is generally pretty good these days, though YMMV since this is inherently subjective.
>>
is there such a thing as a good Bash terminal emulator for windows 8?
I'm currently using Git Bash but it has some issues displaying information from node.
>>
>>57280836
Who has a cd drive these days?
>>
>>57280883
> bash

why arent you using zsh?
>>
>>57280827
it should've been
>>
>>57280883
Why not install a full on Unix subsystem? MSYS2 is pretty nice.
>>
>>57281087
cygwin is better
>>
>>57280820
no, Haskell doesn't require you to capture things in a previous scope. it implements closures properly...
>>
>>57276702
have you tried it without the this?
>>
>>57280883
>not having windows 10 with the Linux subsystem installed
>>
>>57279274
I jerk off
>>
>>57280202
You won't, since you don't have access to file system.
>>
>>57281162
its shit.
>>
>>57280792

I should re phrase the question, my mistake. I wanted a explanation on how it works not what it's doing.
>>
>>57281105
Lol that shit is outdated. MSYS2 comes with GCC 6.0, the mingw64 core that comes with it is maybe 2 weeks behind release.
>>
>>57281175
Agreed. I tried to pass files between the two, shit froze. Restarting the shell didn't help, restarting the OS didn't work. So I just went back to Windows 7. That was the last straw.
>>
Fact: local-eval makes Guile better than most other dialects.
>>
>>57281263
the upper bound on the for loop is 1 too low, it seems to me

anyway, i'm not sure how to answer your question. the code explains itself to some extent. you want to count the number of positions in the string where s[i] = s[i-1] and the code does exactly that
>>
>>57281334
Fact: tripfags are better than normal posters ;^)
>>
File: 1476811327277.jpg (38KB, 640x480px) Image search: [Google]
1476811327277.jpg
38KB, 640x480px
>>57281442
don't be mean to akkari senpai
>>
>>57281419
You just did it. Thanks. My professor does a shitty job of explaining of how things work. He just gives us 1 example and sends us on our own.
>>
>>57281459
anonymous plebeian kys
>>
>>57281442

You too. :^)
>>
>>57281263
That is some extremely basic code so I'll have to assume you know basically nothing
public static int pairCounter(String str) {
int count = 0; // This represents the number of pairs

/* iterate over the string.
* int i = 1; start at the second character (index 1) since we will look backwards
* i < str.length() - 1; keep looping while i is less than the string's length - 1 (the last character is at index length - 1)
* i++ increment i by 1 each time
*/
for (int i = 1; i < str.length() - 1; i++) {

/* if there are two consecutive characters which are the same (comparing the character at the previous position, i - 1, with the character at the current position, i) */
if (str.charAt(i - 1) == str.charAt(i)) {

/* increment count by 1 */
count++;
}
}

/* return the number of pairs counted.
* The function could be used like:
* String myString = "hello";
* int numberOfPairs = pairCounter(myString);
* System.out.println("The number of pairs in " + myString + " is " + numberOfPairs);
*/
return count;
}


>>57281419
The for loop is correct, Java strings have indices 0 .. string.length() - 1 (0-indexed). The loop starts at 1 because it looks backwards (i - 1), so there's no point in iterating over the first character and it would in fact cause an error because you'd be doing charAt(-1).
>>
>>57281493
>more comments than actual code
>>
>>57281487
No, no, you're much better poster than me ;^)
>>
>>57281516
That's the point
>>
>>57281484
i'm not sure i said anything new
also, there is really no reason to create the String s

>>57281493
i am not taking issue with the lower end, but the upper
i don't think it's going to catch the pair in "abb" for example
>>
>>57281516
Give her a break you misogynist pig
>>
>>57281493
Ya I just started
>>
>>57281551
>her
>>
Doin this english to mandarin numbers i need to write a procedure that converts an American number between 0 and 99 written as a string, into the equivalent Mandarin.
the string is like this
trans = {'0':'ling', '1':'yi', '2':'er', '3':'san', '4': 'si',
'5':'wu', '6':'liu', '7':'qi', '8':'ba', '9':'jiu', '10': 'shi'}


for my edx work
>>
>>57281548
Ah I see now, it should be
for (int i = 1; i < string.length(); i++)

or <= string.length() - 1

>>57281553
if this code was provided by your professor as an example, I truly fear for you...
>>
>>57281526

Wrong!

t. DJT
>>
>>57276439
In java how do I extend multiple classes. Like say a class needs to extend thread and activity.
>>
>>57281615
No, it's true, I'm a terrible poster. Sometimes I just shitpost for hours at a time. Before I know it, entire threads are derailed ;^)
>>
new
>>57281637
>>
>>57281621
You don't, you can only inherit (extend) from one class.
>>
>>57281644
So if my class needed to do this Im just shit out of luck. This really makes java seem inferior.
>>
>>57281621
There is no multiple inheritance. You can only do multiple extends of interfaces.
>>
>>57281663
It's actually superior for it. Multiple inheritance is a well documented cancer.
>>
>>57281663
Multiple inheritance is tricky, which is why languages like Java did not include it, but there are alternatives. Look up Interfaces, this will almost certainly be exactly what you want.
>>
>>57280782
I've tried that... But it doesn't let me pass a proper anonymous function, as it seems to create an IntObject::<lambda ...>. At least that's is what I've understood.
The error is the following:
error: no matching function for call to ‘BuiltInFunction::BuiltInFunction(IntObject::IntObject(int)::<lambda(const Object&)>)’

And the BuiltInFunction constructor is the following:
BuiltInFunction(Object& (*function)(const Object&))


Why is this so hard on C++? Am I totally overlooking something?

I'm trying to build around it on another branch, but other suggestions are still welcome.
>>
>>57279937
You're an idiot.
>>
>>57278679
GODDAMNIT CARLOS
Thread posts: 320
Thread images: 23


[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.