[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: 22
File: 1435753933225.png (481 KB, 811x599) Image search: [Google]
1435753933225.png
481 KB, 811x599
No trapfags allowed edition

Old: >>52178500
>>
I'm home for the holidays and using my parents' Windows 10 machine. What should I use to write and how do I compile or run scripts?
>>
second for D
>>
>>52181140
>there are people on this general who think rounding should occur towards 0, as if rounding should ever be the final step in a function
Why are you people so dum?
>>
>>52181188
HTML
Chrome
>>
File: python.png (40 KB, 540x566) Image search: [Google]
python.png
40 KB, 540x566
>pythonfags will defend this
>>
Should I really read pic related if I already know how to program? I know python and C but I'm not omniscient yet.
>>
>>52181200
Wow, really?
>>
>>52181220
It's a good book
>>
>>52181217
Isn't this just what x86 returns for floating-point arithmetic?
>>
>>52181188
Sublime. It has syntax highlighting and compilers/interpreters for ~30 languages
>>
>>52181217
>people who don't understand how floating-point numbers are stored in binary will attack this
>anti-python memers who think it only applies to python actually think this
>>
>>52181243
So I have to pay ... to write ... programs?
>>
>>52181260
I meant Sublime Text 3. I guess I should have been more clear.
>>
>>52181260
The same way you had to pay to use winrar back in the day.
>>
>>52181260
Did you not pay for your computer Jamal?
>>
>muh averaging over 2 ints
>muh floating points
typedef struct _rat {
int n;
int d;
} rat;

rat *makerat(int n)
{
rat *res;
res->n = n;
res->d = 1;
return res;
}

rat *add(rat *a, rat *b)
{
rat *res;
res->n = a->n * b->d + a->d * b->n;
res->d = a->d * b->d;
return res;
}

rat *mul(rat *a, rat *b)
{
rat *res;
res->n = a->n * b->n;
res->d = a->d * b->d;
return res;
}

rat *inv(rat *a)
{
rat *res;
res->n = a->d;
res->d = a->n;
return res;
}

rat *div(rat *a, rat *b)
{
return mul(a, inv(b));
}

rat *avg(int m, int n)
{
return div(add(makerat(m), makerat(n)), makerat(2));
}

you can implement cancellation etc. yourself
>>
>>52181300
I haven't used anything but Linux for like 4 years now for anything more than Internet access.
>>
File: 1450463515813.png (583 KB, 740x571) Image search: [Google]
1450463515813.png
583 KB, 740x571
>>52181306
rat *res;
res->n = n;
res->d = 1;
return res;
>>
>>52181140
How do we know she isn't a trap?
>>
Gonna start getting more into C, so I can supe up my python programs

What projects should I do?
>>
>>52181217

That's not a python problem. That's a float problem.
>>
>>52181319
guess
>>
>>52181326
Mathematica returns correct values.

Wolfram language confirmed best language.
>>
>>52181217
lol, do even know how floating point numbers are stored in memory? you should have googled that before posting that bullshit
>>
https://better-dpt-roll.github.io/

I got 29. I'm going to try to finish it tonight.

>Cipher encryption/decryption tool
note: Implement at least one of Rumkin Collection: http://rumkin.com/tools/cipher
In cryptography, encryption is the process of encoding messages or information in such a way that only authorized parties can read it. Encryption does not of itself prevent interception, but denies the message content to the interceptor. In an encryption scheme, the intended communication information or message, referred to as plaintext, is encrypted using an encryption algorithm, generating ciphertext that can only be read if decrypted. For technical reasons, an encryption scheme usually uses a pseudo-random encryption key generated by an algorithm. It is in principle possible to decrypt the message without possessing the key, but, for a well-designed encryption scheme, large computational resources and skill are required. An authorized recipient can easily decrypt the message with the key provided by the originator to recipients, but not to unauthorized interceptors.
>>
>>52181336
>this math-based language which has arbitrary precision works right

Well, I guess it's time to rewrite the linux kernel in Mathematica.
>>
File: lolel.png (10 KB, 282x172) Image search: [Google]
lolel.png
10 KB, 282x172
>>52181318
muh design patterns n shit
that's why you need a language with built-in rational types, like lisp
>>
>>52181321

Go here: >>52181348

Roll and post results.
>>
>>52181352
>muh design patterns n shit

The real problem is that a pointer is created, but it's not actually pointing at a 'rat' object.
>>
>>52181348
rolling so I can leave this shithole, if only temporarily
>>
>>52181306
you sure you need that pointers?
if you really want to use pointers, `makerat` should return a pointer from (m)alloc. Also, whenever you allocate memory via alloc (and friends), be sure to free it.
>>
>>52181370
Fine, I forgot to use malloc.
>>
If you don't program in OCaml, you don't know SHIT about programming.
>>
>>52181382
>Your own small assembly language + VM for it
>bonus: and make a game with it
You're damn right I will
>tfw hopefully my practice making a VM for synacor challenge makes this more viable
>>
>>52181306
You're aware of that nifty thing called "reference", right? That's what you should be using.
>>
>>52181396
well, your struct is made up by two ints. thats a really small amount of data that even fits into a single cache line.

You can really avoid these pointers here, as the data is small.
>>
>>52181424
implying he's programming c++. Never head of C?
>>
>>52181396
>Fine, I forgot to use malloc.

You may as well have just returned the structs so they could be copied. No malloc.
>>
https://codeshare.io/rsqRX
Let's code some C together /g/
>>
>>52181442
The question is why ISN'T he programming C++? I don't even like it, I just happen to use it a lot. But it's certainly an improvement over C.
>muh elegance
C is anyhting but elegant, might as well completely dive in that shit called sepples.
>>
>>52181396
>Fine, I forgot to use malloc.

You should stick to babby languages.
>>
>>52181481
>requires 5 billion js scripts enabled
>>>/trash/
>>
>>52181488
well, there are a lot of use cases where C is just more fitting. Especially on smaller devices, arduino, microcrontrollers etc., C++s STL is often times to big and consumes to much memory.

It's very difficult to use an STL vector on a small microcontroller as the arduinos.

Also, C can be quite elegant, i'm sure you just have not seen any quality C code. If you you really want to see good C code, take a look at the kernel, or John Carmaks Quake/Doom code. It's really well written, easy to understand and elegant.

You just have no idea what you are talking about, kid.
>>
>>52181556

And if you want to see any bad C code, look at anything GNU.
>>
Just installed Debian. Only past experience with Linux was a free months of Arch and about a year of gentoo. Goddamn, Debian is comfy for programming. Such a painless setup too. I guess synaptics finally added support for my touchpad since I have proper multitouch which I never got working under gentoo.

All in all, I gotta say Linux is probably much easier to use than Windows now and approaching OSX levels.

I fucking love having a decent package manager and no circular dependencies.
>>
>>52181556
>One of the world's most famous C programmers can write elegant C
>Therefor C is elegant
>>
>>52181566
If you want to see sexy C look at openBSD.
>>
>>52181566
hmm... that's a lame argument for your point :(
(I agree at one point, GNU C CodingStyle sucks, but that's personal preference and does not have anything todo with the codequality)
>>
File: .jpg (48 KB, 540x447) Image search: [Google]
.jpg
48 KB, 540x447
>>52181556
>C++s STL is often times to big and consumes to much memory.
Don't use it then. The point of C++ is not in its shitty standard library. Richer syntax allows you to write more concise and fitting to your task code. The only things you'll miss is just some hacks like implied int, no need to cast pointers and zero size arrays(maybe it's still legal, didn't try).
>>
>>52181586
A lot of idiots can write ugly C code, even more idiots can write much more ugly C++ code.
>>
File: Y0UJC.png (208 KB, 680x880) Image search: [Google]
Y0UJC.png
208 KB, 680x880
>>52181601
>>
Threadly reminder that you should not refer to the act of programming as coding. It is improper and makes you look like a 15 year old

You are a programmer, not a coder
>>
feelio when enjoying coding
>>
>>52181583
Your in the wrong thread buddy, go blog somewhere else
>>
How do we fix C++, /gee/? My suggestions:
Remove #include and #define.
Forget STL and C libraries exist.
Add a module system.
Finally do something with that const faggotry.
Single root type system.
>>
>>52181661
i'm a hacker >:^)
>>
>>52181609
>and even more even stupider idiots can write even more ugly PHP code
do you have a point?
>>
>>52181350
inb4 Linux boots in 4 hours and integrates x^sqrt(x) wrong
>>
>>52181661

I'm actually a Pythonista. It's the only language I use and every other line in my code has cute Pythonic tricks.
>>
>>52181694
well, do you have?

Saying C is not, can not be, or only written elegant by the gods of programming is just naive. C is a rather small language, it's easy to understand.

Everybody can write good C code, if one is willing to put enough effort in it. But that itself does not make it elegant. People that write terrible C code does not make the language rubbish.

The whole discussion is pointless as the first argument is just silly.
>>
>>52181765
MTF are not welcome.
>>
>>52181684
Remove classes, RAII, STL, constexpr, smart pointers, auto, 99% of std::...

That's a good start I guess.
>>
>>52181765
that sensation when I am also a Pythonista

am I still one if I still use C and assembly?
>>
>tfw doing 128-bit calculations/bit manipulation in C.
>>
>>52181784
>Remove classes, RAII, smart pointers
Oh shit nigger what are you doing. Smart pointers pair well with shit like emplace.
>>
So is anyone here actually going to use Perl6 or is Perl a dead language?
>>
>>52181828
its not python XDDDD XDDDDDDDDD
>>
File: 1450369221617.png (80 KB, 694x732) Image search: [Google]
1450369221617.png
80 KB, 694x732
>>52181140
Who here has a degree
>>
File: .jpg (74 KB, 455x619) Image search: [Google]
.jpg
74 KB, 455x619
>>52181817
GNU Multiple Precision Arithmetic Library? Or something homebrew? If the former, I feel you
>library redefines allocators
>>
Good morning

I slept in again XD So lazy
>>
>>52181903
fuck off fucking idiot
>>
>>52181556
Bull fucking shit.

I used both the STL map and vector to log temperature data over a few days and neither the binary size nor the memory requirements were ever a problem.

The operator overloading and smart_ptrs alone are reason enough to abandon the antique dinosaur.
>>
>>52181891
hdip in software development and design

(fun () -> [1 .. 10] |> List.average)()
>>
Why do functions inside of functions exist in JS?
Why can't I statically define a type in JS?

Can I avoid this dynamically typed shit?
>>
>>52181891
Why would you use a lambda for that? I guess you can map lambda (x) : x/n where n is len(list) and then sum the whole (fold/reduce with (+)) but that's just stupid as you can divide the sum due to distributivity.
>>
>>52181911
No need for that.
>>
>>52181784
>remove things that dramatically improve program performance and safety in one fell swoop
OK kid.
>>
>>52181932
>Why do functions inside of functions exist in JS?
because first class functions are useful

>Can I avoid this dynamically typed shit?
TypeScript
>>
File: sicpIsEveryoneReady?.png (2 MB, 1920x1080) Image search: [Google]
sicpIsEveryoneReady?.png
2 MB, 1920x1080
>>52181891
I do
>>
>>52181916
To be honest, any inefficient collection is problematic only when it's created/used in a cycle. And std::vector doesn't do any checks in [] so usage overhead is very low.
>and it doesn't throw any exceptions, just loudly breaks everything
>>
I have learned some python and C

when do I begin making money
>>
>>52181891
List.fold x ~init:0 ~f:((fun l -> (fun p n -> p +. (float_of_int n) /. (float_of_int l))) (List.length x)) x
>>
>>52181891
(\ xs -> sum xs `div` length xs) [1..20]
>>
>>52181899
I'm writing my own stuff. Just need to add/xor/RoL/RoR some 0x10 byte keys.
Xor is done because its the easiest.
The ideas are there, its just a matter of putting it into code.
>>
>>52181932
>Why do functions inside of functions exist in JS?
Because it is a useful way to hide functions from the global scope. They exist in plenty of other languages.
>>
>>52181688
Remembered a few other things. Remove all "global" shit, it creates dependency on the order of declaration. Remove function prototypes. Give functions their own type, hell, just make them first class citizens.
>>
>>52182036
>hide functions from the global scope
that's what vtables are for
>>
My os is being a little bitch. I can either compile it successfully w/o a bootstrapping stack or the stack wigs out. I ended up using a modified crt{begin|end}.o just to get 64bit mode running. Can anyone help w/ kernel programming?
>>
>>52182103
I think you'll find JS does not support those.
>>
>>52182029
It's all done with shifting and masking. I did arbitrary precision stuff with that. Bit fields are useful too.
>>
>>52181688
>single-root type system
>ever
Absolutely disgusting.
Fix is easy:
-linear types with proof
-type inference
-complex typing with disjunction, conjunction, dependence, etc. (C++ already supports dependent types though)
-keep the ability to write embedded C in the same way that __asm blocks exist, no more. As you said, remove #include and #define and add a module system. Also add a competent macro system. Get rid of const, simply because it's literally too much work to track what is and isn't going to be const, which kind of const, etc. and it will change tons of times during development, rendering the whole thing useless. Use functional programming tactics instead.
>>
>>52182023
syntatic shit
>>
>>52181933
Because its useful if you dont iterate and program functionally.
>List.average
into the trash it goes
>>52182023
just why
(define (average lst)
(/ (foldr + 0 lst) (foldr (lambda (x y) (+ 1 y)) 0 lst)))
>>
>>52181817
I made a bit manipulation library that handles an arbitrary number of bits a while back. I think I got most bit manip ops working up to about 1Gb If you'd think it be of any use I could host it somewhere.
>>
>>52182144
Also important:
-first class functions
I think that's it.
>>
>>52182103
>vtables
not the same thing.
>>
>>52182138
Enjoy your 0 portability.
>>
>>52181891
avgList xs = uncurry (/) $ foldr (\x y -> (x + fst y, 1 + snd y)) (0,0) xs
>>
>>52182133
what about function pointers?
>>
>>52182144
Single root type system fits better with the whole Oh Oh Pee theme of sepples. And do you think your solution will work good with template's duck typing?
>>
>>52182194
Do you even understand the "hide from scope" thing? It's done to not breed on-time helper functions.
>>
>>52182194
references yes. pointers, no.
>>
>>52182201
Only because of the crap simula-style OO and even then, not really because of multiple-inheritance such that a top-level interfaces model would fit better.
Also, templates are strongly-typed, with inference.
>>
>>52182226
Don't make helper functions then.
Write the whole thing as 1 function.
>>
>>52181370
The problem could be fixed by just writing "rat *res = new rat();" Right?
If not, please elaborate.
>>
OOP is better than x
>>
>>52182256
>not knowing many JS projects actually write everything inside a single function
>>
>>52182274
Wayland is better than OOP
>>
Rely on erlang, better bit manip.
>>
alright which one of you faggots has the multiple cursors in codeshare?
>>
>>52182265

Yes, but considering it's C, it'd be malloc. That or declare it on the stack and return it (which will result in it being copied on return).
>>
>>52182253
Wait, you haven't seen this shit?
http://ideone.com/izvfdY
>>52182256
Kill ur whole self.
>>
>>52181217
Lel, K tard
>>
>>52182350
I've no much experience with C, i jumped right into C++.
Thanks tho.
>>
>>52182379
>not writing C with classes
ktard
>>
>>52182158
It might help. I have my keys stored as uint8_t* and im just having a hard time visualizing this. I could probably parse each bit and simulate binary addition and such, and carry, but that sounds pretty slow.
>>
>>52182265
Rewrite that shit from scratch using move-semantics.
>>
>>52181140
in java, what is an alternative if I want to make an if/else statement that compares two strings?

I have an enum class named "Weapons". But java is telling me I can't use the '==' and '| |' operands with strings. What is the alternative for strings?

public void setWeapon(String weapon1) throws WeaponException {
if(weapon1 == Weapons.Rifle || weapon1 == Weapons.SMG)
this.weapon = weapon1
else
throw new WeaponException("Weapon not found.");
>>
>>52182435
.equals()
== does jack shit in Java.
>>
>>52182353
That's why you need real type inference instead of the shoehorned template-based one.
>>
>>52182435

You use .equals for strings.
>>
>>52182408
Please read my post again. I rarely write C, and prefer C++.

>>52182430
I'm not the guy posting the code. I was just curious.
>>
>>52182435
weapon1.equals(Weapons.Rifle) 

i think thats the way to go, either that or .contains
Your logical or '| |' should be alright though
>>
>>52182459
>>52182452
thanks
>>
>>52182459
disgusting, man Java is inferior to C# in every way
>>
>>52182482
>>52182459
>>52182452
thanks
>>
>>52182435
>Weapons
Why is the the enum made of strings? Why not ints? Do enums need to be reference types in Java?
>>
>>52182435
String comparison is inherently inefficient because you have to compare the entire string if it's a match.

Never use string comparison unless there's no other way around it. Strings should more or less only be used as labels or plaintext.
>>
>>52182500

Precisely.
>>
>>52182523
what would a better way be to write it so that when a user inputs a weapon type that doesn't exist it throws an exception, without comparing strings, then?
>>
>>52182539
use ints. then
if(weapon1 == Weapons.Rifle || weapon1 == Weapons.SMG)

Should work, afaik
>>
>>52182539
>user inputs a weapon type
Depends on what "input" is.

If you're using a real GUI framework, you can use an input field such as a drop down box to forcibly limit the possible inputs. Each element in the drop-down box would refer to an integer-based enum, but display a string.

If you're forced to use text because you're using the console, then string parsing is the only thing you can do. That doesn't mean you can't immediately parse it into an integer-based enum though.
>>
File: perfection.png (17 KB, 900x900) Image search: [Google]
perfection.png
17 KB, 900x900
I just finished the first version of my show reel circle drawing algorithm

Quality should be higher than 256x MSAA
And I can draw 12,000/s of those on the average Core i5
>>
>>52182523
Doesn't java store all strings in a map to avoid duplicates and only compares the inner pointers ? (Thanks to string constness)
>>
>>52182631
post code
>>
>>52182631
And yet the flatter angles still have aliasing.
>>
>>52182619
>Each element in the drop-down box would refer to an integer-based enum, but display a string.

Most drop-down boxes already work like that, with .index & .value or something similar. Those return the index and string value, respectively. I forget what it is for Swing, but that's the gist of it.
>>
>>52182640
If that were true then
String fgt = "fgs";
String fgt2 = "fgs";

fgt == fgt2 would return true if what you're saying is actually how it is.
But no, it will always return false because fgt and fgt2 are two different objects with two different pointers.
>>
>>52182644
I don't think you know what the term means

>>52182640
I rather doubt that.
>>
>>52182670

Lad, I have some bad news...

https://ideone.com/VLqaFf
>>
>>52182670
>But no,
I seriously fucking hope
>>
File: Untitled.png (2 MB, 1578x592) Image search: [Google]
Untitled.png
2 MB, 1578x592
>>52182671
nigga I know what aliasing is
Maybe you think that "blurry edges" are "antialiased", but in reality there is always a degree of aliasing.

The flatter angles of your circle, on the top, are heavily aliased compared to the rest.
>>
File: dogshit.png (27 KB, 975x455) Image search: [Google]
dogshit.png
27 KB, 975x455
>>52182631
looks like shit
>>
>>52182423
I believe I also used int8_t's but I would revise them to int32_t or int64_t as those are handled much more efficiently on 32/64 bit architectures.
>>
>>52182694
holy fuck shit, Java is garbage:
https://ideone.com/09sao6
>>
>>52182751
that just cause the Java compiler recognizes they are the same constant string, so the compiler makes both variables refer to the same string. It is an optimization.
>>
>>52182751
>Java is garbage
Woah, I don't even like Poo in Loo, but that output is expected. It stores "fg" and "fgs" for optimization
>>
>>52182709
they look the same
>>
>>52182795
:^)
>>
>>52182643
It's too large to post
I'll publish it when I get around actually making a show reel

>>52182644
Well, there will always be some aliasing on displays using pixels
>>
>>52182670
No for multiple reasons. Java only has data types and == only compares those. In your example, you are comparing two references but a difference between pointers and references is that two references pointing to the same object are not necessary equal. I said inner pointer, two different strings objects can share the same characters array.
>>
I have been fucking around with Rust. The Cargo system is fucking wonky, so if one wants to do the same as this:
gcc -c source.c


In Rust, it's like this:
rustc --crate-type lib --emit obj source.rs


Not doing the --crate-type lib part actually seems to generate a .o file that contains absolutely nothing, even when the function is declared pub.

And after some experiments with this, I have discovered that it does, in fact, use the same register calling conventions as C... at least on x86-64 Windows.
>>
>>52182783
>It is an optimization.
It's an optimisation that affects how code will behave depending on whether or not the compiler made the optimisation or not. To discuss Java is to learn something new and terrible about it. Fuck me.
>>
>>52182794
>but that output is expected
No it's fucking not. Is 1+2 not expected to be 3 because 1 and 2 are stored separately? Aren't you just pulling it out of your ass now?
>>
>>52182803
seriously, there's 0 difference in quality and even if there was some slight difference that's supposed to be shown, it's not noticeable at all
>>
>>52182435
>java
>>>/trash/
>>>/out/
>>
>>52182813
>two references pointing to the same object are not necessary equal.
huh? when would they not be equal, and why?
>>
>>52182709
I'm not who you responded to, but I'm not using any blurring on my circle borders
My output should be the same as sampling 256 points inside a pixel
>>
>>52182828
>affects how code will behave
Not really, it's pretty much a read-only optimization, but it's an optimization at least. Try to change one of the variables and see what they are after. Whether or not the compiler made the optimization does not change the behavior

>>52182831
It's expected given how Java operates
>>
>>52182826
>it does, in fact, use the same register calling conventions as C... at least on x86-64 Windows.
Lots of things do. I've been sending a C# lambda as a callback to a C dll. It just werked.
>>
>>52182856
Mutability is one reason.
>>
>>52182751
Meanwhile with real languages:
https://ideone.com/eQfTGB
>>
>>52182883
>Not really, it's pretty much a read-only optimization
yes really, the outputs of my program would be different depending on whether or not the optimisation was made.

>Try to change one of the variables and see what they are after.
The fuck does that have to do with anything?

Javafags don't even understand why their langugae is shit. What else is new.
>>
>>52182828
>implying Java is the only compiler to do these sort of "optimizations"
>>
>>52182883
>It's expected given how Java operates
Explain this:
https://ideone.com/zI6SU4
>>
>>52182913
please explain.
>>
>>52182937

weed lmao
>>
anyone here have any experience for simulating mouse control using c#, i've been trying to simulate dragging the mouse from one location to another for maybe a day and a half of occasional changing and nothing i'm doing is working

mouse click is fine, ctrl or shift + click is fine, but no matter what method i use for dragging, the program im trying to drag will not recognize it

ive used SendMessage and PostMessage and mouse_event to send the left click down, and have used multiple methods to move the cursor to the destination like SetCursorPos or setting Cursor.Position, but absolutely nothing is actually registering the mouse being dragged
>>
>>52182950
import pyautogui

https://github.com/asweigart/pyautogui
https://pyautogui.readthedocs.org/en/latest/
>>
>>52182923
>yes really, the outputs of my program would be different depending on whether or not the optimisation was made.
Give an example scenario then.

>The fuck does that have to do with anything?
Read above. They point to the same string, and there is no difference if it pointed to different strings, because if you only change 1, only that changes, it points to something else. It's a read-only optimization

>>52182937
You are comparing strings using ==. Optimization means that different pointers will point to the same strings, but the fact of the matter is when it comes to string comparing, you are supposed to be comparing their value, unless you're new to programming
>>
Oh no, it's retarded.
https://ideone.com/U1CKea
>>
>>52182934
not at all. stay salty
>>
>>52182982
> using c#
>>
>>52182982
https://pyautogui.readthedocs.org/en/latest/mouse.html#mouse-drags
it jus werks :^)
>>
>>52182982
>python
>>>/trash/
>>>/out/
>>
>>52182937
>https://ideone.com/zI6SU4
Java compiler probably has an optimization where two strings being appended are appended at compile time
"fgs" == "fg"+"s"

becomes
"fgs" == "fgs"

now they are same constant string.
>>
>>52183001
not my fault you want to make things hard on yourself
>>52183007
>language wars
>>>/trash/
>>>/out/
>>
>>52182996
>Give an example scenario then.
https://ideone.com/09sao6
yes, some random retarded piece of code in a 300,000 line code base could have something like this and break because the compiler changes. Fun stuff.

>They point to the same string, and there is no difference if it pointed to different strings, because if you only change 1, only that changes, it points to something else.
And they don't point to the same string if the optimisation is not made. How about that?
>>
>>52183019
changing everything i've used to python would "make things hard on myself", my program does more than drag ...
>>
>>52183029
Holy shit, you're retarded

In any language that does not do the optimization, you will get a False every time you use ==. If you are telling me you rely on False, the same exact bool everytime, returning, that you do string checks using == in other languages, you are retarded.

In Java, the behavior is expected because it does the optimization. If you get False everytime, that means that the compiler doesn't optimize. If you are telling me that someone is going to rely on string comparing, but only in Java, then they are buttfuck retarded, because if they do the same in other languages, they would get just as useless information
>>
File: 1430047930651.jpg (36 KB, 480x360) Image search: [Google]
1430047930651.jpg
36 KB, 480x360
>optimization and compiler specific behavior
Truly the pinnacle of engineering.

And then somebody actually even defends that garbage.
>>
>>52181891
I don't.

I'm still a full time Web Developer though.
>>
>>52183090
Shitposting aside, though, == is a primitive type comparator. The primitive type of string is "pointer". The primitive type of an Object instance is "pointer". The primitive type of an int is "int".
>>
>>52183071
>If you are telling me you rely on False, the same exact bool everytime, returning, that you do string checks using == in other languages, you are retarded.
Yes, that would almost certainly be poor code. Yet it might be in some part of my code base, maybe written by an intern, maybe part of some library i pulled in the source for. My point is that code shouldn't break just because some compiler optimisation was turned on or off.

>because if they do the same in other languages, they would get just as useless information
Works fine in C#. Not that a Java advocate would know. Typically Java advocates who are significantly familiar with how C# works, don't use Java anymore.
>>
>>52183090
nice meme post, but you should really study programming more so you know how strings operate and what == does
>>
Just remember that there's no operator overloading in Java so don't use == on anything but primitve types.
>and then there's + for String concatenation
Just burn that shit down, ugh.
>>
>>52182941
You can not mutate references in java but what I mean is
object foo = new object ()
reference a = new reference (foo)
reference b = new reference (foo)

a == b // false
*a == *b // true

reference c = a
a == c // true

a.referTo (new object ())

*a == *b // now false
a == c // still true


Mutable references are like double pointer
>>
Is there any real reason for Java to even allow pointer equality comparisons? You'd think that causes a lot more problems than it helps, and Java has already thrown so much out the window for "safety" reasons...
>>
>>52183128
>Yet it might be in some part of my code base, maybe written by an intern, maybe part of some library i pulled in the source for. My point is that code shouldn't break just because some compiler optimisation was turned on or off.
Your code would break just the same in any other language, because comparing strings using == will NEVER compare by value, unless the language actually does compare by value

>Works fine in C#
So an example of something that compares strings by value then, ok.

>Java advocate
It's funny that you keep calling me that. I use Java, but I hate it with a passion, but not even I'm retarded to not know how strings work
>>
>>52181891
>tfw python cripped lambda
lambda x: sum(x) / len(x) 
>>
>>52183158
Yes. Optimization is one reason.
>>
File: 4413246790_da5f8b7e68.jpg (66 KB, 312x312) Image search: [Google]
4413246790_da5f8b7e68.jpg
66 KB, 312x312
>>52183184
>>
>>52183169
>but not even I'm retarded to not know how strings work
I know exactly how string work and have demonstrated as such. What I'm saying is simple:

Compiler *optimisations* should not change the behaviour of code. I should not have to worry about my code no longer working when I change from one completely standard compliant compiler to another. Is that unreasonable?
>>
>>52183158
Yes. When you work with singleton or singleton-like patterns, == is a fuckload faster than equals and just as accurate.
>>
>>52183224
Congrats on your continuous success in demonstrating your awe-inspiring cluelessness.
>>
>>52183198
It just doesn't make sense to me that they leave in this tiny opportunity for optimization, which is very easily misused, while they completely baby the programmer at the expense of large swathes of significant optimizations elsewhere.

>>52183232
I suppose so, but fuck me if I'd ever be comparing two references to the same singleton object.
>>
>>52183224
>and have demonstrated as such.
Yes, great work demonstrating comparing strings fucking retard
>>
>>52183150
I'm really not sure what you mean. References is Java are value types. They go directly on the stack, or inside objects. So when you compare two of them, if they point to the same thing why would they have a different value ever? They are double pointers sure, but why would two references pointing to the same object be pointing to different pointers pointing to that object?
>>
>>52183251
>>52183262
>I can't respond to his point. I'll just insult him instead. That will show everyone I'm right.
>>
>>52183252
>but fuck me if I'd ever be comparing two references to the same singleton object.
Then go back to your fizzbuzz since that's all you do all day.
>>
>>52183232
>singleton

/!\ Meme pattern alert! /!\

http://gameprogrammingpatterns.com/singleton.html
>>
File: tumblr_nmhpghhZQK1rg3vrmo1_500.jpg (75 KB, 500x375) Image search: [Google]
tumblr_nmhpghhZQK1rg3vrmo1_500.jpg
75 KB, 500x375
>>52183251
>>
>>52183296
Nice meme.
>>
>>52181583
>debian is comfy for programming
>compared to gentoo
maybe I'm just biased because of the kinds of programming I do, but Debian has always been a bitch for me to get dependencies working on, and I'm saying this after using both Debian and Gentoo for all my programming for the past year or so.
If you're trying to do anything with really recent dependencies on Debian you'll not only have to compile the packages, but also compile them without a package manager to help you through it. Even if all the latest versions of all the packages you want are on testing or sid, it's still a huge inconvenience to deal with broken updates or packaging bugs and I've found apt to be very prone to breaking at times where it'll just give up on fixing dependencies (especially when you've had to compile certain libraries). Having to stay in sync with the current release is a nightmare, but my biggest problem is probably the fact that I miss out on the convenience of overlays and all of the more advanced options in Gentoo like USE flags.
>>
File: 404.png (247 KB, 498x481) Image search: [Google]
404.png
247 KB, 498x481
I'm trying to troubleshoot an angularjs 404 error that is currently happening with a live site. The live site is a bit of a mess. My real job is working on developing a new site for them. While I was working on the new site it became apparent that their SSL certificate wasn't installed properly. Once that started working, making the same node request that worked before is suddenly turning out a 404 error. I'm pretty new to Angular. I understand how it is all based on nodes and ajax requests. What I am confused about right now is what happens after the open() ajax request is sent? I can see the url path that is being sent and it is the same for both the http and https requests '../Su6UsWuf/bb/option/mfg/all' Why am I getting different responses?
>>
>>52183287
Maybe try starting your post with truths
>I know exactly how string work and have demonstrated as such.
No you clearly don't, because you think comparing strings using == in a language that compares strings by reference will bring you any meaningful information that you have stated, multiple times, as potentially breaking your code. It would break the code just as much as it would in any other language that returns False everytime, because it's not desired behavior
>>
>>52183158
Here a c++ examples
struct Foo {
int a;
int b;
}

