[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: 31
File: K&R himegoto waifux2.png (1 MB, 1000x1400) Image search: [Google]
K&R himegoto waifux2.png
1 MB, 1000x1400
old thread: >>54980467

What are you working on, /g/?
>>
File: 26375861581.png (75 KB, 430x546) Image search: [Google]
26375861581.png
75 KB, 430x546
First for union types are retarded
>>
>>54987899
C/C++ unions? or type theory sum types?
>>
I'm writing a userscript to autoplay gifs and webms.
My problem is getting webms to expand correctly, if you click on them, the thumbnail disappears and the 4chan extension's ImageExpansion functions don't trigger as they should.

function autoplay_images()
{
var imgs = document.getElementsByClassName("fileThumb");
for (var i = 0; i < imgs.length; i++)
{
if (imgs[i].href.indexOf(".gif") > -1) /* GIF */
imgs[i].firstChild.src = imgs[i].href;
if (imgs[i].href.indexOf(".webm") > -1) /* WEBM */
{
var thumb = imgs[i].firstChild;
var webm = document.createElement('video');
webm.setAttribute('src', imgs[i].href);
webm.setAttribute('poster', thumb.src);
webm.setAttribute('style', thumb.style.cssText);
webm.setAttribute('autoplay', 'true');
webm.setAttribute('loop', 'true');
webm.setAttribute('preload', 'auto');
webm.onclick = function() {
window.open(webm.src);
};
imgs[i].replaceChild(webm, thumb);
}
}
}

autoplay_images();
>>
>>54987933
Both
Java doesn't have either
>>
/dpt/

Shit flinging discussions on pooo in the loo languages.

/wdg/

Comfy discussions on white languages and frameworks.
>>
>>54987866
first for Rust
>>
>car broke down
>no jobo
>roommate out of town for the next two weeks

What should I work on guys? I need something to stay sane.
>>
>>54987866
8th for Go is awesome.

>>54988054
is Rust THIS slow?
>>
>>54988043
red pill me on F# for web development
>>
How can I reference null in java in an if statement, I've done something similar in C trying it out in Java.

 if(ch5_body_1.contains(ch5_Swap_Name+"_"+ch5_Swap_No) != null)
>>
>>54988208
null
>>
>>54988300
>>54988208
Giving me an error when I compile saying that -
>the operator != is undefined due to argument types
>>
>>54988358
You're comparing boolean and null
>>
in Java a boolean has three states
true, false, null
>>
GRAPHICS PROGRAMMING AND OPEN GL ARE
SO
FUCKING
BORING!
>>
>>54988461
>>54988405
>>54988358
>>54988300
I tried doing this giving me an error can't figure out why pls halp
 Boolean set = null;
if(ch5_body_1.contains(ch5_Swap_Name+"_"+ch5_Swap_No) != set)
>>
>>54988578
learn dx12 with frank luna :^)
>>
>>54988578
OpenGL is quite comfy if you know what you're doing.
You clearly don't however.
>>
>>54988598
if(ch5_body_1.contains(ch5_Swap_Name+"_"+ch5_Swap_No))
>>
Learning Rust at the moment
>>
>>54988681
Why?
>>
File: 1451340571525.jpg (49 KB, 300x498) Image search: [Google]
1451340571525.jpg
49 KB, 300x498
/dpt/ I have a a question, I don't know the terminology or what to search for to answer it myself either.

Lets say I have a pool of threads and they're all full, a new task comes in and has to wait for a thread to open up, what I currently do is have a request function loop forever with a 100ms sleep, it checks to see if any are open and returns when there is, if not it blocks until there is, in situations like this I always use some kind of sleep function in every language I've used so that I don't kill the CPU but what I'm wondering is if there's any better way to do things like that, hardcoding arbitrary times like 100ms seems like a bad practice because it could either be too long or still too short.

tl;dr what is the proper way of doing infinite loops without killing the cpu or sleeping an arbitrary amount of time? Is this the only option?
>>
>>54988777
A semaphore that blocks the sentinel function until a thread opens up..?
>>
Should I learn C++ first?
>>
>>54988681
BEST LANGUAGE
>>
>>54988825
no, go for python or c# or java
>>
>>54987933
>type theory sum types?
kek

https://en.wikipedia.org/wiki/Tagged_union
https://en.wikipedia.org/wiki/Union_type

>>54987967
>Java doesn't have either
inheritance.
>>
>>54988825
learn C first
>>
is programming highly reliant on memory?
How do you guys remember all those random ass codes and their orders?
>>
>>54988825
personal option - learn ruby or python first because you don't have to deal with banging your head against the wall with boilerplate, static typing and compiling - you'll learn fundamentals like variables, control flow, functons and classes must faster and you can take that knowledge with you into other langs
>>
>>54988777
google event/observer pattern
>>
>>54988852
>inheritance

class One extends Integer
class Two extends Integer
class Three extends Integer
>>
>>54988812
I feel like that's what I'm doing now but nested deeper, like no matter what I have to poll the array of threads to check it right? That polling is what I'm trying to avoid but it seems impossible, I know a little about events in operating systems but I don't know how they're implemented in a cpu efficient way.

I guess I could have threads signal back to the semaphore that they're done in some way allowing them to be consumed again. Is that a good approach?

