[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: 26
File: spheres.jpg (90 KB, 800x800) Image search: [Google]
spheres.jpg
90 KB, 800x800
Old thread: >>54739798

What are you working on?
>>
File: AAAAAAAAAAA.jpg (9 KB, 342x342) Image search: [Google]
AAAAAAAAAAA.jpg
9 KB, 342x342
first for functional programming is shit!!
SHIT!!!!
>>
>be pajeet
>can't understand functional
>can only write java poo code
>big companies can only afford pajeets
>poo languages become mainstream
>20 years later
>poo languages still trying to copy shit that functional languages had 30 years ago
>>
int fill(int *x, float *y) {
*x = 1;
*y = 0.5;
return *(char *) x;
}

>undefined behavior
>>
someone link me some /dpt/ shit on youtube to watch. my brain cells are dying from b oredom
>>
>>54744692
https://www.youtube.com/watch?v=rRbY3TMUcgQ
>>
Trying to automate the data entry for some call center phone statistics. Using Java to read text files, and output to an excel file. I hope to have it set up for no one to ever have to touch it again.

It's going pretty well so far, and its actually my first "large" project that is independent of school so its exciting too.

Does anyone have experience writing scripts for Avaya software?
>>
>>54744692
https://www.youtube.com/watch?v=n_dU8qdH77M

Notch making a game, set to a song Notch made
>>
>>54744672
t. unemployed
>>
>>54744383
read up on this
https://fsharpforfunandprofit.com/series/why-use-fsharp.html
then progress like so
https://fsharpforfunandprofit.com/learning-fsharp/
https://fsharpforfunandprofit.com/series/thinking-functionally.html
https://fsharpforfunandprofit.com/series/expressions-and-syntax.html
https://fsharpforfunandprofit.com/series/understanding-fsharp-types.html
http://fsharpforfunandprofit.com/posts/recipe-part1/


of course you could go to haskell
https://github.com/bitemyapp/learnhaskell
>>
>>54744672
>20 years later
>functional languages still useless shit
>>
File: fizzbuzz.png (24 KB, 735x314) Image search: [Google]
fizzbuzz.png
24 KB, 735x314
>>
libtorrent is bloated, hard to install, and difficult to call from outside C++. The Bittorrent project is structured into individual protocols and extensions that would be straightforward to gradually integrate. Tell me why I shouldn't write a cross-platform C torrent client library.
>>
>>54744749
holy fuck, that's insane that he did all that in 6 minutes
>>
File: fizzbuzz rules.png (27 KB, 1132x264) Image search: [Google]
fizzbuzz rules.png
27 KB, 1132x264
>>54744782
>>
>>54744672

Functional features that OOP/procedural languages steal really do make them easier to use, though.

Sure, maybe they're old hat, but they are nice to have.
>>
>>54744782
>System.Console.ReadKey()

Jesus Christ you're retarded
>>
>>54744804
Literally nothing wrong with this
>>
>>54744803
Closures, pattern matching, modules, generics, etc., came from procedural languages in the first place.
>>
>>54744831
(You)
>>
>>54744831

We all knows that McCarthy invented everything good about programming in the late 1950s.
>>
In pic related I've implemented a class in javascript;
the instantiated class, 'primegen', has data, state and behavior.
I could have added primitives to 'primegen' and kept them updated with 'this', for example 'last', but I was lazy.

C++ and Java fags: 0, Javascript fag: 1
>>
>>54744869
I had to deobfuscate some malware written in JavaScript at work today and now I hate it with a burning passion.
>>
Is there a bitwise operation that can be performed on 2 bytes of data that would increase its size to more than 2 bytes, and can be reversed to get the original 2 bytes back?
>>
>>54744676
>C
>undefined behavior: the language
>>
>>54744897
Hashing functions are just a myth
>>
Java noob question.

I have a static long variable "a" in class "X".
System.out.println(a) gives me the correct value when called from class "X", but calling System.out.println(X.a) from class "Y" always returns 0.

Am i missing something?
>>
any good books or references for JavaFX?
>>
>>54744865
He actually stole it from IPL and FLPL, but Lisp shills pretend those languages never existed.
>>
>>54744941
getters and setters exist for a reason
>>
>>54744953
Still, i'd like to know why it is not working.
>>
>>54744953
to obfuscate code
>>
>>54744952

Oh wow, it's true.
>>
>>54744869
>ES6 functions
>old style classes
disgusting
>>
>>54744968
because your class Y doesn't have access to the variable in class X
>>54744969
yeah exactly
>>
>>54745012
Not him, but if it was a public static variable wouldn't Y be able to call it?
>>
>>54745012
This >>54745030. Why doesn't it have access? Wouldn't there be a compilation error if that was the case?
>>
How can I set a program to run at a certain time every week? Just needs to call a Java program in Windows 7.
>>
>>54745062
Task Scheduler
>>
>>54745070
Looks perfect, thanks.
>>
>>54744672
kill yourself smug fag
>>
>>54744969
more to controll access
>>
Say I have defined serialization interface like this:

template<typename T>
struct Serializer {
std::string serialize(T const &obj) const;
};


And have a concrete serializer for type int defined like this:

struct ConcreteSerializer : public Serializer<int> {
std::string serialize(int const &integral) const
{
return std::to_string(integral);
}
};


Is there a way to have
Serializer<int>
default to ?

I basically want to be able to write
Serializer<int> s;
and create a
ConcreteSerializer
in the process.

Something like
Serializer<int> = ConcreteSerializer
>>
>>54744672
>use a language that makes use of currying
>call other people pajeets
>>
>>54745213
>Is there a way to have
Serializer<int>
default to ?
Is there a way to have
Serializer<int> 
default to
ConcreteSerializer
?
>>
>>54744785
You should write a cross-platform C torrent client library.
>>
>>54745228
Curry is an English surname
>>
One day ISUCKGTP will learn to post in /pol/ without looking like a complete outsider
>>
>>54744672
>Big companies can only afford pajeets

kek
>>
File: primegen.png (12 KB, 465x221) Image search: [Google]
primegen.png
12 KB, 465x221
>>54744869
>>
File: ant NEETS.png (182 KB, 866x635) Image search: [Google]
ant NEETS.png
182 KB, 866x635
I'm trying to learn to code. I know absolutely nothing about programming, and while i know more about computers than most normies, I wouldn't say I'm well versed in that either (to solve most of my computer problems I have to resort to google)

What is a good site to learn to code Python? I tried Codecademy for like an hour before I realized it was teaching me nothing because it only shows you specific circumstances in a vacuum and rarely has you use past knowledge in an exercise or lesson. Also, it taught me nothing about how the language actually works, or the differences in terminology like a high-level or low-level language.

>tl;dr
What is a good, free resource to learn to code? Python to start preferably, C++ once I'm more experienced.

I'd like to be a full-time NEET like a year from now, so I need to get started on this shit ASAP
>>
File: 1409270993591.jpg (300 KB, 1200x948) Image search: [Google]
1409270993591.jpg
300 KB, 1200x948
>his language doesn't have monads
>>
>>54745333
is that ruby?
>>
>>54744785
Maybe you should write a cross-platform C torrent client library.
>>
>>54745365
no, it's F#
>>
writing an Artificial Neural Network to learn how to play 2048 better than me.
>>
>>54745386
so uh...
i think the F# code you wrote is cool, don't get me wrong.
I think es6 has generators, i just didn't use them.

If you were trying to show that your code is better than mine though, you have to realize that i implemented a class with multiple methods (next, all and reset).

so if this is just a LOC contest, then you're comparing apples to oranges
>>
>>54745334
LPTHW is fine
>>
>>54745396
also writing it in Groovy because why not.
>>
>>54745365
>let, yield
I don't think it's ruby

>>54745334
you want to learn how to code? don't start by watching hours of videos on some site
pick a problem to solve, pick a language you'd like to learn, and solve it. you want to pick up on python.. I like to recommend writing a reddit bot. It can be as simple as combing through the latest posts on a subreddit looking for keywords and reporting it to your console, or maybe messaging your personal account, or making posts, etc.
You'll have to figure out to install python, get an editor set up, install the reddit python packages, and go through all the shit figuring out how to accomplish whatever it is you want to do.
You'll have to google the entire way through, and it may seem daunting and a lot to figure out at the start but if you get through it you'll learn a lot.
You can do other things too of course, picking something math - related to solve is always a good choice
start out kind of small and keep expanding. Always ask the question 'is this the best/easiest/most elegant way to do this?'
After you get a feel for what programming is then you can spend a few hours watching videos to learn better ways / paradigms for doing things
>>
>>54745396
>>54745431
can I ask how does one write a neural network?
like at a high level how will it learn to play better than you?
>>
>>54745461
the same way you would learn to play better than you
>>
>>54744676
Some please explain to me why this is undefined behaviour. At best this is implementation defined.

It would definitely be undefined if you called the function with the same address for both parameters, but then you'd be violating strict type aliasing rules.
>>
>>54745302

I'll never be as racist or as hateful as most /pol/ users, so I doubt that'll be the case. I'll love nigresses forever.
>>
>>54745473
by playing the game a lot then?
>>
>>54745461
well the basic neural net that I've used before was basically a cyclic directed graph with weighted edges that traversed the graph and outputted the states of the visited nodes, whatever those may be. I used this for music generation, poetry generation, and twitter bot programs. This one I intend to use some of the more traditional neural network designs to map a certain layout of the 2048 board to a specific directional output up, right, left, down then use evolutionary tactics like pruning and simulated annealing.
>>
>>54745506
yes

>>54745403
all:
let r = primes n
r

next:
let r = primes n
r.GetEnumerator().MoveNext()

reset:
let r = primes n
let r = Seq.empty
>>
>>54745546
also I'm nearly certain this has to exist already. but I see it as a nice easy entrance into machine learning problem domain.
>>
What's the best programming language to learn right now?
>>
>>54745586
java
>>
>>54745334
>What is a good site to learn to code Python?
https://docs.python.org/
>>
>>54745586
C. It's always been C.
>>
File: 1441916195346.webm (2 MB, 994x1028) Image search: [Google]
1441916195346.webm
2 MB, 994x1028
how do you shorten float numbers in python 3? For example, if you return 3.14159 how do you shorten it to just 3.1
>>
>>54745626
import floatshorten
>>
>>54745632
Had to try to be sure this wasn't actually a thing.
Nice bait.

>>54745626
try
print('%.1f' % 3.14159)
>>
hey I forgot, how do I make git drop the changes since the last commit?
>>
>>54745422
fuck off z. s.
>>
>>54745626
round(x, 1)
>>
File: 1459275274543.jpg (127 KB, 1920x1080) Image search: [Google]
1459275274543.jpg
127 KB, 1920x1080
I'm making an irc bot, should I split up irc messages into lines and then just strncmp to check for commands, or would it be more advisable to construct some sort of lexical analyzer/state machine.
Also, can I use BNF for this or would that be retarded?
This is in C.
>>
>>54745554
jayeeeezus
so why do you use F#?
>>
File: 1459118398023.jpg (26 KB, 221x221) Image search: [Google]
1459118398023.jpg
26 KB, 221x221
>>54744948
>>
>>54745777
>should I split up irc messages into lines and then just strncmp to check for commands, or would it be more advisable to construct some sort of lexical analyzer/state machine
Either is a viable thing to do.
I would personally do the second, but that's because I really like writing parser related stuff. It also might be slightly overkill for the problem.
>Also, can I use BNF for this or would that be retarded?
Again, viable but possibly overkill.
>>
>>54745793
i could make a mutable stateful class if you wanted, but why?
>>
>>54745626
use a mathematical round function
unless you don't care about the sig, and just want the "int"
>>
File: MyOS1.png (2 KB, 720x400) Image search: [Google]
MyOS1.png
2 KB, 720x400
Working on an OS with this
https://littleosbook.github.io/

Apparently newlines aren't a thing this far down
>>
>>54745849
cute meme
>>
>>54745453
>pick a problem to solve, pick a language you'd like to learn, and solve it

>you want to know how to speak French? just start speaking it.
>you want to learn how to fix your car? just pick up a random tool and try to figure it out.

Great advice there, retard. You need to have at least some basic understanding of the language before you can start solving some problems.

>go through all the shit figuring out how to accomplish whatever it is you want to do

What does that supposed to mean? So, instead of watching a video on some site, he needs to read a text on some site or what the fuck do you even mean?
>>
File: MyOS2.png (2 KB, 720x400) Image search: [Google]
MyOS2.png
2 KB, 720x400
>>54745872
Thank you
>>
File: 34761567_p0.jpg (1 MB, 1642x877) Image search: [Google]
34761567_p0.jpg
1 MB, 1642x877
>>54745814
Overkill is my middle name.
>>
File: fin.png (805 KB, 2240x996) Image search: [Google]
fin.png
805 KB, 2240x996
I made a python program that creates a random color in a text file and then it writes that to an html file, and creates graphics in turtle to display the hex code.
>>
>>54745948
>https://littleosbook.github.io/
neat dude
>>
>>54745893
>>54745453
It is good advice though. That's how I learned Python, Java, Groovy, Visual Basic, Javascript and Ruby. The hard part is definitely starting out. I "learned" c++ just by taking the basic intro and datastructures classes in my undergraduate. If you pay attention/ apply yourself in a learning atmosphere like that or codecademy or coursera or getting someone to teach you one-on-one it really helps to lay the groundwork. Really I think it starts with a real thirst for the knowledge, not just "I wanna learn to code because...". I personally wanted to learn as much as I possibly could about computing which started with programming and lead to things like finite state automata.
"you don't become great by trying to be great. You become great by wanting to do something, and then doing it so hard that you become great in the process." - Randall Munroe
>>
Is there a way to get Node's REPL to show the definition of a function?
For example if I had
function a(){ return "hi"; }

what could I type into the prompt to make node show the definition of a?
>>
>>54745333
redid this using a sieve
still asynchronous which is pretty good
>>
what is the datatype of
 sizeof 
in C?

long? int? short?
>>
>>54746031
 a.toString() 
>>
>>54746043
size_t i'd assume
>>
>>54746043
size_t
>>
>>54745378
>>54745244
Oh yes, I wasn't expecting this response
>>
>>54746079
>>54746073
>size_t

source? how do you know this>?
>>
>>54746043
size_t
>>
>>54746124
http://en.cppreference.com/w/cpp/language/sizeof

>Both versions return a constant of type std::size_t.
>>
If you're pregnant with a boy, you're growing a pair of balls
>>
>>54746124
It was Dennis Ritchie's dying words.
>>
>>54746142
thanks!
>>
Help a CSfag, I have to create a GUI Button that saves all of the data received from my program to a database called top_ten.db. The db is structured as Top_Ten (table) -> Then two columns, one called Rank (Int) and Description(String). I cant get my solution to work for moving the music data to the database.

Here is the pastebin -
http://pastebin.com/wq822cND
>>
>>54746380
Forgot to add, I can either have the save button on my introduction window and allow users to save after they have selected a window or on each window allowing users to save the results of the page they are currently looking at.
>The 10 entries have to be overwritten every time the user clicks the save button.
>>
>>54746380
>>54746438
few things:
>too much whitespace
>too many comments (don't comment simple shit that can be easily understood)
>pass vars between functions instead of using global vars

is the problem just in saving the data to the database? do the other functions save the data? do you actually get music data to save to the db?
>>
>>54746547
Thanks for the feedback, I'll clean it up once i've finished. I get this error output when I try to save the music data.

 
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1489, in __call__
return self.func(*args)
File "/home/bilieu/Documents/Building IT Systems/Assesment/Top 10/top_ten(1).py", line 317, in music_db
topten_db.execute("INSERT INTO Top_Ten VALUES (?, ?)", (float(line4), str(music_results)))
ValueError: invalid literal for float(): 1) One Dance
2) This Is What You Came For
3) Can't Stop The Feeling!
4) Don't Let Me Down
5) Sound Of Silence
6) No Money
7) Just Like Fire
8) I Hate U, I Love U
9) Say It
10) Panda
>>
>>54746631
>hurr durr why can't I turn an arbitrary string into a float