book equals (Foo *x, Foo *y)
{
return (x == y) || (x->a == y->a && x->b == y->b)
}
>>
>>52181661
What about "developer"?
>>
So, what have got? Java stores string literals in the string pool. Any explicitly allocated strings aren't stored there. "a"+"b" is apparently "ab", but if you try that with objects it apparently isn't. == is a reference comparison, not value. Conclusion: read the compiler warnings, == on strings is one.
>>
>>52183345
Developer is fine.
>>
>>52183348
>it apparently isn't
exactly. The code isn't going to test run the program to see what object values turn out to be
>>
>>52181891
I do, but it certainly isn't related to computer science or programming in any way.
>>
>>52183287
>C is garbage because when I printf("%p", malloc(1)); it prints different values depending on compiler, OS, or EVEN ON DIFFERENT RUNS!!1111
>>
>>52183266
I am talking of reference, the concept, not of java reference. Java reference are immutable and transparent.
>>
File: fake ball prank.gif (4 MB, 320x240) Image search: [Google]
fake ball prank.gif
4 MB, 320x240
/dpt/ official guide to using singletons:
don't
>>
>>52181140
what was even the point of this character? wakaki goes to so much trouble to flesh out this new girl in the past arc, only to completely forget she exists when the story shifts back to the present. jesus fucking christ twgok's ending was terrible
>>
What are the reasons of using a singleton over a static class?
>>
>>52183158
Yes, there is some use cases, sometimes you need to know if two objects refer to the same object, not just have equivalent values.
>>
>>52183395
It's pretty much the most avoided, discouraged, disliked design pattern out there. People only recommend using the one that is a singleton by default, which is typically the main() file.
>>
>>52183395
No one here writes code that anyone else has to look at, so they just blindly hate design patterns. Don't take programming advice from here.
>>
>>52183403
>>>/a/
>>>/trash/
>>
>>52183158
To check for null refetence
>>
>>52183408
consult the guide, it's very clear in the matter
>>52183395
>>
>>52183335
>because you think comparing strings using == in a language that compares strings by reference will bring you any meaningful information that you have stated
I'm not sure what you mean by meaningful information.