>>54988867
Thanks I'm going to read up on it. Keywords like "observer" are what I'm missing in my searches, and words like "yield" often result in generators.
>>
>>54988857
It's simple. Most programming languages you can just go 10101010101010001010 and a tutorial will pop up and guide you through
>>
>>54988857
Practice mostly. Plus the reward of being able to shitpost on /g/ is a good source of positive reinforcement.
>>
>>54988885
anon pls
>>
>>54988857
no, quite the opposite, its just like any other profession, you remember it because you need it, and work with it. But you use logic principles to learn it and use it.
>>
>>54988872
class NotAnInteger extends Integer
>>
>>54988857
It's 100% practice

first you have everything taught to you by google and it takes agonizing amounts of time to do anything
then you learn how to read documentation and install packages without it taking too much time and do everything independently
and finally then you have everything you use on a daily basis memorized and you only have to refer to things once every few hours

that's the way it is for me anyways
took a few months
>>
>>54988912
how do you remember when to make a space or when to leave a coma or when not.
or stuff like attributes or any sort of random little symbol.

Is there a program that like auto completes stuff or mentions when you made a typo?
>>
>>54988958
explain install packages and documentation
>>
>>54988965
https://en.wikipedia.org/wiki/Integrated_development_environment
>>
>>54988973
I think you need apt-get, bb
>>
>>54988965
what the fuck?

Do you even understand basic syntax?
The rules never change, you should learn what the commas are for.
>>
>>54988965
yes, eclipse for java is very specific in what it accepts and was pretty helpful when I was just starting out
Haven't found anything quite like it

>>54988973
what is there to explain? Documentation is made up of documents written by the developers explaining how to use their language/packages
Packages are collections of files written to help you do stuff easier
>>
>>54988999
>the rules never change
Have you only ever used one language?
>>
>>54989010
name a language where commas aren't a delimiter.
>>
>>54988857
I almost always have the spec or some kind of syntax sample open because there's no way I can remember all the details of each language when working with multiple ones, my memory is terrible which is why I utilize notes too. I have no idea if professionals need to reference documentation as much as I do or if it's as bad as I think it is.

It's only ever syntax or language semantics though, logic and methods I've learned or experienced carry throughout all languages I've used.
>>
>>54989014
... bf?
>>
>>54988965
>Is there a program that like auto completes stuff or mentions when you made a typo?
Text editors and compilers/interpreters. Static analysis tools, etc.
>>
>>54989014
what do you mean by delimiter

in some useless sense all tokens are delimiters
>>
>>54989014
English
>>
>>54989014

One I just made up.
>>
>>54989014
Brainfuck
>>
>>54988999
I don't even mean the comas and symbols that much, just the phrases and sets of words

like autoplay_images
setAttribute

like if you have never done shit with images how are you supposed to suddenly know
"oh this function eould be great for what I need" when you've never seen or heard about it?
>>
>>54989076
documentation
>>
>>54989076
for instance (libraries)
http://en.cppreference.com/w/
>>
>>54989076
blood rituals
>>
>>54989081
>>54989093
sounds like you really have to go out of your way to programm something, does this never conflict with programmers working together and wanting to do things differently?
>>
>>54988578
Learn Vulkan instead.
>>
>>54989104
yes, using other people's libraries can be difficult and oftentimes isn't worth the effort.

you see this a lot in javascript
jquery code looks more complex than it's equivalent in pure javascript
>>
>>54989124
javascript is never pure
>>
MATLAB>Python>Java>C++>C>R

Thanks to uni, I learned in that order. Where should I go from here? I use only Python and R at work.
>>
File: 1452154219311.jpg (65 KB, 480x640) Image search: [Google]
1452154219311.jpg
65 KB, 480x640
>>54989124
>jquery code looks more complex than it's equivalent in pure javascript
get a load of this fag
>>
>>54989124
explain libraries in /g/ terms
aside from the default ones
>>
>>54989132
I can guarantee you know none of those languages very well.
>>
>>54989132
I assume > means you did the one on the left first, because otherwise your arrows are all reversed. It certainly seems like your choice in languages is improving
>>
>>54989148
Yes, you are correct. My choice of languages was out of my control. It followed a typical MIS track with a focus on data science.
>>
>>54989146
Use someone else's bad code so you can blame your spaghetti on someone else.
>>
>>54989147
I do well with Python and R. I use them every day. The rest? Meh. C and C++ aren't really used in the field for it. Java can be, but who wants to?
>>
>>54989076

By reading, the same as anything else.
>>
>>54989196
congrats, you're unemployable
>>
File: no.gif (862 KB, 300x224) Image search: [Google]
no.gif
862 KB, 300x224
>>54989124
>>
>>54989216
Currently employed with a consulting firm who does mostly HR consulting. Maybe I'm unmployable for software engineering, but not everything in IT requires C or Java.
>>
>>54989146
the reason that it takes 30 minutes to run any fucking project on github because the programmer has a dependency that only works on certain operating systems
>>
How can I make my cheat less "detectable" by humans? The community has realized that the anticheat is useless and has taken it into their own hands to find cheaters. They're making suspected cheaters dump Explorer and looking through displaydns and even looking in the Prefetch folder. What can I do?
>>
>>54989528
By teaching humans not to cheat
>>
>>54989528
depends a lot on the cheat and what anti cheat your trying to get through
for DNS scanning you can simply flush the DNS cache
use somekind of polymorphism to throw off signature scans
most importantly, make sure your cheat doesn't modify shit in the code section of your target process because that will flag you instantly
>>
>>54989528
rather than telling the cheated not to be
>>
I have a bunch of html files, each one containing a line that would link to an image, formatted like so.