kill yourself
>>
>>54746659
My bad, I was just trying different things because int wasn't working
>>
File: 1395343863414.jpg (63 KB, 500x628) Image search: [Google]
1395343863414.jpg
63 KB, 500x628
Lisp vs C: Inverted index

https://bpaste.net/show/e8035eda2f4b
https://bpaste.net/show/3d769ba9e0c4
>>
>>54745334
newb here

al sweigart's book "automate the boring stuff" has helped me get into programming with python and I've having an okay go at it so far, his books are available online at

http://inventwithpython.com/
>>
File: 1424950028866.png (302 KB, 1920x1080) Image search: [Google]
1424950028866.png
302 KB, 1920x1080
Rollin
>>
>>54747061
stop posting that shit, and get the fuck out of here.
just make a new thread or something, ffs
>>
using Django to fizzbuzz in my browser lads

going to use bootstrap to style it after
>>
>>54746883
Typical lisp narcissism rearing its head. I don't even have to know lisp to understand there's no trie implementation in there.
>>
>>54746883
And Haskell would be better than both
>>
>>54747418
get out of here ricky
>>
What does it mean if something is "turing complete"?

That you can use it to calculate any problem given enough ram?
>>
>>54747494
it can solve any problem that a Turing machine can, given an appropriate algorithm and the necessary time and memory.
>>
>>54745586
Racket
>>
>>54747505
is is that a yes?
>>
>>54747582
Pretty much...
>>
>>54744676
Remove the pointers from
*x=1;
And
*y=1;
I haven't used C that much but I think it should fix it
>>
Ideas for summer projects:

>Port CoreCLR to RISC-V
>Make LLVM backend for GB-Z80. I don't know if this exists, and if so, how well it works, but it would be cool to try and get some Rust or C++14 running on a Gameboy.
>Minimal operating system kernel.

What else could I do that's interesting...
>>
>>54747631
You could make friends instead of blogging on a mongolian passport counterfeiting BBS.
>>
>>54747631
Definitely the one of the first two, not last
>>
>>54747642

I have friends. But I can't spend my summer doing nothing but hanging out with friends. I'd like to get at least some personal projects to throw on a resume.

>>54747675

To be fair, I have dabbled in that area before.
>>
>>54747631
dumb tripfag fuck off to reddit
>>
>>54747709

No, I think I'll stay here and make you mad some more.
>>
>>54747494
>any problem

No, especially not the problem of the halting kind.
>>
>>54747631
Make a computer gf
>>
Yearly reminder to filter tripfags. They live off (You)s.
>>
What's the best language for large scale statistics and data management?
>>
I wish I started making shit earlier. I'm about to graduate and I can barely make a website or shitty mobile game.
>>
>>54747845
R?
>>
>>54747841

AI/ML/NLP shit is hard tho.

>>54747845

You'll have to be more specific with your needs, but R is big in the stats community.
>>
>>54747845
APL
>>
>REEE WHY WONT IT RUN