>as potentially breaking your code
Yes, I'm still 100% correct on that, depending on weather that optimisation is made. You seem to agree it will break the code. I think it is bad that it will break the code. Do you disagree? And why?

> It would break the code just as much as it would in any other language that returns False every time
Of course it won't. What kind of logic is that? If that "optimisation" is actually part of the spec and the compiler MUST implement it, then it's not so bad. But not intuitive imo. If it always returns false, that's more intuitive to me personally, and the compiler can certainly put one real string on the heap and pretend both references point to different objects for the sake of consistency. But what's important is it behaves the same whether or not optimisations are on. Agreed?
>>
>>52183422
Design patterns are very useful, especially in game dev

Singletons, though, are largely hated by audiences of any kind
>>
Using anything just because it is a "design pattern" is retarded.

Design patterns are for studying and explaining code, not writing it.
>>
>>52183375
>C is garbage because
That's expected of C because it is a low level language. But generally one of the most despised aspects of C is all the undefined behaviour that varies between compilers. So yeah, thanks for helping me make my point.
>>
File: gray_circles.png (493 KB, 1750x900) Image search: [Google]
gray_circles.png
493 KB, 1750x900
Are these artifacts normal?
>>
>>52183395
you just wanted people to talk about your gif you fucking fag
>>/trash/
>>
>>52183224
>I should not have to worry about my code no longer working when I change from one completely standard compliant compiler to another. Is that unreasonable?
If your code relies on non-deterministic behavior, then yes, that is unreasonable.
And it doesn't even have to be optimization, just a different run or version of the runtime could change the addresses of the strings.
>>
>>52183389
this post >>52182813 was talking about java references. Java references are mutable.
>>
>>52183446
>I'm not sure what you mean by meaningful information.
Information you believe to break your code in some way, or information that, because of optimization, will cause you great distress