<img id="show_image" src="https://49.media.tumblr.com/a7d7323885509fa85478fd30af784af9/tumblr_n6sxu83sGe1scd4jmo1_400.gif" />


I want to grab the link located in the quotation marks after src=
grep -Po 'show_image" src=".*?"' "$line"
will find the line within the file, but it still leaves everything before and after the .*?. I don't want that to happen
Don't tell me what I'm looking for is in the grep manual.
>>
>>54989568
Humans, the cheat itself can be easily deleted with sdelete, but traces of it are still there.

So far my plan is just to make it look like a windows exe something like Win32FontHelper but that seems like a horrible and temporary solution
>>
>>54989591
http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags

>>54989592
>Humans
elaborate, what are they doing and what traces are we talking about?
>>
>>54989591
Just run it through a python script. EZ.
>>
>>54989591
oh my gosh! I know how to do a question on /g/

in beautifulsoup you'd:
for element in soup.findAll('img'),{'id'.'show_image'}
print(element.get('src'))
>>
>>54989615
>traces
For example, checking C:\Windows\Prefetch for known cheat names

Dumping Explorer.exe and looking for keywords (solved by encrypting strings)

displaydns, recently flushed? tempban

Looking through installed icons, easy fix just don't use icons

Looking in Regedit for USB's (I don't trust my client to use USBOblivion safely), if there's USB's you better plug it in or have a really good excuse
>>
>>54989106
it's ever more boring
>>
>>54989651
Just name it something inconspicuous
>>
>>54989651
kek, sounds liek a poormans anticheat senpai
just randomize strings/names and dont use icons
as for dns, just clear your own entry and you should be fine

>Looking in Regedit for USB's, if there's USB's you better plug it in or have a really good excuse
uh i dont think this is how it works m8
>>
File: javaw_2016-06-09_03-40-13.png (38 KB, 433x686) Image search: [Google]
javaw_2016-06-09_03-40-13.png
38 KB, 433x686
>>54989759
They check here for known USB's

>as for dns, just clear your own entry and you should be fine
this would help me greatly, how do I do this?
>>
>>54989819
They check here for known USB's
searching for what exactly?

>this would help me greatly, how do I do this?
great, figure it out on your own
>>
>>54989860
My cilents are telling me that once they check in the registry, they're being asked to plug in any USB's that are found there. Thankfully most of them don't use the cheat from a USB, so it's not much of an issue.
>>
>>54989906
>my clients
>>
>>54987866
I know C, R, Perl, Java, and Python. I can also do a bit of MPI and OpenMP. Do I have any chance of getting a job guys? Almost finished my CS degree and I'm a bit scared.
>>
>>54990059
get a job where you did your two summer internships
>>
>>54990065
Didn't do any internships.
>>
>>54990095
what did you do with your time then? Just sit on your ass all day?
>>
>>54990109
Worked hospo jobs and trained a lot of BJJ mostly.
>>
Hey guys, I'm learning C right now (from C programming a modern approach, albeit the first edition cause I found it at my local powells for $4) and was wondering if this would be a good book for when I move to C++ as I found it at goodwill for $6 https://www.amazon.com/Programming-Problem-Analysis-Program-Design/dp/1285852745/ref=sr_1_fkmr1_1?ie=UTF8&qid=1465472301&sr=8-1-fkmr1&keywords=from+project+design+to+C%2B%2B
>>
IT'S ALIVEEEEE
>>
>>54982474
I can't tell if you're seriously retarded.
>In 1999, Yasumasa Kanada and his team at the University of Tokyo correctly computed π to over 200 billion decimal places on the supercomputer HITACHI SR8000/MPP (128 nodes) using another variation of Ramanujan's infinite series of π.
>There soon followed other computations, all based directly on Ramanujan’s idea—as is the method we use for computing π in Mathematica and the Wolfram Language.
>>
File: le.png (14 KB, 752x106) Image search: [Google]
le.png
14 KB, 752x106
>>54985864
web apps are overhyped even today, they're mostly just bloated babby's first toy shit like agar.io and crap like that, and e.g. music streaming services don't make much money or they lose a fuckton of money, and e.g. google play music is fucking garbage and has an unresponsive UI and is full of bugs.

web apps in general tend to be of incredibly poor quality and be full of bugs and incorrectness because they're awful lazy hackjobs, but even if you fixed those things you'd still have the inherent issues with performance and the latency and battery drain of an online connection.

the format of websites that are visited through a general-purpose web browser is only suitable for low-quality content (e.g. 4chan) that needs to be readily and conveniently accessible from everywhere on a whim. for any serious application it's better to have a native client if it's not too much effort for the overpaid sub-105 IQ smug hipster fag developers to program and for the end users to install.