def music_db():
connection = connect(database = 'top_ten.db')
topten_db = connection.cursor()
music_int = map(int, re.findall("[-+]?\d+[\.]?\d*", line4))
music_str = ', '.join(music_results)
params = (music_int, music_str, )
topten_db.executemany("INSERT INTO Top_Ten VALUES (?, ?)", params )
topten_db.commit()


I get this error message, anybody know how to fix this issue?
in music_db
topten_db.executemany("INSERT INTO Top_Ten VALUES (?, ?)", params )
ProgrammingError: Incorrect number of bindings supplied. The current statement uses 2, and there are 10 supplied.
>>
File: fellow adults.png (246 KB, 500x329) Image search: [Google]
fellow adults.png
246 KB, 500x329
>>54748375
>Stupid C Student
>>REE WHY WONT IT RUN
>>
>>54748418
pls help senpai
>>
>>54747061
I like to call this one cuck roll
>>
>>54748375
What's so hard for you to understand ?
You have a thing that takes 2 inputs and you're giving it 10 inputs. You need to format music_str so it passes a single string to your sql command.
>>
>>54747061
roll
>>
>have to do quizzes (multiple choice) for interview
>literally 40 seconds to read and answer over 60 of them each
ogre
there is one about the stupid IEEE float shit as well
>>
>>54747603
Pajeet pls go
>>
For a prime counter, where you build a list of prime and check each new number through that list. Should you divide by two for less computation or square root for the least amount of checks?

I'm using Python btw.
>>
File: Capture.png (15 KB, 367x359) Image search: [Google]
Capture.png
15 KB, 367x359
>>54748807
>>
>>54748815
>not rounding the square root before casting to int
>>
>>54748838
Well I'm straight
>>
Does this accurately measure the number of elapsed milliseconds?
Could I make it do nanoseconds if I divide by 1 billion instead of CLOCKS_PER_SEC?
clock_t start = clock();
int i;
for (i = 0; i < 10000000; i++)
{
malloc(1);
}
clock_t end = clock();
int delta = (((float) end - start) / CLOCKS_PER_SEC) * 1000;
printf("elapsed time: %dms\n", delta);
>>
I'm so confused /g/
I'm used to coding C#
Been working with C++ for a few weeks
Trying to write a general method which uses templates, because otherwise I'll have like 6+ overloads which I can't be bothered altering the code in all of them when it's so similar
So here's what I want to do

[CODE]
template <class TYPE>
void Object::Method(char updateType[], TYPE input)
{
if (updateType == "TopLeftPoint2D")
{
sf::Sprite *spriteToUpdate = spriteBank.getSpriteByID(&spriteID);

spriteToUpdate->setPosition(input.x, input.y);
}
//More update options
}
[/CODE]