>weather

>You seem to agree it will break the code
Your reading comprehension is lacking. It would only be detrimental if you relied on comparing strings using ==. Do you rely on comparing strings using == in other languages that compare strings by reference? If so, for what reason? They are all False.

>If it always returns false, that's more intuitive to me personally
It's intuitive that you have a basic understanding of how pointers work?

>But what's important is it behaves the same whether or not optimisations are on. Agreed?
And why is it important to you? The ONLY way in which this could be important to you is if you rely on == for strings
>>
>>52183408
Yes. In the singleton you can do (pseudocode)
Def new ()
if !instance
If debug
instance = new Debug implementation
else
instance = new ReleaseImplementation

return instance
>>
>>52183479
>But generally one of the most despised aspects of C is all the undefined behaviour
Undefined behaviour is what made C as fast and portable as it is. Implementation defined behaviour is the pesky one.
>>
remind me what a singleton in java looks like
>>
>>52183485
You trying to give me a fucking seizure?
>>
File: lemon facts.png (411 KB, 490x333) Image search: [Google]
lemon facts.png
411 KB, 490x333
>>52183422
updated guide as per this anon's request:
Note: "If you have to read the guide, " ... is implied at the start of every answer
>Should I use a singleton?
No
>Should I read this guide?
No
>>
>>52183534
>doing debug/release with subtype polymorphism and not generic/template polymorphism or even fucking preprocessor branching
>>
>>52183512
The data type holding the reference is mutable. The reference itself is not. That's why java reference are transparent
>>
>>52183503
>If your code relies on non-deterministic behavior, then yes, that is unreasonable.
There shouldn't be nondeterministic behaviour. Especially not in something as basic as this.
>just a different run or version of the runtime could change the addresses of the strings.
the address doesn't matter. They just shouldn't be made the same thing when i defined them as separate entities. I shouldn't have to be aware of potential optimisations, that shit should be completely transparent.
>>
>>52183553
Very interesting lemon fact.
>>
>DPT hates singletons
>DPT loves llvm/clang
>DPT keeps praising its code
>mfw everything in llvm/clang is a singleton
>no fucking face
>>
>>52183537
I don't disagree.
>>
>>52183534
>branch on every new call