also the internet of things and wearable devices meme will require high-performance and energy efficient native apps and will hopefully help stave off the web app meme. your shitty weather app should run on a low-end literal toaster or you'll lose a significant part of the market.
>>
>>54989528
lad
learn to make your cheat a driver, games don't have ring0 access
>>
>>54987757
good lad
>>
Is there a way to "fill" a shell variable as if it was a set?
I'm trying to use this variable as parameter for a cut command in my script, and want it to contain the positions that cut will have to look into based on which parameters the user passed when running the script.
I already have all the parsing and printing parts down.
>>
>>54990602
more likely the toaster will have 8 ARM cores in it and it'll run just fine
>>
>>54990602
it depends
I can't find anything native better than this
https://github.com/bastimeyer/livestreamer-twitch-gui
>>
>>54987866
I've got an exam in C++ tomorrow, any cool built-in functions I should know of?
>>
What are things to take in consideration when implementing a hash map?

Sure, I could just naively create some open addressing thing with linear probing with load factor of something like 0.7 but is there something else I should think about?
>>
>>54990714
A prime number of buckets generates less collisions.
>>
>>54990713
no
>>
I don't know what to do
This is my second year of studying programming and I feel like I should start a personal project but I don't know what to do. I want to start working on game development but every project I think of seems too big and lofty for my means.
>>
>>54989591
ez Perl :
$html = qq(<img id="show_image" src="https://49.media.tumblr.com/a7d7323885509fa85478fd30af784af9/tumblr_n6sxu83sGe1scd4jmo1_400.gif" />);

$link = $1 if ($html =~ /(?:.*)src="(.+)".*/);
>>
>>54988857
A lot of code either works the same in other languages or works very similarly in other languages. You only really learn about loops once, for example, then it's just a matter of how each language does them.
>>
>>54990741
Of course, or most importantly the probing length is relatively prime to the number of buckets.
>>
Question about PHP access modifiers:

Public: Can be accessed outside of a class.
> $pretendObject -> myVar;

Private: Can ONLY be accessed inside the class, including functions in it.

Protected: The same as private, but can also be accesssed by classes that extend its class.

Is that basically correct?
>>
>>54988965
how do you write in english? it's basically automatic, it comes naturally once you know the (programming) language. but yes, the IDE that you use to program with autocompletes stuff and checks for syntax errors
>>
>>54989146
a library is a collection of code that someone else has already written

libraries are mostly garbage
>>
>>54987899
>everyone has unlimited memory
>>
>>54988965
>>54989076
IntelliSense
>>
>>54990884
it was not about memory, the fedora tipping idiot wouldn't accept that F# is shit and irrelevant and his argument was that F# had a concise way of declaring a union of two types, one of which has a variable that the other type doesn't have
>>
Any decent non video learning sources out there for Java? Something ending with a project preferably.
>>
>>54990926
the 10th edition book by daniel lang and
https://docs.oracle.com/javase/tutorial/
>>
>>54990617
You clearly missed the intent of his post.

Cheats are mostly undetectable by games at this point, but competitive games are implementing a human review process where they vote and say whether a person, beyond a reasonable doubt, is cheating.
>>
>>54990942
>https://docs.oracle.com/javase/tutorial/
Oh wow I didn't think the oracle documentation would be good enough to learn from, thanks for the link.
>>
>>54990951
>They're making suspected cheaters dump Explorer and looking through displaydns and even looking in the Prefetch folder

and >>54989592
make it seem like they have humans look at the traces of dump files, etc

not gameplay
>>
>>54990602
Google Play is fine.

For me, the UI is snappy and does what I need it to.
>>
File: huehue.gif (1 MB, 480x270) Image search: [Google]
huehue.gif
1 MB, 480x270
>>54990923
The fact they even call them unions instead of enums like in any sane language is enough of a reason to never touch F#.

That's almost as bad as java trying to redefine the meaning of references.
>>
File: [tilting increases].png (27 KB, 500x500) Image search: [Google]
[tilting increases].png
27 KB, 500x500
>>54991003
yeah

>like to see you do functionality and clarity like discriminated unions in Java

type BankAccountState =
| ZeroBalanceState
| ActiveState
| OverdrawnState
| ClosedState


it's literally

enum BankAccountState {
ZeroBalanceState,
ActiveState,
OverdrawnState,
ClosedState
}


then he backpedaled to

type BankAccountState = Closed | Open of float<dollars>


it's just stupid
>>
>>54990923
>F# is shit and irrelevant
It's irrelevant, but it certainly isn't shit.

I don't really use it, but it feels nice enough.
>>
>>54991003
>>54991025
pajeet
you have no idea what is an enum and what is a discriminated union

this is an enum and it behaves differently
type Poo =
| Loo = 0
| Street = 1


Enum's (besides having limited functionality) have no compile-time guarantee of total matching, so you can't directly translate

type BankAccountState =
| ZeroBalanceState
| ActiveState
| OverdrawnState
| ClosedState

into an enum
>>
>>54987866
Anyone got the roll thing with the challenges and shit?
>>
>>54991080
>discriminated union
unions haven't been discriminated since companies used mercenaries to rough them up
>>
>>54991080
enums in java have compile time guarantees they're not just integers idiot
>>
>>54991080
to have it match in a language without discriminated unions, you have to do this
using System;