The input here is a Point2D object with public variables x and y.
I think I need to cast the input to Point2D once I know that's what it is (inside the if statement)
soz for being mentally handicapped but all the examples I can find are like
>look you can multiply a double and integer without overloading your method 4 times
so no casting examples
>>
>>54748974
apparently i fucked up my code tagss too
template <class TYPE>
void Object::Method(char updateType[], TYPE input)
{
if (updateType == "TopLeftPoint2D")
{
sf::Sprite *spriteToUpdate = spriteBank.getSpriteByID(&spriteID);

spriteToUpdate->setPosition(input.x, input.y);
}
//More update options
}
>>
>>54748992
if you have any problems it's probably .x and .y
you could use something like an overloaded operator[] and then use input[0] and input[1], or overload std::get and do std::get<0>(input), std::get<1>(input)
(and you can combine this with enums to get std::get<x>(input) or input[x])
>>
>>54748992

>comparing char[] strings with ==
You're gonna have to stop doing that. It won't do what you want it to do.
>>
>>54749015
Yeah you totally lost me sorry
But it's not the x y shit
if I comment out that line of code, it still doesn't compile
It doesn't like the function call in a different object
I could screen shot the error message
the code is LNK2019

>>54749048
Oh true actually
I remember reading some shit about that
well I'll work that out once I actually get it compiling
>>
This code works at sending data to my database but they all go to a single cell, pic related. How do I make it so that all of the values are separate rows inside the Description column?

# Save Music results to database
def music_db():
connection = connect(database = 'top_ten.db')
topten_db = connection.cursor()
#music_int = map(int, re.findall("[-+]?\d+[\.]?\d*", line4))
music_str = ', '.join(music_results)
params = (music_str,)
topten_db.execute("INSERT INTO Top_Ten VALUES (NULL, ?)", params)
connection.commit()
topten_db.close()
connection.close()
>>
>>54749076
How are you calling it?
>>
>>54749076
>>54749131
Wait you didn't put that in a .cpp file did you?
Templates don't work properly with .cpp files
>>
>>54749142
I put it in the .h and the .cpp file of that object

Calling it with
    int temp1 = rand() % 920;
int temp2 = rand() % 420;
Point2D temp3(&temp1, &temp2);
graphicsManager.updateSpriteByID("TopLeftPoint2D", temp3);
>>
>>54749155
What error are you getting?
>>
>>54749155
You can't have a templated definition in the .cpp
>>
>>54749155
Post your .h .cpp and main.cpp
>>
File: Capture.png (7 KB, 1246x36) Image search: [Google]
Capture.png
7 KB, 1246x36
>>54749166
see pic
>>54749176
If I didn't put the template definition in the .cpp as well I got some different error

>>54749178
Okay I'll try pastebin for the first time lol
>>
>>54749099
pls help me famalam
>>
>>54749208
Put the definition in the .h
>>
>>54749218
Here's the .h
(removed all the rest of the shit in the object tho)
http://pastebin.com/Z7qdpSpw
>>
>>54749233
Put the definition for the template function in the .h
>>
>>54744782
I don't understand all the fuss about this fizzbuzz shit. I'm an English major and I've been programming in some form or other literally since I was 4 years old. At 8 I remember making a random erotic story generator with names from people in my school that used text-to-speech to read it out loud. I fapped vigorously. Sometimes I find old code I wrote I don't even remember.

I started programming for a living doing custom accounting and administration software for middle sized companies, but as open source became more prevalent, that kind of work was reduced to just setting up a server and installing whatever FOSS solution they wanted. That is something a CS major can do, so having no credentials, I had to move on.

I'm currently a web developer. There's so much demand nobody really cares what kind of degree you have as long as you can prove you can do your shit.

I am amazed, however, at the abysmal computer skills of CS people. Really, isn't that what you're supposed to be learning in school? Your incompetence is doubly frustrating for me because I have to fix your shit and deal with the fact that everyone assumes, by default, that you know your computers and I don't.
>>
>>54749238
That's it there?
Confused sorry
Could you show me where the template shit goes?
>>
>>54749268

Put this shit in your .h file and delete your .cpp file.

template <class TYPE>
void Object::Method(char updateType[], TYPE input)
{
if (updateType == "TopLeftPoint2D")
{
sf::Sprite *spriteToUpdate = spriteBank.getSpriteByID(&spriteID);

spriteToUpdate->setPosition(input.x, input.y);
}
//More update options
}
>>
>>54749257
>English major
>>>/lit/
>web dev
>>>/g/wdg
>you know computers and I don't
>>>/out/


>>>/trash/
>>
>>54749274
I think he has other stuff in his cpp file

>>54749268
Put ALL of the template stuff in the header
>>
>>54749268
>>54749274

#pragma once
#include <string>
#include "Point2D.h"

using namespace std;

template <class TYPE>
class SFMLManager
{
public:

void updateSpriteByID(char updateType[], int spriteID, TYPE input)
{
if (updateType == "TopLeftPoint2D")
{
sf::Sprite *spriteToUpdate = spriteBank.getSpriteByID(&spriteID);

spriteToUpdate->setPosition(input.x, input.y);
}
// More shit
}

private:

};
>>
>>54749291

Plus move all your shit from your cpp file to the header file.
>>
>>54749291
>>54749299

Include your header file instead of the cpp file.
>>
>>54749280
I'm sorry I didn't want to hurt your feelings, just to vent a little.

Seeing as you're mostly college students and high schoolers here I thought you could benefit from having some perspective of the real world.

>English major
>>>/lit/

See? That's what I mean. I don't care about English (I don't even write that well, and besides, I'm not English native). I just studied that because it was easy and I didn't really know what to do with my life back then.
I'm 10 times the programmer you are, and yet you send me to /lit/ just because of what my major is. That is backwards man.
>>
>>54745334
learn c
>>
>>54749280
>>>/g/wdg