JUST
>>
>>52183576
>/dpt/ is one person
>>
>>52183558
>java
>preprocessor
OK tard.
>>
>>52183485
It's a moire pattern. Git gud nigger, and apply a gaussian filter.
>>
>>52183485
It's a combination of these three things
https://en.wikipedia.org/wiki/Illusory_contours
https://en.wikipedia.org/wiki/Aliasing
https://en.wikipedia.org/wiki/Moir%C3%A9_pattern
>>
>>52183569
>The data type holding the reference is mutable.
that data type is called a "reference". get it? in what sense is the reference not mutable?

You might as well say ints are immutable in java but the data type holding an int is mutable.
>>
>>52183570
You don't have to be aware you dumbfuck. You could have lived the rest of your life not knowing that compiler optimization is a thing that happens, and you would never have noticed a difference, in any language. You just want to be a purist turbo autist, who thinks everything has to be black and white because your mind can't comprehend it
>>
>>52183587
Given that not a single person has yet given a contrary opinion to these consensi, yes.
>>
>>52183485
looks fine to me.

>using a 1080p monitor running @ 1366X768
>>
I don't compile any code until I've written a compiler myself. Much like I don't write any graphics code until I've hand implemented every single library that may be required.
>>
>>52183184
>not taking into account that you will have int divided by int truncating precious values

faggot

 lambda x: sum(x)/1.0/len(x) 
>>
>>52183633
where do I cancel my subscription to this blog post?
Thread replies: 255
Thread images: 22

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.