namespace FSM.BankAccount
{
public abstract class BankAccountState
{
public static readonly BankAccountState ZeroBalanceState = new ChoiceTypes.ZeroBalanceState();
public static readonly BankAccountState ActiveState = new ChoiceTypes.ActiveState();
public static readonly BankAccountState OverdrawnState = new ChoiceTypes.OverdrawnState();
public static readonly BankAccountState ClosedState = new ChoiceTypes.ClosedState();

public abstract T Match<T>(
Func<T> zeroBalanceStateFunc,
Func<T> activeStateFunc,
Func<T> overdrawnStateFunc,
Func<T> closedStateFunc);

private static class ChoiceTypes
{
// ReSharper disable MemberHidesStaticFromOuterClass
public class ZeroBalanceState : BankAccountState
{
public override T Match<T>(
Func<T> zeroBalanceStateFunc,
Func<T> activeStateFunc,
Func<T> overdrawnStateFunc,
Func<T> closedStateFunc)
{
return zeroBalanceStateFunc();
}
}

public class ActiveState : BankAccountState
{
public override T Match<T>(
Func<T> zeroBalanceStateFunc,
Func<T> activeStateFunc,
Func<T> overdrawnStateFunc,
Func<T> closedStateFunc)
{
return activeStateFunc();
}
}
...
>>
>>54991106
>using C# in a strawman argument against java
kill yourself
>>
>>54991106
            public class OverdrawnState : BankAccountState
{
public override T Match<T>(
Func<T> zeroBalanceStateFunc,
Func<T> activeStateFunc,
Func<T> overdrawnStateFunc,
Func<T> closedStateFunc)
{
return overdrawnStateFunc();
}
}

public class ClosedState : BankAccountState
{
public override T Match<T>(
Func<T> zeroBalanceStateFunc,
Func<T> activeStateFunc,
Func<T> overdrawnStateFunc,
Func<T> closedStateFunc)
{
return closedStateFunc();
}
}

// ReSharper restore MemberHidesStaticFromOuterClass
}
}
}
>>
>>54991080
>waaaaaaaaah, your language doesn't fully support my autism

Good.
>>
File: anaconda-1.jpg (252 KB, 1024x768) Image search: [Google]
anaconda-1.jpg
252 KB, 1024x768
anyone here like using ncurses? it's fun
>>
echo -e "$line" | cut --output-delimiter=$'\t' -d ' ' -f 1,${three},${four},${five},${six},${seven},${eight},${nine},${ten},${thirteen},${fourteen},${sixteen},${fifteen},${seventeen}

I wrote this shell line, where cut should print the data in the 15th separator after the data in the 16th, if both have been called for by the script's parameters.
Problem is, whenever I call for both those pieces of data, cut always prints 15th and then 16th. How can I fix that?
>>
File: 1396697154175.jpg (66 KB, 600x450) Image search: [Google]
1396697154175.jpg
66 KB, 600x450
>>54991106
>>54991121
holy KEK
>>
>>54991178
nice samefag jackass

you're a fucking idiot, enums in java are not just integers
>>
File: ss (2016-06-09 at 02.49.33).jpg (19 KB, 224x198) Image search: [Google]
ss (2016-06-09 at 02.49.33).jpg
19 KB, 224x198
>>54991185
ok kid
>>
>>54991193
>literally hitting f12
>>
>>54991193
kys
>>
>>54991159
Yes

Coding an ncurses spreadsheet app with lua as formula evaluator/scripting language
>>
this is valid java