By the way, C was my first non-scripting programming language and the first book I read in English (or one of the first) was a C introductory course.

What were you learning when you were 10 years old?
>>
>>54749289
I do have more stuff in my cpp, like a lot

>>54749291
This makes SFMLManager into a template or something
All the shit in cpp is now erroring about having not argument list
>>
>>54749328
> This makes SFMLManager into a template or something

What the hell do you think you're doing by adding
template <class TYPE>

at the top?

You're making a template class.
>>
>>54749349
Did you read my first post?
I just want a method that accepts an argument of an undefined type
That method is in SFMLManager and is called from another object
>>
if I have a custom class in c# that contains two ints (x and y coords), and I have a dictionary where the key is the custom coord class, and the value is data about the position (it's a tile map)

are each keys unique?

for example

CoordClass coord0 = new CoordClass(50, 60);
CoordClass coord1 = new CoordClass(50, 60);

Dictionary coordDict<CoordClass, int> = new coordDict<CoordClass, int>();

coordDict.Add(coord0, 0);
if(coordDict.ContainsKey(coord1))
{
//this isn't working but I need it to, what do?
}

that's my problem

should I instead, since my coords are actually shorts (short x and short y), bitshift and use one variable for my coordinates?

int coords = shortX << 16 | shortY;
>>
>>54749364
https://stackoverflow.com/questions/8627625/is-it-possible-to-make-function-that-will-accept-multiple-data-types-for-given-a
>>
>>54749364
Include this header in your cpp: >>54749291
Then do this to use it:

SFMLManager  newManager<int>;
newManager.updateSpriteByID(blah blah blah)
>>
>>54745334
Dont learn to code

Its not as fun or glamorous as you think it is
>>
>>54749374
I've looked through that exactly question (amongst others)
I decided to post here because I've been stuck on this for 2 hours when it should take minutes

>>54749382
No idea what you mean
That .h file is turning SFMLManager into a template

about to give up holy shit
>>
>>54749364
>>54749382

>>54749364
SFMLManager.h:
#pragma once
#include <string>
#include "Point2D.h"

using namespace std;

template <class TYPE>
class SFMLManager
{
public:

void updateSpriteByID(char updateType[], int spriteID, TYPE input)
{
if (updateType == "TopLeftPoint2D")
{
sf::Sprite *spriteToUpdate = spriteBank.getSpriteByID(&spriteID);

spriteToUpdate->setPosition(input.x, input.y);
}
// More shit
}

private:

};


Main.cpp or wherever you want to use it:
include "SFMLManager.h"

int main( int argc, const char* argv[] )
{
SFMLManager newManager<int>;
char foo [20];
int a, b;
newManager.updateSpriteByID(foo, a, b)

SFMLManager newManager2<string>;
char foo [20];
int a;
string b;
newManager.updateSpriteByID(foo, a, b)
}
>>
>>54749408
>>54749409
Is this still not clear?

If it's not, maybe you should give up.
>>
>>54749409
Last line supposed to be newManager2
>>
http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html

oh now I get it
>>
>>54749409
>>54749418
yeah I don't know how but you're really not understanding what I want to do
>>
def sqrtPrime(n, l=[]):
if n == 0:
return []
print(l)
lstPrimes = l # Why does not having list() fuck shit up?
isPrime = True

for count in range(2, n+1):

sqrt = count**0.5
for prime in lstPrimes:
if prime > sqrt:
break
elif count % prime != 0:
continue
else:
isPrime = False
break
if isPrime:
lstPrimes += [count]
isPrime = True

return lstPrimes


Why running this multiple times variable 'l' somehow contains the past lists.

>>> sqrtPrime(10)
[]
[2, 3, 5, 7]
>>> sqrtPrime(10)
[2, 3, 5, 7]
[2, 3, 5, 7, 2, 3, 5, 7]
>>> sqrtPrime(10)
[2, 3, 5, 7, 2, 3, 5, 7]
[2, 3, 5, 7, 2, 3, 5, 7, 2, 3, 5, 7]
>>>
>>
>>54749439
>>54749426
Give me 10 minutes I'll make a new project to show you
>>
>>54749440
wtf I am getting nothing, you sure that is the function
>>
>>54749439
>Trying to write a general method which uses templates, because otherwise I'll have like 6+ overloads which I can't be bothered altering the code in all of them when it's so similar

If you want to use a template this is how you do it.

If you don't want to use a template, then that stackoverflow link has another ways including the overloads that you don't want to do.

SFMLManager.h:
#pragma once
#include <string>
#include "Point2D.h"

using namespace std;

template <class TYPE>
class SFMLManager
{
public:

void updateSpriteByID(char updateType[], int spriteID, TYPE input)
{
if (updateType == "TopLeftPoint2D")
{
sf::Sprite *spriteToUpdate = spriteBank.getSpriteByID(&spriteID);

spriteToUpdate->setPosition(input.x, input.y);
}
// More shit
}

private:

};


Main.cpp or wherever you want to use it:
#include "stdafx.h"
#include "SFMLManager.h"

int _tmain(int argc, _TCHAR* argv[])
{
SFMLManager<int> newManager;
char foo[20];
int a, b;
newManager.updateSpriteByID(foo, a, b);
return 0;
}


I'm done.
>>
>>54749409
>>54749439
>>54749484

I fixed up some of the syntax that I previously fucked up.

This compiles and accomplish what you're trying to do.

