Anime Forever Edition
Previous - What are you working on, Sup Forums?
/dpt/ - Daily Programming Thread
Other urls found in this thread:
en.wikipedia.org
en.wikipedia.org
twitter.com
MSWLogo is literally the best lisp
I can't get the listener to fire at all. I have the fragment inside a ViewPager on an activity and there's also a custom View for a navigation drawer on top of them. None of them seem to be consuming the click though, so I'm pretty lost here.
First for D
First for D
>apply for job at this research institute with this awesome project
>get job
>now find out that after 10 years of work nothing of note has come out of it and people are still discussing how to design the self made metamodel because UML is for little kids and we HAVE to make our own
Kill me
I know there are a lot of learners lurking here.
Been studying Python for a series of months now.
Been going through Zelle's Python Programming book and some Code Wars.
Interested in moving to the next level.
Looking for people interested in some
collaborative studying- let's make it vigorous- hit me up at [email protected]
what's the resulting assembly look like?
Quick! post some trick/tip you know in a programming language.
Example:
in C : array[10] is the same as 10[array] .
share your tips and tricks!
I don't know, but you could instead create the entire output string at compile time and it'd just be one writeln
...
how do I differentiate between a method and an attribute if there's no () to methods?
Thank you for using an anime image.
When I get home from my menial job, I'm going to read through the Scrapy documentation & write a Danbooru scraper in Python. Two more weeks in this hellhole, then I can finally quit & start my internship...We're all gonna make it...
that's not lisp you fucking mongol
You write an unnecessary (), or use __traits(...), or don't in the case of @attribute fields
It's a lisp
in C, 10[array] is the same as 10
yes its true. but what's the purpose?
#include
int main()
{
int array[9] = {1,2,3,4,5,6,7,8,99};
printf("%d\n", 5);
return 0;
}
a.c:7:19: error: expected expression before ‘:’ token
So I need to know the implementation details of a class just to know whether something is a call that can have side-effects or a value copy that generally doesn't have side-effects?
is ]
/*"$4*/{ is {
compile with trigraphs on
You can check for the pure attribute
its must be the pedantic flag
cc a.c -Wall -ansi -pedantic
It's an imperative language
I'm doing some small coding tasks and problems in C, mostly concerning the standard C library, system calls, threads processes and so on. This is one of the rare few courses I had that assert is used. I know what is that, and what do I use it for in a program, but is there a general rule of thumb when should I use assertions or simply check for errors myself?
That doesn't have anything to do with knowing whether a part of a program has side effects.
Did your CS classes even cover Ada or PL/I, not to mention some more obscure languages?
All parts of a program have a side effect on the registers and the cache
at work we kinda do both. we use an assert macro as an if block, and that block is evaluated only if assert is true
y = 0;
safe_assert ( x > 0 )
{
y /= x;
}
kinda like this. if x is not positive, it gives an assert warning and does not execute division by zero.
not sure if this is necessary though. it is too much of an hassle and you should fix asserts anyway.
this could be done with a monad
What's a monad?
Special snowflake's try/catch.
>imperative programmers actually believe this
>don't realise try/catch is a special snowflake's instance of a monad
return :: a -> M a
fmap :: (a -> b) -> (M a -> M b)
join :: M M a -> M a
I programed in both java and c++. To this day I'm still not sure what try catch blocks are used for .
Sucks to be retarded.
Sucks to be a cunt
...?
...!?
:^)
what
exactly what I said
they are a great way change control flow
try
{
bla bla bla
bla
if (bla)
throw BlaBlaHapenedException;
} catch (BlaBlaHapenedException e) {
do more bla bla
}
pretty clean and you didn't use evil goto s!
Well I think I used it in java only, can't remeber for what though. I mean it looks like an extra precaution if some function or whatever misbehaves, but why complicate things? C doesn't something like that, why would java and c++ have something like that?
kys
So, it's used because instead of getting a fatal error that shuts the program down, you can allow it to continue working?
But then that error doesn't seem that fatal, so why not a regular bunch of if else statements?
In Java you're forced to catch exceptions that do not inherit RuntimeException. It's a way of error handling. C normally uses error codes for that (which is cleaner IMO).
>guy arguing that Rust was right to rename "Either" to "Result" because "Either is an abysmal API"
Proper return types are better than error codes
If you're using C, use an enum for your errors
On the matter of Either, I'd actually say it should be renamed on the basis that Haskell gives it various left biased operators that don't really make sense in an "Either" type
That's only because of currying at the type constructor level, which forces things like Functor, Monad, etc. to work with the final type parameter (without a newtype mess).
Is there no Flip type for Haskell(+GHC)?
That would fall under "newtype mess".
So I created something I think is worth sharing. What do I do?
Share it
Share it
Which one of us got dubs?
The problem is the lack of gradual or dependent typing
Trying to teach myself python by making a game. I'm trying to turn a dead/surrendered monster into an item you can pick up and put into your inventory but I keep getting this error
File "C:\Users\PC\Desktop\python\roguelike.py", line 330, in pick_up
inventory.append(self.owner)
AttributeError: Item instance has no attribute 'owner'
I thought owner is already defined.
elif choice > 1:
message('The ' + monster.name +' has surrendered! ' + 'You gain ' + str(monster.fighter.xp) + ' experience points and ' + str(monster.fighter.gold) + ' gold', libtcod.orange)
monster.char = '*'
monster.color = libtcod.dark_red
monster.blocks = False
monster.fighter = None
monster.ai = None
monster.item = Item()
monster.name = 'A surrendering ' + monster.name
monster.send_to_back()
class Item:
#an item that can be picked up and used.
def __init__(self, use_function=None):
self.use_function = use_function
def pick_up(self):
#add to the player's inventory and remove from the map
if len(inventory) >= 26:
message('Your inventory is full, cannot pick up ' + self.owner.name + '.', libtcod.red)
else:
inventory.append(self.owner)
objects.remove(self.owner)
message('You picked up a ' + self.owner.name + '!', libtcod.green)
#special case: automatically equip, if the corresponding equipment slot is unused
equipment = self.owner.equipment
if equipment and get_equipped_in_slot(equipment.slot) is None:
equipment.equip()
along with setjmp and longjmp
Any android developers lurking here?
Wanted to ask something about data persistence.
>I prefer silent undefined behavior
Thanks DPT
were? not a single person on shithub even viewed it
I don't see it defined anywhere.
The __init__ method is the constructor where object attributes get defined. The only attribute that Item seems to have is "use_function".
It doesn't have an owner, as far as i can see.
A monad has a type constructor M t (t is a type parameter)
A monad defines three operations
return :: t -> M t
fmap :: (a -> b) -> (M a -> M b)
join :: M M a -> M a
An alternative implementation
return :: t -> M t
bind :: (a -> M b) -> (M a -> M b)
I'm reading up on the exception system in Java. for some reason it isn't as complicated as I remember. Maybe I didn't pay attention the first time, maybe we didn't give it nough attention in the practical classes.
I do have a question though. Lets say i make a new exception, What does it need to inherit?
Also, let's say I make a method of a a class I made throw that exception. Does it mean that the program automatically aborts? Which exceptions abort the program, and which do not?
The Item class doesn't have 'owner' defined, you could define it like this depending on how it works:
class Item:
#an item that can be picked up and used.
def __init__(self, owner ,use_function=None):
self.use_function = use_function
self.owner = owner
>new exception, What does it need to inherit?
You should extend Exception.
>Does it mean that the program automatically aborts?
yes, if you do not catch the exception, your program will crash
>Which exceptions abort the program, and which do not?
any uncaught exception will abort your program
I'm not looking for a lib to bind my sepple code in JS, I'm looking for a lib that enables a program in JS or sepples to perform binary analysis on a raw binary, like IDA or radare, but I want to write a perform that automates a certain kind of analysis.
>openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 3650
>panic: crypto/tls: failed to parse private key
REEEEEEEEEEEEEEE
What am I doing wrong?
you can also extend RuntimeException, which does not need to be caught to compile but will crash the program all the same
you can also extend Throwable so people who try to catch your exceptions with catch (Exception e) get rekd
Trying to assign any more meaning to a monad is laughable.
That's great, that means that I can catch an exception and continue running the program? If so, how do I make it stop running in the catch block?
Are your key/cert decrypted and do they follow the following structure?
key.pem:
-----BEGIN RSA PRIVATE KEY-----
... key ...
-----END RSA PRIVATE KEY-----
cert.crt:
-----BEGIN CERTIFICATE-----
... root ...
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
... intermediate ca ...
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
... your cert ...
-----END CERTIFICATE-----
There's loads of guides for Go crypto/tls, by the way.
JS is terrible at handling binary data. Sure, there are typed arrays and Node's Buffer(), but I would still not use them for anything, given a choice.
Best Book for learning embedded programming on Atmel chips?
>anime
Cringe
Well, technically there's more meaning than just those operations; there's laws to be upheld, too.
return a >>= f = f a
m >>= return = m
(m >>= f) >>= g = m >>= (f >=> g)
Where (>=>) is Kleisli composition:
(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c
f >=> g = \a -> f a >>= g
It's difficult to write a Monad implementation that breaks these laws unless you're really abusing the interface.
In C, how would you create a macro to zero an array that compiles with the most strict flags (-Wall -Wextra -Werror -ansi -pedantic)?
That means you can't mix variable declarations and code (including variable declarations inside a for-loop), let's also assume you can't use the standard library (no memset etc.). The only "solution" I have is with inline assembly, but that feels wrong as it's not strictly C (even though it compiles and works fine).
what do you mean?
So I found & fixed a small bug in an open source project. Should I open an issue ticket first or just commit it?
r8 my monad
>inb4 muh laws
The way I understood is that uncaught exceptions of any kind automatically terminate the program, but if caught you can choose whether to terminate the program, or do some other action, correct?
Maybe you should fork the project with the bug fix and then request a merge.
all of my items are working, can pick them up and use them. I'm only getting trouble trying to turn the monsters into items on death
it glitches out when I try this making the player show up every tile they pass through
I switch to a compiler with newer standard that allows me to declare variable in loops
If not I would implement memset_zero function and call that in macro
cert.pem:
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
key.pem:
-----BEGIN ENCRYPTED PRIVATE KEY-----
...
-----END ENCRYPTED PRIVATE KEY-----
having a bit of a problem with c++ here. currently learning classes and dynamic arrays.
class tut{
int size;
int* dynarray;
public:
tut(int size=0) {
this->size=size;
dynarray=new int[size];
for (int i=0;i
See, your key is encrypted, no wonder crypto/tls can't read it.
Decrypt it.
Thanks senpai. I got it working by not encrypting the key like this:
openssl req -x509 -nodes -newkey rsa:4096 -keyout key.pem -out cert.pem -days 3650
your copy constructor creates an 'array' of 1 element.
Yeah. For example, you might be conducting a multi-step, error prone process. If an error occurs at any time, you want to roll back to a safe state, tell the user what hapened, or anything else.
try {
// error prone stuff below
openUpThePatient();
removeHeart();
addNewHeart();
sewBackPatientUp();
} catch (Exception e) {
// error recovery
Doctor.out.println("Fucked that one up!");
putOriginalHeartBackIn();
sewPatientBackUp();
notifyMortician();
}
rollPatientOutOfRoom();
Doctor.out.println("Surgery Finished");
if addNewHeart throws a HeartNotFound exception, everything in the catch block will execute. Then, everything after the catch block will execute. (Note that if rollPatientOutOfRoom() is error prone, you may need to put it in its own try-catch)
D E V I L I S H
E
V
I
L
I
S
H
Going through binary, the hexadecimal. Going to write a program that converts hex to decimal.
Hides which functions throw an exception and which don't, though.
In (imperative) languages where try-catch is considered good style it's often incredibly annoying to trace error related behaviour when the stack trace wasn't logged.
How would I terminate the program in that catch block? How do I in general force a termination of a program in a catch block?
Rethrow it as a RuntimeException.
Does someone know a good tutorial on how to learn to code in the windows "Command Prompt" ?
how stupid.
thank you!
System.exit(1) will do it.
This will work if you dont catch the runtime exception elsewhere
?? how you terminate your program depends on how you programmed it?
program execution (main thread & deamons) stops when you reach the end of the main() body, how you get there is up to you. or you can force exit the main thread with System.exit()
You don't force termination. You rethrow, which will allow higher callers to potentially recatch.