public enum Planet {
MERCURY (3.303e+23, 2.4397e6),
VENUS (4.869e+24, 6.0518e6),
EARTH (5.976e+24, 6.37814e6),
MARS (6.421e+23, 3.3972e6),
JUPITER (1.9e+27, 7.1492e7),
SATURN (5.688e+26, 6.0268e7),
URANUS (8.686e+25, 2.5559e7),
NEPTUNE (1.024e+26, 2.4746e7);

private final double mass; // in kilograms
private final double radius; // in meters
Planet(double mass, double radius) {
this.mass = mass;
this.radius = radius;
}
private double mass() { return mass; }
private double radius() { return radius; }

// universal gravitational constant (m3 kg-1 s-2)
public static final double G = 6.67300E-11;

double surfaceGravity() {
return G * mass / (radius * radius);
}
double surfaceWeight(double otherMass) {
return otherMass * surfaceGravity();
}
public static void main(String[] args) {
if (args.length != 1) {
System.err.println("Usage: java Planet <earth_weight>");
System.exit(-1);
}
double earthWeight = Double.parseDouble(args[0]);
double mass = earthWeight/EARTH.surfaceGravity();
for (Planet p : Planet.values())
System.out.printf("Your weight on %s is %f%n",
p, p.surfaceWeight(mass));
}


java has no proper enum type (valuetype), it is just an alias for a class
>>
>>54991250
URMOM (Double.POSITIVE_INFINITY, Double.NaN)
>>
>not inheriting Byte with your Enums to save memory
>>
>>54991292
enum class Yes: uint8_t {};
>>
File: clint.gif (858 KB, 240x228) Image search: [Google]
clint.gif
858 KB, 240x228
>>54991228
>coding
>>
>>54991292
>not declaring your enum members as powers of 2 so you can use bitwise comparisons
>>
File: 1464853587470.jpg (23 KB, 238x292) Image search: [Google]
1464853587470.jpg
23 KB, 238x292
>>54991198
>not using gdb to attach to the browser process and manipulating single bits directly
>>
>>54991431
That's not an enum anymore then is it.
>>
>>54991548
Of course it is.
>>
>>54991561
You get the values from the enum, but you can't actually store the flags in the enum.

And if you're not storing the values in an enum, why even bother at all, just use constants with the same prefix to show how they are connected.

So no, it's not.
>>
Is there a technical term for stripping an application of all unnecessary libraries to decrease file size before deployment?
Surely there is.
>>
>>54991741
yes stripping
>>
Curry programming languages:
Java, C++, C#, PHP

Aryan programming Languages"
C, Javascript, Python,
>>
File: o1SZsdB.png (15 KB, 828x312) Image search: [Google]
o1SZsdB.png
15 KB, 828x312
>>54991593
>just use constants with the same prefix
Laaaaame.
>>
>>54991809
posts like these should be banned
>>
>>54991809
>i am not pajeet ur pajeet
>t. Nagarajan Shanmuganathan
>>
>>54991824
>t. Pajeet
>>
>spent whole day fighting with maven and intellij and annotation processor
>while at it decided to finally move root module content to child, leaving root empty, like all big guys do
>everything works just fine like if there weren't any problems at all
On the bright side I can do actual work now. On the other I still don't understand why it didn't work before.
>>
>>54991809
>C, Javascript, Python
>webmonkey copypasted helloworld.c and became 1337 haxor
>>
>>54991818
As I said, you can only use an instance of the enum to store the explicitly defined values, not all combinations.
So you'll probably just use an int instead, and lose all the benefits of using a fucking enum in the first place.

This meme needs to die.
>>
>>54991809
literally the other way around
>>
>>54991561
i'd just have unsigned integers as bitmasks instead of calling them enums, enums are quite different conceptually, you shouldn't rely on an enum having a specific value
>>
>>54991908
>you can only use an instance of the enum to store the explicitly defined values, not all combinations
No fucking shit.

Why would you store all possible combinations of anything?
>>
>>54989059
Shitty language, desu.
>>
Wondering why if I subscribe a method that updates the display to a lists changed event handler it changes the list, but if I call the same method from a button the list doesn't get changed.
>>
>>54991961
Put a breakpoint in the method and confirm that it's actually being called.
>>
>>54991942
Enums are for storing values that can only be what is defined in the set, like the state in an FSM.

Using enums to mangle flags stored in an int doesn't actually give you any of the benefits of an enum over using constant values instead, it's just syntactic sugar.
>>
>>54991772
Naughty
>>
>>54992038
Well, yeah.

I didn't claim any sort of benefit.

I just prefer the way it writes. It's easier to reason about when I'm writing.
>>
In my spare time I help blind children

I mean the verb, not the adjective.
>>
>>54992050
no it's literally called binary stripping
>>
>>54991741
de-bloating
>>
>>54992061
can't wait for the SJWs to catch wind of this.
>>
>>54992061
Stop. You're getting me hot
>>
>>54989059
depends on what you mean by delimiter, i use commas all the time

https://www.youtube.com/watch?v=wKl6umkwKfU
>>
>>54991741
ya it's called having common sense in your release build settings
>>
>>54992052
Except it's not easier for the person reading it, as they'll see an enum and only expect those defined values to be used.

Just because you can do something, doesn't mean you should.
>>
>>54992093
pls no bully
>>
>>54992028
Yeah. When subscribed to the event handler it's being called -- 3 times in fact, because somehow it modifies the list inside the handler. Which creates additional calls.
>>
>>54992176
Does the handler reference either of the method parameters?

That's the only way it would change depending on which element called it.
>>
>>54987866
typography library in scss
>>
Is it okay if I initialize a pointer in a constructor?
>>
>>54992220
yes
>>
File: image.jpg (84 KB, 325x450) Image search: [Google]
image.jpg
84 KB, 325x450
>>54992294
Thank you
Have this as my thanks
>>
>>54988857
How do you natural language users remember all those random ass sounds and their orders?

My point is that they're not random ass, if you learn them, you know what they mean, and you know how to compose them into something larger.
>>
>>54992220
you should always initialize everything in the constructor.
If you don't know what the pointer should be, use a nullptr.
>>
Working on Bingo game for my schoolwork

http://pastebin.com/Vu0mQW5K
>>
oxford or cambridge?
>>
File: 9780511791338i.jpg (61 KB, 180x276) Image search: [Google]
9780511791338i.jpg
61 KB, 180x276
>>54991319
What's wrong with the term faggot?
>>
>>54988698
Because it's a pretty cool systems language
>>
>>54992603
cambridge for CS
>>
>>54992645
I didn't say there was anything wrong with the word faggot.

I'm not taking advice on terminology from someone who doesn't know when commas are required.
>>
>>54992603
Depends if you like putting your chode into a pig's mouth or not
>>
>>54992708
I asked you why do you think faggot is wrong as a term since you seemed like such a grammar faggot, knowing all about the term coding and shit, but apparently you're just a faggot in general, faggot.
>>
File: women-in-tech.png (59 KB, 1354x602) Image search: [Google]
women-in-tech.png
59 KB, 1354x602
hey guys there's an entry level job opening for software developer advertised at my university and it says requires experience with C++ and visualstudio but i don't really have any experience with either. do you think i should still apply?
>>
File: 562.jpg (36 KB, 600x600) Image search: [Google]
562.jpg
36 KB, 600x600
>>54987866
>posting the degenerate homosexual anime image
>>
File: really.gif (2 MB, 300x290) Image search: [Google]
really.gif
2 MB, 300x290
>>54992755
You seem upset, is it because English is not your first language and you sometimes have trouble getting your point across?
>>
>>54992867
he's probably a pajeet. vote trump so his h1b doesn't get renewed
>>
Hey dpt i've only recently started with html and css i'm currently modifying a homepage thats setup with links, I was wondering how I would go about adding a live weather check. I don't want it to tell me if its raining or if its cloudy I just want the temperature.
>>
I'm starting a summer project/internship next week, based on displaying data in VR via the Unreal engine and I have no idea what I'm doing with no motivation to read tutorials

someone help pls
>>
>>54992837
Absolutely not.
>>
>>54991025
>backpedalled
The original problem was someone else you muppet
>>
>>54992954
lol, keep up.

http://www.foxnews.com/politics/2016/03/03/trump-softens-h1b-visa-policy-during-gop-debate.html
>>
>>54991003
>>54991103

Discriminated unions often aren't enumerated
The fact that Rust or whatever calls sum types / discriminate unions "enums" when they aren't even enumerated is enough of a reason to never touch F#

That's almost as bad as Java completely lacking anything like a union at all
>>
>>54993100
>enough of a reason to never touch F#
whoops, meant Rust. but performance is certainly a reason not to touch F#

use Ocaml instead
>>
Why do I have to use the friend keyword when using some operation overloads?
>>
>>54993100
if you unironically believe you have a need for unions just use C++ like any sane non-neckbeard and non-fag industry person
>>
File: 1958201258.png (147 KB, 815x627) Image search: [Google]
1958201258.png
147 KB, 815x627
>>54993217
I love how salty you get when I post this image

You my friend have what's known as a stupid fucking opinion
>>
>>54993242
They're right though, you autist
>>
>>54993168
Because we like to maintain a friendly atmoshere here at strostrupistan
>>
>>54993217 >>54993267
Why would I use C++ for unions when I can use almost any language I like?

Don't you think it would be pretty retarded if Java didn't have product types in the form of:
class abcd { int x; float y; }

So why isn't it retarded that it doesn't have unions?

You literally can't do them in Java without trying to use FFI or something to do memory management yourself
>>
>>54993242
you're clearly the one that's salty
>>
>>54993309
>You literally can't do them in Java
ever heard of a little oop concept called inheritance?
>>
>>54993309
C++ and java are literally the best languages. the reason java doesn't have unions is because it's a simplified language based on C++ but with many features removed (on purpose).
>>
>>54993309
java is object oriented.
>>
File: highresicon.png (1 MB, 512x512) Image search: [Google]
highresicon.png
1 MB, 512x512
I was finally able to publish a 3D Unity game to the appstore. people say its fun, but I think it could have been better.
>>
Pick one /g/

struct MouseHolder {
const Mouse& mouse() const;
Mouse& mouse();
};
MouseHolder a, b;
a.mouse() = b.mouse();


versus

struct MouseHolder {
const Mouse& getMouse() const;
void setMouse(const Mouse& mouse);
};
MouseHolder a, b;
a.setMouse(b.getMouse());
>>
>>54993333
Inheritance isn't the same as a union, inheritance is open
Plus having to separate it is pretty dumb

e.g.
base class integer

class One extends Integer
class Two extends Integer
class NotAnInteger extends Integer
etc

In Java how would you say "ONLY x y and z and NOTHING ELSE inherit from this"?

>>54993342
lots of OOP code uses unions
>>
>>54993367
>class One extends Integer
>class Two extends Integer
>class NotAnInteger extends Integer
>etc
not an argument.
>>
>>54993383
not an argument extends argument
>>
>>54993367
>lots of OOP code uses unions
oop is only about operations. please, learn the basics before posting here.
>>
>>54993363
The second. The first is pants on head retarded
>>
>>54993395
Can't do OOP without primitives to work on
>>
>>54993403
Are you retarded? What do you *need* unions for, tell me right now.
>>
>>54993403
unions are completely unnecessary. you think java would be the #1 programming language in the world if it lacked something that was truly necessary?
>>
>>54993414
Fixed subtyping
>>
>>54993422
java lacks unsigned integers of any kind
>>
if [ $count>$max ]; then
max=$count
fi
echo -e $'\t\t'$max

This isn't working, max decreases as the script finds lower values of count. It's like it ignores the if entirely. Help?
>>
>>54993429
char is unsigned and java guarantees two's complement so that the bit pattern is always the same as unsigned, and it has the logical shift operator >>>
>>
>>54993446
Char in java is signed.
>>
>>54993429
So does OCaml.
>>
>>54993403
wrong
>>
>>54993114
ocaml is worse than f# though
>>
>>54993443
Solved, string comparison should be quoted.
>>
>>54993464
wrong
>>
>>54987866
I am working on a site. Because of Bordom and for my Friend. Want a Peak? kingzandqueenz.neocities.org/
>>
>>54993428
you're doing it wrong
>>
>>54993333
Nice quads.

If Java had barebone unions, it would fuck up arbitrary inspection of references for the GC. Same thing for barebone pointers that can be xored and such
>>
>>54993515
>namefag
>non-English speaker

You need a noose.
>>
>>54993598
I do. Thank you for pointing that out. God damn the name thing. I swear to God if my cousins keeps adding names to it I will freaking remove all electronics in his room.
>>
>>54993593
At the very least it could have discriminated unions
>>
>>54980467
fuck, I had forgotten how to prove shit...

>9. Prove that for each n e N,
>(n+1)(n+2) ··· 2n
>is divisible by 2^n.
this one was easy. proof by induction:

for the base case: let n=2. then we get:
(2+1)(2+2) = 3·4 which is obviously divisible by 2^2

let's assume that for n=k, (n+1)(n+2) ··· 2n is divisible by 2^n. let
f(n) = (n+1)(n+2) ··· 2n

for n = k+1 , we get
f(k+1) = ((k+1)+1) ((k+1)+2) ··· ((k+1)+(k-1)) ((k+1)+k) ((k+1)+(k+1))
= (k+2) (k+3) ··· (2k) (2k+1) (2k + 2)
= [ [(k+1) (k+2) ··· (2k)] / (k+1) ] (2k+1) (2k + 2)
= [ [(k+1) (k+2) ··· (2k)] / (k+1) ] (2k+1) 2(k + 1)
= 2[(k+1) (k+2) ··· (2k)] (2k+1)
(removed (k + 1) from the dividend and divisor)
= 2·f(k)·(2k+1)

then f(k+1) is divisible by 2·(2^k) = 2^(k+1), and the general case is proven
>>
>>54993624
That's true... maybe one could bundle together some template stuff in order to create a baroque templated mess like so:
class mess <T...> {
abstract private class hiddenBase { ... }
public class container1 extends hiddenBase { public T1 get() ... }
public class container2 extends hiddenBase { public T2 get() ... }
...
public class reference { private hiddenBase; public T1 get1() throws(...) ...
}
}
Then any Mess.Reference can only contain types that were passed as parameters. (Maybe containers don't need to be public and have encapsulation but I'm too lazy to edit) Is there such a thing as variadic template parameters in Java?
>inb4 I know they are generics
r8 my suggestion DPT
>>
>>54993785
>private base class
That's actually not bad
You only need two to have full functionality since you can do
mess<A, mess<B,C>>

but obviously it's very messy that way
>>
>>54993363
option c use a class
>>
>>54993801
>his lang doesn't have Turing complete generics
Obviously I'm very C++ oriented. Nonetheless thank you very much. A mess inside a mess in a binary tree... yes that's not even envisionable :^)
>>
>>54993916
Java generics are turing complete
>>
Hi /g/
I've written a little application that downloads all pics in a thread but I'm having a bit of trouble with some unicode filenames.
This is the thread I'm talking about:
>>>/aco/619361
I'm using python and fetching the filenames from the thread's JSON, unfortunately my program crashes on certain filenames like:
ストッキング (1).gif and ストッキング (2).gif