You can't use different data types for the same function using a template without creating a new instance for each type.
>>
>>54749478
Yeah, using version 3.5.1, I copy and pasted the code in the post and still it does it.
>>
>>54749512
oh python 3, was using 2
>>
>>54749499
I'm basing it off this guys code:
http://www.codeproject.com/Articles/257589/An-Idiots-Guide-to-Cplusplus-Templates-Part

who did
template<class TYPE>
void PrintTwice(TYPE data)
{
cout<<"Twice: " << data * 2 << endl;
}


but all his examples use integers doubles and floats
>>
>>54749440
because of this
lstPrimes = l


if I had to guess, python is probably setting up a global scoped variable l
which is then referenced to lstPrimes

what is the purpose of this? Why not just return a local list
>>
So with python, a function parameter is somehow a global scoped variable? And setting the default of k to be [] not affect lstPrimes anyway to become empty as well?
>>
>>54749528
But it's not a class. It just a templated function.

If you want to do it like that guy you can do:

Something.h :
#pragma once
#include <string>
#include "Point2D.h"

using namespace std;

template <class TYPE>
void updateSpriteByID(char updateType[], int spriteID, TYPE input)
{
if (updateType == "TopLeftPoint2D")
{
sf::Sprite *spriteToUpdate = spriteBank.getSpriteByID(&spriteID);

spriteToUpdate->setPosition(input.x, input.y);
}
// More shit
}


Your cpp file where you want to use it:
#include "stdafx.h"
#include "Something.h" // File with the above code.

int _tmain(int argc, _TCHAR* argv[])
{
char foo[20];
int a = 0;
int b = 0;
string c;
char d = 'd';
updateSpriteByID(foo, a, b);
updateSpriteByID(foo, a, c);
updateSpriteByID(foo, a, d);
return 0;
}

>>
>>54749440
>lstPrime = l
>lstPrimes += [count]
this is just one of the many reasons why python is SHIT especially for learning
>>
>>54749596
how is this a thing honestly
defining an empty list in a parameter
>>
>>54749625
>how is this a thing honestly
you could ask that about a lot of things in python

or just stop using fucking cancerous retarded python

https://www.youtube.com/watch?v=2k0SmqbBIpQ
>>
>>54744831
No. Lisp invented everything in the 1950s
>>
>>54749613
So you're saying you can do it to a function outside of an object, but not inside...?
Not without making multiple instances (which can't be done in this case for my program)
>>
How's this for a first attempt at Fibonacci? I know you can make it a lot better but I'm just starting and this seems pretty simple.

fib :: Int -> Int
fib n
| n <= 0 = error "N must be greater than 0"
| n == 1 = 0
| n == 2 = 1
| otherwise = fib (n-1) + fib(n-2)
>>
>>54749658
>Functional
>And recursive
-10/10
>>
>>54744941
Do you initialize that variable, do you give it a value?
>>
File: 1455396440081.gif (645 KB, 969x700) Image search: [Google]
1455396440081.gif
645 KB, 969x700
>>54749684
Pls no bulli anon~
>>
What music does /dpt/ listen to while programming?
>>
File: fiercebully.webm (3 MB, 800x450) Image search: [Google]
fiercebully.webm
3 MB, 800x450
/dpt/-chan, dai suki~

Ask your much beloved programming literate anything (IAMA).

>>54749684
Please, don't bully.

>>54749658
>| n <= 0 = error "N must be greater than 0"
https://oeis.org/A000045

>>54744952
Not really
http://www-formal.stanford.edu/jmc/history/lisp/node2.html

>>54744692
https://www.youtube.com/watch?v=a9xAKttWgP4

>>54745586
A lisp

>>54745484
>It would definitely be undefined if you called the function with the same address for both parameters
No, even if the addresses are equal, there still no undefined behavior: Strict aliasing doesn't apply to the char type.

>>54744676
Already been debunked.
>>
>>54749658
Why does Haskell require you to type the function signature again

Doesn't the type system do that
>>
>>54749099
>>54749215
You're forming your SQL wrong.

You still here?
>>
I want to improve my knowledge in pointers in C++. Any books you guys would like to recommend?

>>54749658
Which language is this?
>>
>>54749721
Haskell
You reach satori after learning it
>>
>>54749706
The same thing I listen to otherwise.

My music tastes don't suddenly change if I'm programming.
>>
>>54749714
You don't need to nearly all the time but my book says doing it is a good idea
>>54749721
Haskell
>>54749710
You are right oops
>>
>>54749736
Oh I see, so it's optional
>>
>>54749710
>Already been debunked.
you mean you already got raped >>54741271
>they never learn
>>
>>54745484
>definitely be undefined if you called the function with the same address for both parameters
yes, that was the scenario
>you'd be violating strict type aliasing rules
correct
>>
Can someone help me out with Java's ImageWriter class?

BufferedImage imagePart = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB);

ImageWriter imageWriter = ImageIO.getImageWritersByFormatName("png").next();
imageWriter.setOutput(ImageIO.createImageOutputStream(new ByteArrayOutputStream()));

imageWriter.prepareWriteEmpty(null,
ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_ARGB),
imagePart.getWidth(),
imagePart.getHeight(),
null, null, null);


But, prepareWriteEmpty throws the following:

java.lang.UnsupportedOperationException: Unsupported write variant!


What does this mean?
Is it because it's a PNG image? Is it simply not possible to write to PNG images like this?
>>
>trying to implement a lagged fibonacci generator
>cant understand the pseudocode
>cant find any examples online

JUST KEK MY SHIT UP
I must be indian to suck this much at following simple psuedocode reeeee
>>
File: dank.png (327 KB, 954x744) Image search: [Google]
dank.png
327 KB, 954x744
What is the easiest way to make this? (pic related)

