Old thread: >>57217788
What are you working on /g/?
>>57224975
first for nice OP image
What's Prelude?
>>57225015
i havent done haskell before but im pretty sure the prelude is where you define variables n shit like that, and import shit
How do you feel about makefile ricing?
>>57225059
I feel i don't know what that is.
>>57225015
prelude is a module which contains basic functions and data types that are frequently used in every haskell program
>>57224975
implementing gain & entropy for random decision trees
>>57225071
The followup question is probably embarrassing, but what's a module?
can anyone tell my about redeffing a class in common lisp?
does it delete all the slots that aren't in the new definition?(defclass butthole ()
((shape :initform 'star)
(poopoopeepee :accessor pepe
:initform 'smug)))
what happens if I redeffed it with shape and a new slot called owner-age
what would happen to instances of butthole who existed before the redefining?
>>57225113
literally just a file
>>57224816
Made some good progress fixing up errors on my C++ Linked List class. Still getting some weird issues that I can't quite understand or pinpoint, nor come up with a viable solution.
Header: http://pastebin.com/htPxuh5x
Main:#include "LinkedList.h"
#include <stdio.h>
#include <iostream>
using namespace std;
int main() {
LinkedList<char> *cool = new LinkedList<char>();
string st = "abcdefghijklmnopqrstuvwxyz";
for (int i = 0; i < st.length; i++) {
cool->add(&st[i]);
}
cool->print();
getchar();
return 0;
}
Can't sleep, so I've just kept working on my textboard. I implemented post deletion and installation. Also fixed a few weird bugs, but it's been pretty smooth.
Any and all suggestions welcome.
>>57225269
st.length()
>>57225285
How are you implementing user accounts?
I'm in an entry level Java class, my objective was to make a program that removes the vowels from any phrase you enter, and then to show how many letters out of the total were removed and what the rate or letter reduction was.
http://pastebin.com/gMJHLMDu
Can you guys make fun of my program? I'm 100% sure this is the ugliest, most retarded possible way to achieve my goal. What would have been the best way to do this?
>>57225297
Fuck didn't even notice. Now it gives me an error "Cannot convert argument 1 from char** to char*"
My prompt changed fromPrelude>to*Main>
What does *Main mean?
>>57225312
Currently, all users are just admins. The passwords are SHA-256'd/salted etc etc
>>57225361
>>57225297
>>57225269
Scratch that; here's what I get now:
"Exception thrown: write access violation.
this->myLast was 0xCDCDCDCD.
If there is a handler for this exception, the program may be safely continued."
>>57225352
be more careful in the future
>>57225362
it means you are in the module Main, aka, baby.hs
I think thats the default name in ghci when you dont specify a module name
>>57225394
any advice on the code though?
How do I implement a pool of worker threads with pthreads?
My use case is probably the most ideal thing ever, I have an array of thousands of independent strings and I'd like to be able to throw them through a battery of string manipulation routines and have them finish whenever.
>>57225362
Main is the module you defined in baby.hs.
Every haskell program file has a module declaration at the top, so the module looks like this:module MyModule(exported, function, and, Type, Names) where
import OtherModule(otherFunction)
exported = ...
privateName = ...
If you don't write a module header, it automatically inserts this:module Main where
The lack of an export list means every name is exported, and the asterisk in ghci means it's an interpreted or something I dunno. RTFM.
>>57225361
When constructing temp in add() you're trying to feed the constructor a pointer to a pointer, when it wants a pointer.
>>57225380
That's a segfault.
>>57225422
Just figured that out shortly after posting, now it runs but throws a write access violation.
why the fuck are no lispers in /dpt/
reeeeeee
>>57225415
Oh wait I think the asterisk means ghci will allow you to use unexported names defined in the module within the REPL.
>>57225422
Just noticed the second part of your post. How would I fix something like that? I've never run into a segfault before.
>>57225352
My first point:
Switch statements exist, and in my opinion look a lot more elegant than multiple if-statements. In fact, seeing loads of similar if statements is the biggest indication that you're new to programming.
All those "if" statements do something similar. Think about breaking it in to a function that takes a character and returns a boolean if it's a vowel.
>>57225431
>setf
Maybe you should ask yourself why you aren't a lisper?
>>57224975
Is it just me or are OpenSSL's docs godawful?
>>57225443
not him but
c++ makes me want to vomit but from a quick glance at your other file it seems like within the methods of a list element you start trying to access private fields of another list element
>>57225449
>he uses setq even though setf expands into setq
hahahahahahah
I bet you use set to
>>57225443
Look where's the point in which your program tries to access a pointer to a nonexistent item, r somewhere where you left the boundaries of an array.
you could do the good olestd::cout << "something useful: " << useful value << std::flush;debugging or use an actual debugger.
>>57225412
I'm assuming each string can be processed independently.
Depends on if you're using C++ or just C. If you're using C++ I would just make a vector containing all of your joinable threads, starting them as you add to the vector. Then just iterate over the vector and join them all back
This isn't technically the best way to do it but it's simple and works
>>57225457
>he thinks I was referring to his mode of mutation
>mutating data at all
>>57225447
thanks, this is easily my ugliest code ever. I also just realized that every time it says numVowels + 1 it is completely pointless.
>>57225456
Oh shit I didn't even think about that, I'll try changing up a few things. And yeah I know, I'm more of a C# and C kinda guy, C++ just has too much tumor-inducing eye candy.
>>57225470
>muh purity
>>>/haskell/
>>57225443
What? I thought you said you had experience with C.
I don't suppose you know how to use the debugger then either? You can stick brakepoints in the margin of your code in VS. And then step through your code line by line, or continue to the next brakepoint.
Or you can just do it the old school way with trace prints and commenting out code until you localize the problematic code.
>>57225504
I know how to use the debugger, I can't remember a time I've ever run into something like that before in C that wasn't just a syntax error I didn't notice at first glance. I'm more new to C++ though which is my biggest problem, along with abstract data structures.
>>57225438
>unexported names defined in the module within the REPL.
I'm just going to smile and nod.
>>57225466
>join them all back
I'd like to keep them floating around without actually destroying them.
Isn't that the whole point of a thread pool?
Otherwise, I'd just make a for loop with pthread_create and another for pthread_join, which is really simple, but it's not a pool.
>>57225530
>C programmer
>never run into a segfault
Nope. I don't believe it.
>>57225544
you didn't explicitly export them
repl = read eval print loop
basically an interactive session
it will let you use code you didn't explicitly export within the interactive session
>>57225562
I've only done C for about a half a year now, and it's only been really simple things. Most of it was just messing around with inline assembly anyway.
>>57225431
There are, though. In an earlier thread just today we had a grand time talking about Lisp.
>>57225410
well i'm not a java person but i agree with the other guy -- any time you are repeating the same thing 6 times something is probably wrong
your else clause seems useless
what if your user enters something with ~? that won't be good
i'm worried about phraseLength. unless the string is also eating up a newline (don't have the energy to check this) then you can set this to userPhrase.length(), iterate up to i < phraseLength, and save a bunch of .length() calls later. maybe this all gets optimized away later but it looks funny
this is not to say that you can't do better performance-wise. i'd have to think about it
>>57225544
How on earth is that not clear?
You define names in a module.
In the module header you list the names that you want to export so that other modules may use them.
You can use an import declaration to use names from other modules in your module.
Prelude is the name of a module that defines a long list of types and functions specified in the language report. The Prelude module is always implicitly imported.
...Don't tell me you don't know what a repl is?
>>57225580
not enough desu
anyways
how frustruated were you when learning lisp?
I wanted to use public libraries so that I could do something producitve but then came the package, modules, system crap
I hope the road to lisp helps me in the end
>>57225565
Oh ok. I see. Thanks.
So not exporting things is a kind of encapsulation.
>>57225593
>Don't tell me you don't know what a repl is?
Well, i didn't up until 30 seconds ago.
>>57225610
That thing,
that you made screenshots of
ghci
that's a repl.
It reads text you type as haskell expressions
then it evaluates those expressions
prints the result
and loops back.
How does /dpt/ deal with depression while programming?
Anyone used GDI+ before? Trying to get access to the pixel data (preferably in a BYTE array) from a saved .PNG file, but can't get anything to work.
>>57225597
>how frustruated were you when learning lisp?
Mm, not frustrating, per se, just needed to get used to how different things were. The Racket documentation really helped out. I've probably read so much of the documentation at this point I could teach a class.
>>57225633
be a man
>>57225633
SSRIs
>>57225643
you started with racket, huh
I'm doing common lisp
its kind of a pain making real programs because its a repl even if not in an interactive session
had to learn the properties of packages, systems and even learn to use asdf in order to include other code
also, how is racket
whats different from other lisps
>>57225633
>not filtering emotions
pleb
learn function programming and you'll be calm and intuitive
emotions will go by themselves
>>57225693
Racket is basically Scheme, but there's a lot of stuff built in. It's very much a "kitchen sink" kind of deal, so you have a package manager, lots of neat macros, and other things. It's largely the same as any other Scheme, but the for/* macros are a godsend.
I was following some examples in a C Programming book today, and I got a compiler error about initializing an int in a for loop.
Why does this work in C++ but not C?
>>57225736
tell me about those
i'll give it a shot after clojure
should i continue trying to learn haskell or is it a meme? i've just done babby's first lambda.
>>57225756
For reference, here's the error:
error: 'for' loop initial declarations are only allowed in C99 mode
note: use option -std=c99 or -std=gnu99 to compile your code
||=== Build failed: 1 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|
Why does it do this?
>>57225757
The for/* macros are for iteration. The basic for loop looks something like this(for ([len (length '(1 2 3 4 5))]
[i (in-naturals)])
(printf "len: ~a, i: ~a\n" len i))
It does something and then returns (void), similar to for-each. One that I use rather frequently is for/list, which is very similar to map.(for/list ([sym '(a b c d e f g)])
(printf "sym: ~v\n" sym)
sym)
#| =>
sym: 'a
sym: 'b
sym: 'c
sym: 'd
sym: 'e
sym: 'f
sym: 'g
'(a b c d e f g)
|#
is actually equivalent to(map (lambda (sym) (printf "sym: ~v\n" sym) sym) '(a b c d e f g))
#| =>
sym: 'a
sym: 'b
sym: 'c
sym: 'd
sym: 'e
sym: 'f
sym: 'g
'(a b c d e f g)
|#
There's quite a lot of different for/* macros that allow you to iterate over hashes and vectors. There's even a for/fold which is some crazy ass shit.
>>57225849
I haven't looked at the loop maccro in cl, but would you say that this is better than the loop macro?
>>57225886
I'm not much of a CL programmer so take what I say with a grain of salt. I don't know about better, but the macros in Racket are, well, there's just more of them. AFAICT the loop macro in CL just for looping, while most of the for/* macros in Racket return something. So for/list returns a list, for/vector returns a vector, and so on.
>>57225633
CTRL-F "emotions"
replace with ""
>>57225816
>>57225756
Pre-C99, the definition of a for loop was strictly:
for(<set a variable>; <condition>; <expression>)
But after java, C++, and other languages adopted initializing a variable inside the for loop, it was changed to:
for(<set a variable or declare one>; <condition>; <expression>)
C is a relic from the past where it was too complicated to do that from the get go.
>>57226026
:%s/emotion//g
>>57225756
man your compiler, you can set your standard to C99
>>57225113
maybe like point to read from process from?
Someone keeps asking me to make my javascript compliant with LibreJS even though it's GPL already.
It's not even minified or obfuscated.
>>57225352
I like it actually. This takes virtually any statement and will always spit out the right answer. All in like 50 lines of code a good amount considering a large portion was just conditionals. Find ways to condense those maybe with booleans.
>>57226065
Hmmm, interesting.
Thanks.
>>57226107
1) I'm actually on Windows, sadly.
2) I just wanted to know WHY. I wasn't asking how to fix; I was confused about why it did this in the first place.
tfw you get banned from /r/computerscience for telling someone who said they "identified as agender and sir is not their pronoun" they were mentally ill
>>57226360
The guy above you already posted why so I was just letting you know that you can set the standard manually.
>>57226371
types are essential
>>57226382
there's only two possible types, anything else should be considered malformed code and should be reviewed and rewritten.
>>57226371
You can get banned from /g/ for saying rude things about transgendered people. The moderator is very touchy about the subject.
___He____ does it for free.
>>57226398
jesus it's hilarious isn't it? if you're mentally ill the worst thing you can do for yourself is to pretend that you aren't and that it's normal, and block out all normal people. It's a one way trip to crazy land of denial and depression.
>>57226371
To be fair, you'd be ostrosized and/or banned from any public establishment for saying the same thing.
>Tfw you learn some scheme and common lisp and suddenly you start to like javascript and python after hating them for years
>>57226497
Yeah, but this isn't a public establishment with a reputation to uphold. Anyway, I'm not mad about it, just thought it was hilarious. /r/computerscience generally consists of "how to exit vim" or "how to reboot my dads laptop"
>>57226518
>"how to exit vim"
Hopefully the people there are smart enough to tell people to use emacs instead.
>>57226557
Nah, they'll instead just tell you to purchase Sublime Text or download an IDE.
>>57226504
How?
After I learned Racket I started to hate python because of its complete inferiority. And Javascript is just mediocre.
I want to learn how program but i don't know where to start from, any suggestions?
>>57225756
Because C was built for the processor, not for C.
>>57225059
I admit that I do this however it usually detracts greatly from my actual productiveness. Avoid at all costs.
Trust me,srcs=$(wildcard src/*.c)
objs=$(srcs:src/%.c=obj/%.o)
all: $(objs)
$(cc) $(lflags) $(objs) -o $(binary)
obj/%.o: src/%.c
$(cc) $(cflags) $@ -c -o $<
is plenty.
>>57225924
CL loop macro is probably full of more features, but Racket for/__ macros are more consistent and are usually enough. Plus you have stream iterators which allow you to emulate most of CL loop's syntaxy stuff without relying on hardcoded syntax.
This is generally true of the two Lisps; CL is more "pragmatic" and a bit sloppier, but more powerful. Racket is more "academic" and very neat and consistent, still very powerful as a lisp, but wasn't driven by software developement needs like CL was.
>>57226562
Sublime text is actually good, though.
>>57226672
It's okay. It's not "good". It's not worth any money, nor is any text editor. It is certainly not worth $70.
>>57225431
Dlang deprecates Lisp.
>>57226717
>D fags shilling this hard
>>57226724
Quit being a fag and let Andrei give you the D.
>>57226725
You mean the other way around, don't you?
Anyway, we both know that D is superior to Lisp.
>>57226360
>I'm actually on Windows, sadly
And this matters, why? I'm assuming you're not a complete plebian and are using MinGW-w64 to compile, so you should use -std=c11 to compile your code.
>>57226705
>It's not worth the money
Will you stop with this meme? Nobody here pays for Sublime Text.
http://appnee.com/sublime-text-3-universal-license-keys-collection-for-win-mac-linux/
There is literally a master key to activate the shit.
Now, as a free (as in beer, not freedom) editor, compare it to the others.
>>57226766
Pls, read the reply chain desu. I was specifically talking about reddit's tendencies to tell you to purchase a legitimate copy of sublime text. If you use it for free it's fine I'm really not talking about /g/ at all
>>57226766
>compare it to the others.
Good, not great, best combination of easy + powerful + not rendering your text in a mini browser
>>57226777
>reddit's tendencies to tell you to purchase a legitimate copy of sublime text
Why does Reddit do this? Do they also pay for Photoshop and Microsoft Office?
>>57226797
Yes, they really do. I don't know, they think it's morally right or something. What's morally right is not being charged $70 for a piece of software.
this is what a typical ruby developer looks like
OH MY FUCK WHAT AM I READING
https://github.com/dirtycow/dirtycow.github.io/blob/master/pokemon.c
>>57226803
The same site with /r/piracy and /r/trackers hosts these kinds of retards? Fugggg.
>>57226831
Yep, they claim it's "stealing". Never will I get my head around the fact that people unironically consider clicking a link and copying bit patterns somebody has claimed as $70 over to my bit pattern storage device as immoral. Illegal, yes, not immoral.
>>57226852
The quality of users on the Internet is constantly decreasing. It used to be everyone pirated, and we made fun of people who paid for things like music. Now everyone has a subscription to a streaming service.
>>57226705
i paid $45 or something like that for textmate a decade ago. that's been absolutely worth it to me
>>57226888
Normies, man. The internet is used by absolutely everyone and they've all been brought up around the concept of sharing, money and IRL markets. Can't jump the counter and steal a $12 coffee, better go find an alternative or whip out the wallet for fear of getting arrested. Once they've had that mindset implanted on them they never consider the ethical issues behind overcharging somebody, that computer programs are infinite resources and the viability behind obtaining software differently.
>>57226905
Could've gotten it for free and been even more worth it.
>>57226766
>neverending Sublime shills for the past 6 months
Why the actual FUCK would you use Sublime when vim/emacs exist. nu-/g/ kindly do us all a favor and fuck off back to upboat-land.
>>57226888
Checked
Also also yeah normalfags are technologically inept. Most people using the internet now are children and old people because they have the most time. Both demographics are fucking mentally retarded. The rest of the human scourge don't even use the web. They're just shitposting to each other on social media apps.
Discord bot /o/
>>57226920
>Why the actual FUCK would you use Sublime when vim/emacs exist
Editing text quickly and efficiently.
>>57227041
Thank God you're a tripfaggot. Filtered.
Also pic related.
>>57227041
In what way is sublime at all faster than using vim?
>>57226822
thats what the top half of europe looks like. Maybe I should've said northern. Would hate for them to get any ideas.
>>57227041
Both vim and emacs (especially emacs) provide all the functions of Sublime and more.
I don't understand, why doesn't make-house-nigger
work??(defclass subhuman ()
((iq :initarg :iq
:accessor smarts-of
:initform 30)))
(defclass nigger (subhuman)
((welfare :initarg :gibbs ; k units, i.e 40k
:accessor melon-affordability
:initform 90)))
(defun make-house-nigger (nog)
(with-slots (iq welfare) nigger
(incf iq 20)
(decf welfare 10)))
(defvar tyrone)
(setf tyrone
(make-instance 'nigger
:iq 45
:gibbs 40))
>>57227041
>Sublime
>faster/more efficient than vim
You're not even trying
>>57225113
a collection of definitions
>>57225269
have you tried the dot operator in place of the pointer call? I think the pointer gets locked to the string and hits segfault on the way to the function. Maybe you could make the element being added a const?
>>57227041
I still can't use vim or emacs efficiently. But to be honest I haven't given it a real try. Something about the efficacy of the movement throws me off because I don't have a hard time with regular notepadd+, amirite, at all.
>>57226580
The Scheme Programming Language by Kent Dybvig
>>57226580
don't listen to>>57227411
learn haskell instead
very intuitive and will make you feel like a god
learn c right after
When did you realize Swift 3 is the best programming language?
>>57227525
never
>>57227525
that's an interesting way of spelling Scheme
>>57227525
Please use English regardless of your country of origin. If it's good enough for Linus, it's good enough for you.
>>57227525
>using non-English variable names and comments
Stop that. The language you're writing in is in English. The majority of everything out there is English. Please for the sake of standardization and usability, write in English.
why doesnt java support multiple inheritance? creating modular shit needs nasty work-arounds because of this.
Anyone up? I'm giving up sleep to pass this lab I'm working on. Why the fuck does my android app keep passing a null value to the removeStudent?public class RemoveRecordActivity extends AppCompatActivity {
EditText idEditText;
//Create database connection object
DatabaseConnector dbc = new DatabaseConnector(this);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_remove_record);
//Create instances of the id field
idEditText = (EditText) findViewById(R.id.idEditText);
//Register listener with removeRecordButton
Button removeRecordButton = (Button) findViewById(R.id.removeRecordButton);
removeRecordButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Remove student record from database
dbc.removeStudent(idEditText.getText().toString());
finish();
}
});
}
}
>>57227869
because idEditText or the text in this class is null, duh
>>57227888
But why though senpai.
I put a number in the field when I run my app. Is android just retarded and doesn't realize it.
>>57227888
well to add getText() returns null else it would throw an exception on calling the method.
>>57227896
you know you can debug that shit in eclipse`?
>>57227901
Not until now.
Then again, I was shilled into using netbeans.
>>57227742
Because multiple inheritance is a bad idea in theory and practice. And Java's not alone. Most OO languages don't support it, including C#, Ruby, Python... Plus you don't really need it anyways. Interfaces do the job just fine.
>>57227742
use common lisp, it even lets you use arbitray amounts of specialized variables within a methods
and also, methods aren't tethered to a class
>>57227914
im sure netbeans can debug too. that's some really basic shit to know how to use a debugger
>>57227915
well I do need it now and interfaces wouldnt work in my case. so I just write a wrapper to simulate the modularity.
>>57227916
I dont think I will spend at least 1 year to master a new language and rewrite my whole 50k loc codebase in lisp because it would make it a little bit easier :^)
>>57227949
>I do need it now
Rethink your design pattern, because it's probably shitty.
>>57227962
Oh shoah, as if your shitty pattern cover my usecases
In C, I have this thing that allows you to add (register) function pointers to a list, and whenever a specified event happens, it iterates through the list and executes all the functions in the list
Is there a general name for this?
>>57227608
>FUCKING NORD NAZI!
Also, Hi Ruby!
>>57228246
an monad?
It isn't specific enough to be a monad, I don't think, hence the question mark.
>>57228246
I dunno I'd just call it event callbacks.
considering that old people over 25 are incredibly stupid with computers, doe sthat mean 100% job security for us?
>>57228150
I'm not suggesting any particular design pattern, just that you not come up with an idea that involves multiple inheritance.
>>57228247
Hello Anon. Are you ever going to say anything other than hi to me?
>>57228246
Callback functions.
https://github.com/blog/2262-github-s-game-jam-game-off-returns-next-month
>>57225015
prelude is the standard library that is automatically imported
>>57226766
only morons use sublime text
and all ruby users are morons
and only morons tripfag
and only the biggest moron would tripfag as a ruby user
>>57226026
nmap <Leader>x :%s/emotion[s]*//g
Press \x whenever you feel emotions.
>>57228710
>\x
>Not usinglet mapleader=" "
>>57227525
>using shitty Apple language
>contributing to the evilness of Apple
>using a Mac
>posting on /g/
If OOP has taught me anything, it's the value of not being dogmatic.
>>57227525
>coding in not english
Opinions disregarded.
I want to bring my daughter a bit into programming but on a more easy and creative level. I thought about the Arduino or Raspberry Pi. Do you recommend it? With the Arduino she can build blinking LEDs, etc. with using Java. Not sure what she could do with the Raspberry though.
>>57229294
Java (TM) (R) is the way to go. I'm sure you can buy some book from Oracle (R) Press.
Otherwise fuck her right in the pussy.
>>57229294
Two million LEDs to play with, right in front of her nose, isn't enough?
>>57229294
Good taste anon. Torturing your loli with Java really is a good idea.
>>57229294
Girls hate programming though
>>57229463
Only most of them. That's kind of true for most boys too, though.
take 10 [(a,b,c)|c<-[1..], b<-[1..], a<-[1..], a^2+b^2==c^2, sum [a,b,c] == 24]
i think i messed up
>>57229512
Girls have waaaay less interest in shit like programming, engineering, building etc than men.
>>57229531
Again: True, but only true as a generality.
There exist lots of girls who are interested in shit like that, and nurture can only increase that number, when people grow up not feeling that their gender has to have anything to do with their interests.
Gah, my WebGL program isn't drawing anything, and I can't fathom what's wrong.
There's a decent amount of error checking in the code but it's reporting nothing.
Though my vertex shader is literally just:in vec4 vertexPosition;
void main() {
gl_Position = vertexPosition;
}
And the coordinates of the triangle vertices I'm trying to render are:
0.0, 1.0, 0.0,
-1.0, -1.0, 0.0,
1.0, -1.0, 0.0
Dunno if there's anything wrong with that.
>>57229577
>but only true as a generality.
well what else would I mean?
>when people grow up not feeling that their gender has to have anything to do with their interests.
Will never happen because it's anti science.
Of course you're girl might become interested in programming, but I wouldn't expect it to be very likely.
>>57229604
>>Will never happen because it's anti science.
>this simplistic view of science
How's high school treatin' ya'?
>>57225633
I don't know if you have serious depression but I've been diagnosed with it and it's very hard to program. I have no motivation for it and I can't concentrate on anything at all. I only program very small things if I program anything. Sucks
learnyouahaskell
>Functions also have types. When writing our own functions, we can choose to give them an explicit type declaration. This is generally considered to be good practice except when writing very short functions.
Do function declaration do anything besides making code more human readable?
I have the following situation in C++:class D { };
class C {
virtual D* f() = 0;
virtual void g(D*) = 0;
};
void f(C* c) {
auto d = c->f();
c->g(d);
}
C and D are interfaces. What's the correct way for C::g to cast the argument to its implementation of D? Should I use dynamic_cast for this?
>>57229775
I feel you man. I've been fighting this shit for longer than I can remember and I used to love coding. Now it's a hassle more than anything.
>>57225633
>>57229775
daisuki~
>>57224975
>What are you working on /g/?
Discovering the deepest, darkest corners of Racket.
>>57224975
Thank your for using an anime image.
>>57230149
If i understand your question: that's what virtual functions do for you automatically.
>>57230179
Do you go to a therapist? You probably should if you don't. I'm going to get inpatient treatment soon, I hope it will help.
>>57230278
Virtual functions only work for one object.
>>57230314
I do, actually. I'm taking some shit and see someone twice a week. Doesn't do a lot for me but it might help eventually.
>>57230361
Then i don't understand the question.
>>57230240
>Racket
I didn't even know about this meme
>>57224975
I'm working on some database with a node.js backend api. I fucking hate programming for the web so I suck at node.js.
However, I'm pretty good at swift.import Alamofire
//Get item by barcode
fileprivate func getItem(barcode: String)
{
if let url = URL(string: "REDACTED")
{
let headers: HTTPHeader = ["Auth" : User.sharedInstance.token]
Alamofire.request(url, method: .get, parameters: nil, headers: headers)
.responseJSON{ (response) in
print(response)
}
}
}
kill me /g/
>>57230388
Really? it's a well know programming language among lispers and teachers (htdp)
print(0.99999999999999999 == 1.0) # True
What did he mean by this?
>>57230541
https://en.wikipedia.org/wiki/Floating_point#Machine_precision_and_backward_error_analysis
Do you jerk off in the morning before you program??
>>57225633
Not very well desu senpai. It usually ends up with me not doing a lot of programming at all. I've been putting off getting a job because of it.
>>57230149class D {
public:
virtual const void *id() = 0;
virtual ~D() = 0;
};
class C {
public:
virtual D* f() = 0;
virtual void g(D*) = 0;
virtual ~C() = 0;
};
class DImpl : public D {
const void* id() override {
return &id_;
}
static DImpl* from_d(D* d) {
assert(d->id() == &id_);
return static_cast<DImpl*>(d);
}
static const char id_;
friend class CImpl;
};
class CImpl : public C {
public:
D* f() override {
return new DImpl;
}
void g(D* d_) override {
auto d = DImpl::from_d(d_);
(void)d;
}
};
void f(C* c) {
auto d = c->f();
c->g(d);
}
>>57230581
I masturbate about 5 times a day, so yes.
when you dream in code do you dream in oop or fp?
>>57230679
Neither, just normal, procedural programming.
>>57230679
depends
when im lucid dreaming its definitely not fp due to the side effects my actions have
>>57230679
I dream in Japanese, it's the best programming language for creating waifu bots.
would girls be attracted to me if they saw me coding in Haskell on the train to school?
>>57230679
>oop and fp are exclusive
confirmed for cs101 kiddo.
>supposed to do a group project in pairs
>meet my pair today
>he already has everything done in a way more efficient way than we were supposed to do it
what do? I feel so useless
>>57225285
cuteee
>>57231213
tfw wrong pic
>>57231144
let him get you pregnant so you can ride his coattail
>>57231144
Look at it as a golden opportunity to get him to explain everything and suck his knowledge.
Rewrite everything from scratch if need be, as long as there's time, to make sure you really understand everything that's going on and get the full benefit of the project.
Sucks to be him, i guess, but that's the burden of the smart. If he's not a total dick, he will help you, as long as you show a willingness to learn.
>>57227915
>Interfaces do the job just fine
What if I want to inherit from multiple interfaces?
>>57230794
yes
libgdx has a Gdx class that allows static access to the relevant parts of the backend.
so like Gdx.graphics.something()
in the comments it is written
>This is normally a design faux pas but in this case is better than the alternatives.
why is this a faux pas and what are the alternatives?
Hey, Haskell is pretty fun!
>>57230794
No
But leg shaving crossdressers would.
Give me O N E reason why I should use raw pointers and notauto variable = make_shared<int>(12)
>>57231450
You shouldn't unless you need to pass something to a C function.
However, consider using unique_ptr instead of excessive use of shared_ptr.
>>57231450
>make_shared<int>
just fuck my shit up
What's the best way to do flexible array members in C++?
>>57231481
>flexible array
Vector?
>>57231488
no. use google.
>>57231481
>>57231498
C++ does not have flexible array members, and desu most C compilers will nag as crazy as well.
>>57231498
use vector
>>57231498
>>57231488
But anon is correct, use a vector instead. That's what they are for.
>>57231527
Just stfu if you have nothing to contribute. The point of flexible array members is to avoid excessive indirection and allocation and you're telling me to add at least 24 useless bytes to my type + indirection? Have you lost it?
>>57231481
What's that?
>>57231558
I'm telling you that C++ doesn't have flexible arrays, now deal with it by using vectors or risk having nasal demons fly out your nose by relying on undefined behaviour.
KYS
>>57231558
>24 useless bytes
>implying your struct isn't padded to fit alignment anyway
>>57231564typedef struct {
size_t length;
char characters[ ]; // no length
} string_t;
Imagine how many billions of bytes and seconds have been wasted on \0
>>57231611
So an std::array?
>>57231628
std::array is fixed size IIRC
>>57231627
Imagine how many billions of bytes and seconds have been wasted on porn
>>57231627
Imagine how many buffer overflows we could have prevented by not relying on terminating ASCII NILs.
>>57231638
Yes. If that doesn't work for you, then std::vector.
>>57231481
Alright I'll just use flexible array members which both GCC and Clang support as an extension. Much rejoicing.
>>57231644
>wasted
>>57231644
Imagine how many dollars and seconds were wasted on you.
your parents had such high hope.
>>57231660
Non-portable pig disgusting
>>57231672
only a redditor would be this rude
>>57231675
C++ isn't portable to platforms that don't have a C++ compiler.
>>57231672
E'rry day, Anon. E'rry day.
>>57231687
And?
>relying on specific compiler behaviour is portable
>>57231687
chigau yo
>>57231687
There aren't even any C++14 compilers besides clang and gcc.
>inb4 msvc
msvc doesn't even have full C++98 support let alone C++11 or C++14.
>>57231640
yes
>>57231685
only a normie would get offended by that
>>57231732
pretty sure neither clang nor GCC fully support c++ 11
>>57231732
What? I thought vc140 had full C++11 support.
>>57231749
pretty sure you're wrong
https://gcc.gnu.org/projects/cxx-status.html#cxx11
http://clang.llvm.org/cxx_status.html
>>57231749
>Clang 3.4 and later implement all of the ISO C++ 2014 standard.
http://clang.llvm.org/cxx_status.html
>>57231749
>GCC 4.8.1 was the first feature-complete implementation of the 2011 C++ standard
https://gcc.gnu.org/projects/cxx-status.html#cxx11
>>57231769
wow
sucks to be them
>>57231732
>msvc doesn't even have full C++98 support let alone C++11 or C++14.
Actually, both C++98 and C++11 status are complete according to Microsoft.
>>57231757
It has, anon is a nigger.
>>57231769
>4.8.1
But C++11 regex didn't come until GCC 5.1.0
>>57225269
>using C in C++
negro
>>57231837
You can't use C++ without using C
You can't even spell C++
>>57231813
https://youtu.be/MBmp1gxCu9k?t=8m6s
>>57231859
https://msdn.microsoft.com/en-us/library/hh567368.aspx
?
>>57231887
>Visual C++ implements the vast majority of features in the C++11 core language specification
for some definition of vast majority
Optimised file upload on my imageboard. Instead of simply uploading the file it first computes a SHA1 hash and sends that to the server. If the server finds that it already has that file uploaded, it sends the client back a new allocation token. The client uses that to allocate the image. If not, the client then uploads the file for processing as per usual.
Because all files are stored by their SHA1 hash and no file is ever thumbnailed or stored twice, this means that uploading an already thumbnailed file is practically instant.
>>57231930
well done anon
>>57231904
Everything but "Expression SFINAE" is implemented, which is a proposal/optional feature and not part of mandatory C++11
?
>>57231855
see plus plus
fite me
>>57231952
No-speaky-spanish-pablo
>>57227525
Libgdx is more versatile
Has anyone here used Bullet Physics? I'm not getting it to work, and I'm beginning to think that I've misunderstood something.
Here is my code:// Initiate Bullet
btDefaultCollisionConfiguration *collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher *dispatcher = new btCollisionDispatcher(collisionConfiguration);
btBroadphaseInterface *overlappingPairCache = new btDbvtBroadphase();
btSequentialImpulseConstraintSolver *solver = new btSequentialImpulseConstraintSolver();
btDiscreteDynamicsWorld *dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0,-10,0));
// Create a collision sphere at -20,0,0
btCollisionShape *collisionShape = new btSphereShape(2.0f);
btDefaultMotionState *motionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,0), btVector3(-20, 0, 0)));
btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(0, motionState, collisionShape, btVector3(0,0,0));
btRigidBody *rigidBody = new btRigidBody(rigidBodyCI);
dynamicsWorld->addRigidBody(rigidBody);
// Test for collisions using a ray from 0,0,0 to -30,0,0
btCollisionWorld::ClosestRayResultCallback RayCallback(btVector3(0,0,0), btVector3(-30, 0, 0));
dynamicsWorld->rayTest(btVector3(0,0,0), btVector3(-30, 0, 0), RayCallback);
if(RayCallback.hasHit())
std::cout << "Hit!\n";
else
std::cout << "Miss!\n";
Why does this code not cause a collision? Am I misunderstanding something?
>>57232023
lel
>>57232023
No. All physics engines are shit. Fuck physics.
>>57232044
>Fuck physics.
>>57232023
>new
how nasty
>>57232023
your timestep looks wrong
>>57232044
Why?
>>57232023
>OOP
>>57231930
Have you considered going for SHA2 or SHA3?
Still, very nice!
>>57232064
Post traumatic stress from having worked with and on real time physics at school.
I am so fucking amazed by and jealous of anyone who gets it even remotely passably right.
>>57232089
I would be using MD5, but SHA-1 is still very standard and has less collision chance. The problem with higher algorithms is of course the computation speed. Even with optimisations and asm.js SHA-1 hashing a 15 MB file produces a noticeable stutter.
>>57232169
Are you sure that's because of the algorithm, and not because of loading in the file?
>>57225285
Kinda want to see the source famalam
Fuck it, I'm writing my own ray picker.
>>57232198
Loading the file might have an influence, but changing to a more optimised SHA1 hash function brought down the stutter by a few seconds and it is tolerable now. So most of the load is likely from the hashing. Mind, it is still Javascript.
>>57230635
David, is that you?
what is it that makes python so disgusting
>>57232265
Semantic whitespace
private Scanner input = new Scanner(System.in);
String name = null;
while (name == null)
{
while(!input.hasNext())
{
// waits for input
}
name = input.nextLine();
}
Why doesn't this work? it just doesn't doesn't take any input.
And if I remove the waiting loop it just skips any input
I'm using Java btw
>>57231930
>>57232089
>>57232169
http://stackoverflow.com/questions/998662/what-is-image-hashing-used-for
>>57232550
file hash != perceptual hash
>>57232577
I know. Image hashing is better
>>57232481
Show us your code when you "remove the waiting loop", because input.nextLine() will wait for input anyway. while (name == null) seems unnecessary since "blank" input will return an empty string which isn't null.
>>57232481
1. i don't understand why you're using private
2. if you get rid of all the loops and just write name = input.nextLine(). doesn't that work?
>>57232588
Are you buttfuck retarded? They serve two different purposes. File hashes like SHA-1 are used to find exact matches, while perceptual hashes are used to find near matches for purposes like spam prevention and image search.
>>57232627
I know. Image hashing is better
>>57232639
Okay, tard.
>>57232648
I know. Image hashing is better
>>57232614
Problem is it doesn't wait for input. I remove the loop now because it indeed seems dumb. I thought it'd wait for input then stop the loop when the user inputs input.
>>57232625
1: Because I don't need it accessible from outside the class
2: if I do that I get java.util.NoSuchElementException: No line found
>>57232481Scanner input = new Scanner(System.in);
String name = input.nextLine();
>>57232658
Okay, tard.
>>57232669
I get java.util.NoSuchElementException: No line found
>>57232668
>1: Because I don't need it accessible from outside the class
They mean fields are private by default, and variables (as in declared in a function) are not even visible outside of that function
>>57232679
How are you running your program? Sounds like a dumb IDE that doesn't know how to pop up a console window when reading standard input.
Is forking the same as threading, or is it a threading knock-off
>>57232719
No
No
>>57232711
>variables (as in declared in a function) are not even visible outside of that function
Oh right I forgot, well I removed private now.
I am running it on Eclipse Neon
>>57232719
Forking creates a new process. Threading does not.
>>57232719
Is your google broken?
>>57232668
it's still unclear to me -- where is input declared? pastebin the whole thing if you can. if you use the two lines >>57232669 wrote it definitely works, so there's some weirdness here
i'm not a java person
>>57225352
Hey friend. It's good to see beginners who are actually interested in learning. Your code is fine, does the job. Mastery comes with practice.
http://pastebin.com/GufJKq7w
Heres some quick refactoring I did on your code.
Now obviously you could do some fancier gimmicks and optimize this code even further, but I just quickly improved what caught my eye
>>57232765
>>57232730
It's his IDE, it doesn't open a console window to let him provide input.
Possibly the fix:
http://stackoverflow.com/questions/22470841/java-scanner-not-working-on-eclipse
>>57232765
I've seemed to fix it, apparently the if you close one Scanner you close all future Scanners as well.
Which is pretty weird in my opninion
>>57232785
This is why you use the command line when writing command line based programs.
>>57232785
i wonder whether you're sharing one scanner between all instances
>>57224975
can someone explain why this isn't working? PS doesn't work with any of the urls ive trieduse strict;
use warnings;
use LWP::Simple;
sub main{
print "downloading...\n";
print get("https://en.wikipedia.org/wiki/Main_Page");
print "Finished..\n";
}
main();
Output:
PS C:\Users\me\Documents> perl .\helloWorld.pl
downloading...
Use of uninitialized value in print at .\helloWorld.pl line 6.
Finished..
>>57232785
Well if you create a scanner named Asshole and then invoke Asshole.close() somewhere along the line, yeah you cant put a dick in Asshole anymore.
>>57232904my $content = get("link");
print $content;
>>57232948
tried that, still get the same error
>>57232963
getprint("link");
>>57232904
works on my machine la
Can someone tell me the point of exceptions?
I never liked them. They're such a pain to use and there are other ways of validating/error handling than throwing an exception.
They also making the program flow harder to read and unrolling the stack just makes it harder to find where the problem originated.
>>57232963
or..#!/usr/bin/perl
use warnings;
use strict;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my $response = $ua->get('http://www.google.ca');
if ($response->is_success) {
print $response->decoded_content;
}
Simple a shit.
>>57232904
Pretty odd, since it prints what's in line 6
>>57233016
They're the easiest way to handle errors, I agree the syntax usually complicates it though
>>57233042
Can someone make a new thread now?
>>57232996
>>57233029
>>57232998
>>57233042
Im on windows 10, seems like for some reason the path for perl isn't correct. I have no idea why it's gong to the Virtual User Generator folder as i just installed perl and have only done like hello world so far501 Can't load 'C:/Program Files (x86)/HP/Virtual User Generator/strawberry-perl/perl/vendor/lib/auto/Crypt/SSLeay/SSLeay.dll' for module Crypt::SSLeay: load_file:The specified module could not be found (Crypt::SSLeay or IO::Socket::SSL not installed) <URL:https://en.wikipedia.org/wiki/Main_Page>
>>57231558
You realise that behind the scenes there's going to have to be some sort of dynamic allocation for that type of stuff to happen, right? Either you implement such a system yourself or use vectors.
If there is a "best" way performance-wise, I can think of not much else but templates, but storage of such objects, if many, will be problematic.
>>57233060
LWP::Simple won't do https I don't think for one.
You also don't have Crypt::SSLeay.
Look at installed cpan, then with cpan you can just do 'cpan install Crypt::SSLeay'
or whatever other module.
Is there an easier way to write this?
Structured it this way to allow diagonal movement and allow you to press multiple keys to cancel out movement
I know it looks bad but this was the onlly way I could do itif (keyState.IsKeyDown(Keys.A) != keyState.IsKeyDown(Keys.D))
{
if (keyState.IsKeyDown(Keys.A))
{
if (keyState.IsKeyDown(Keys.W))
{
DX = velocity * (float)Math.Sin(rotation.Y + Math.PI / 4);
DZ = velocity * (float)Math.Cos(rotation.Y + Math.PI / 4);
}
else if (keyState.IsKeyDown(Keys.S))
{
DX = -velocity * (float)Math.Sin(rotation.Y - Math.PI / 4);
DZ = -velocity * (float)Math.Cos(rotation.Y - Math.PI / 4);
}
else {
DX = velocity * (float)Math.Sin(rotation.Y + Math.PI / 2);
DZ = velocity * (float)Math.Cos(rotation.Y + Math.PI / 2);
}
}
else
{
if (keyState.IsKeyDown(Keys.W))
{
DX = velocity * (float)Math.Sin(rotation.Y - Math.PI / 4);
DZ = velocity * (float)Math.Cos(rotation.Y - Math.PI / 4);
}
else if (keyState.IsKeyDown(Keys.S))
{
DX = -velocity * (float)Math.Sin(rotation.Y + Math.PI / 4);
DZ = -velocity * (float)Math.Cos(rotation.Y + Math.PI / 4);
}
else
{
DX = velocity * (float)Math.Sin(rotation.Y - Math.PI / 2);
DZ = velocity * (float)Math.Cos(rotation.Y - Math.PI / 2);
}
}
}
else if (keyState.IsKeyDown(Keys.W) != keyState.IsKeyDown(Keys.S))
{
if (keyState.IsKeyDown(Keys.W))
{
DX = velocity * (float)Math.Sin(rotation.Y);
DZ = velocity * (float)Math.Cos(rotation.Y);
}
else
{
DX = -velocity * (float)Math.Sin(rotation.Y);
DZ = -velocity * (float)Math.Cos(rotation.Y);
}
}
lucky :: (Integral a) => a -> String
lucky 7 = "LUCKY NUMBER SEVEN!"
lucky x = "Sorry, you're out of luck, pal!"
Can i write this function directly in the interactive interpreter instead of write it in a file an load that? How?
>>57233086
ghol,y fucking dicks pls not be srs
>>57233311
use :{ to begin a multi line input
and :} to terminate it
e.g.
:{ ENTER
...
:} ENTER
>>57233311
Oh, and LYAH is slightly out of date, so you'll actually also need Eq (because you're checking if a number is equal to 7), previously all Integrals would be Eq
>>57233383
How do you mean?
>>57233447
lucky :: (Integral a, Eq a) => a -> String
>>57233369
well IDK mate it works properly and ignores opposite movement I just don't know how to do it any more uniformly
>>57233479
i'll give you a hint -1 +1 equals 0
>>57233463
Seems to work either way. Even seems to work without the type declaration at all. Why do i need that?
>>57233559
You don't need the type declaration because it can infer it. I'm surprised it works without Eq though
>>57233571
Do you know why this workslucky 7 = "LUCKY NUMBER SEVEN!"
lucky x = "Sorry, you're out of luck, pal!"
but this doesn'tlucky x = "Sorry, you're out of luck, pal!"
lucky 7 = "LUCKY NUMBER SEVEN!"
>>57233613
When you do a series of pattern matches, it attempts them in order. It's not just "which is more specific".
x matches everything
>>57233622
Oh, ok. Thanks.
>>57233631
Since you don't actually use x, you can use the wildcard _
This is like matching everything, but without giving it a name
lucky 7 = "LUCKY NUMBER SEVEN!"
lucky _ = "Sorry, you're out of luck, pal!"
>>57233652
cool.
>>57233622
Ha, i continued reading, and literally the next thing he said was this.
>>57233559
You don't need the type declaration, but sometimes you do, especially if the compiler infers a type you didn't intend.
Always write your fucking type declaratios. That will make your code more readable.
>>57230679
I dream in untyped lambda calculus.
>>57231000
oop and fp ARE exclusive
cs001 toddlers will disagree
>>57234445
Wrong. Pretty much everything in OOP is encapsulated FP.
>>57235181
except for all of it