I've looked around on the interwebz but I can't really seem to find anything that helps me.
Here is some of the related code:
# -*- coding: utf-8 -*-

some imports...

reload(sys)
sys.setdefaultencoding('utf-8')

Fetching filenames:
def getFiles (jsonStr):
results = []

def _decode_dict (dic):
try: results.append((dic["filename"],dic["ext"]))
except KeyError: pass
return dic

json.loads(jsonStr, object_hook=_decode_dict)

return results

Removing a few illegal characters (the list is prob not complete but I'm to lazy to fix it until I encounter a problem with it)
def processFileName (inString):
illegalList = ['&','|','?',',',';','.','/',':','=','+','!']
outString = inString

for iChar in illegalList:
outString = outString.replace(iChar,'_')

print('Processed filename: ' + outString)

return outString


The program crashes whenever I try to print one of these strings:
Traceback (most recent call last):
[part left out due to comment length limit]
File "C:\Users\Anon\Pictures\4chan\Scripts\Python\Downloader.py", line 46, in main
fileStrings.append(processFileName(tup[0]) + tup[1])
File "C:\Users\Anon\Pictures\4chan\Scripts\Python\Downloader.py", line 169, in processFileName
print('Processed filename: ' + outString)
File "C:\Python27\lib\encodings\cp850.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode characters in position 20-25: character maps to <undefined>
>>
>>54994039
google search for UnicodeEncodeError obviously

or stop using cancerous python

or stop downloading weeb shit
>>
>>54994039
Fixed it by changing the processFileName function:
def processFileName (inString):
illegalList = ['&','|','?',',',';','.','/',':','=','+','!']
outString = inString

for iChar in illegalList:
outString = outString.replace(iChar,'_')

outString = outString.encode('ascii','ignore')

print('Processed filename: ' + outString)
Thread replies: 255
Thread images: 31

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.