I want to have a HTML page with an image in the center, and have arrow buttons to load the next page with another photo.
This would be easy to make, but I have 2000 images, and yes they all need their own page (adsense etc).
Is there an easy way? I don't want to do this manually.

Ty senpai
>>
>>54749816
post the psuedocode so we can explain it pajeet
>>
Am i fucking retarded for not getting this?

Say we have an array a = [1,5,7,9]
length is n = 4
for(i = n - 1; i > 0; i--){
do something
for(j = i - 1 ; j >= 0; j--){
do something (x)
}
}



How many times will the line on X be executed (with n a random array length). Is it (n-1) * (n-1).
A friend of mine said it was (n(n-1)) / 2. But I don't see how that can be correct.
>>
File: sc.png (33 KB, 802x162) Image search: [Google]
sc.png
33 KB, 802x162
>>54749772
>>54749785
>>
pass an image id with GET request

cuck.html/?image_id=1

add all images to a db
use the passed in `image_id' to get the local PATH to image #1 and href it in the middle

beware of skiddies tho
>>
>>54749856
meant for
>>54749822
>>
>>54744605
>>54744605
I am trying to find R@nsome where code for a coding assignment but really cannot find it anywhere on the internet any of you have any liable sources?
>>
>>54749832
I got the pseudocode from cuckpedia

https://en.wikipedia.org/wiki/Lagged_Fibonacci_generator

i understand the sequence(1,1,2,3,5,8,13...) but cannot understand how you generate the random number from it.
>>
I originally learnt that true multitasking doesn't exist and that it's only an illusion.
However, I recently got more interested in Hardware and just to make this clear:
Does a multi-core system allow true multitasking?
>>
Hello developers, I'm here to ask you for some help.

I'm currently writing on a seminar work (is this the correct English term?) together with a partner.
The seminar's general topic is 'digital transformation' and we are writing about 'mobile shift'.

Within this work we've planned to include a subchapter on technologies to realize this mobile shift.
After having written about the basics of mobile interaction, gamification in apps, patterns, etc. I giving info about the conception models of apps to realize it (native, hybride, web).
I then want to give examples of how developing in the real world works.

The thing I don't know is about programming languages for dedicated apps on iOS and Android (and possibly Windows if you have knowledge on that):
If you program a native App for Android do you use Java? Does Java have any edges over programming languages not native to Android? Same question on iOS: I read you use Objective C or Swift but how does using other languages e.g. Scheme via LambdaNative relate to this?

Is the code compiled to whatever internal code is used? Does it matter what you program in?

Sorry for my limited developing and programming knowledge.

TLDR: how does programming (native) apps work?
>>
>>54749938
true multitasking doesn't exist
you may think automatic breathing and being able to think is multitasking, but those are handled by separate systems.

without the cerebellum you would have to breathe manually, blink manually and you would always have the feeling of your tongue not having a good place to rest in your mouth. (rekt ;^) )

You'd need multiple physical processing chips for 'true' multitasking.
>>
#define freeable __attribute__( ( __cleanup__( _free ) ) )

typedef int32_t int32;

void _free(void **ptr)
{
if (ptr && *ptr) {
free(*ptr);
*ptr = 0;
}
}

int main()
{
freeable int32* a = malloc(sizeof(int32) * 10);
return 0;
}


Just found out this is a thing in gcc, that's pretty neat.
>>
What would be a good book for learning Python as a first language?
>>
>>54749910
where's the pseudocode you dip? do you mean the generalized formula?
>>
>>54749698
>>54749710
>Hur dur tell me what you think of my program, but only if it's positive!
Fuck off, learn to accept criticism faggot.
>>
>>54749966
write program in plain text

compiler makes it to assembly instructions for the cpu its intended to run on

links stuff

creates executable file
>>
>>54749993
Automate the Boring Stuff with Python, and its documentation.
>>
>>54749993
there is none

python is horrible, especially for learning programming
>>
>>54747061
roll
>>
>>54750001
Thank you. So why do Apple, Google etc. recommend certain ways of going about it?
>>
>>54749853
yes, the return statement doesn't violate the standard; calling the function with pointers to the same storage is undefined behavior tho
here's another undefined behavior and there's no char to fixate on:
void g(int *a, double *d) {
int i = *a + 2;
*d = 3.1;
*d *= i;
}

are you too stupid to understand why it's undefined?
>>
>>54750011
i stopped writing bash scripts because of it
>>
>>54750011
Not the guy you're responding to, but why specifically is Python bad for beginners?
Just curious.
>>
>>54749979

GCC and GNU C offer quite a lot of interesting things. Most of them are bullshit unsupported elsewhere, but still neat.
>>
>>54749847
p-p-please help me ;_;
>>
>>54749966
Pajeet
I did research on this native vs trans-native (xamarin) vs JavaScript (Cordova, etc)

Do your own

Yes native means officially supported methods (Java for android, swift/obj-c for iOS, Windows can do c# and some others)
>>
>>54749979
c++ will blow your mind!
>>
>>54749966
>If you program a native App for Android do you use Java?
yes or C/C++. you can also use some other language with a framework built on top of the native android stuff

>Does Java have any edges over programming languages not native to Android?
yes java is literally the best and most popular programming language
>>
>>54750022
mostly so more people can collaborate on the same files easier

#include <stdio.h>

int main()
{
printf ("Hello world!\n");
return 0;
}

#include <stdio.h> int main(){printf("Hello world!\n");return 0;}


both these do the same thing but the first example is much easier to read
>>
>>54750050
I already know C++, though. :(
Thread replies: 255
Thread images: 26

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.