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

What are you working on, /g/?
>>
first for cute boys
>>
File: 145019686915133928.jpg (30 KB, 549x250) Image search: [Google]
145019686915133928.jpg
30 KB, 549x250
What are some ways of encrypting a program with your CPUID and decrypting it on the fly?
>>
>>52080438
encrypt the entire resident memory block allocated to your application
>>
>>52080438
If you're asking about how to implement a Denuvo-style executable packer....
>grab UPX source code
>modify it to retrieve a CPUID, convert it to a binary string and store it in a temp variable
>change the UCL algorithm code to use the temp variable
>compile source code
>pack the executable
Congratulations, you now have a Denuvo-style executable sans the 64-bit Virtual Machine implemented from VMProtect code that encrypts it further.
>>
Who is learning D this Christmas?
>>
>>52080680
oh yeah, I also forgot
>make the UCL decrypt-on-fly code to also grab your CPUID instead of hardcoded shit
to make sure this will only work on your computer and yours alone
>>
>>52080690
that's gay
>>
>>52080378
reading C++ Primer Plus 6th edition then going to try and read a book on DS&Alg and then read a book on design patterns and then apply for C++ software dev jobs.

Just got a math degree and realized I don't want to do data mining work anymore.
>>
Which is real thread?
>>52080391
>>52080378
>>
File: awoo2.png (1 MB, 1072x1273) Image search: [Google]
awoo2.png
1 MB, 1072x1273
I don't understand the symbols being used in Introduction to Algorithms.

What are they for?
>>
>>52080824
Which symbols?
>>
>>52080821
this one
>>
>>52080824
Anyone who posts with anime pictures will be unable to understand them, I'm afraid.

Perhaps you'd be better suited for something such as understanding the dichotomy between reality and fantasy over at >>>/mlp/
>>
>>52080888
euphoric
>>
>>52080838
the triangles, the U, left U, right facing U, upside down U, and the O with the stick going through it.
>>
>>52080960
https://en.wikipedia.org/wiki/List_of_mathematical_symbols
>>
Why do people recommend that you separate the rendering from the update/tick function?
My CPU usage went from 100 % to 30% when I started only rendering surfaces when I needed to.
>>
Can window.onload be used inside of jquery's $(document).ready(...) ? ( I am not talking about $(window).load).
>>
I'm porting a piece of software from Windows to Linux and I'm having some difficulties.

It was written in Qt/C++ so a lot of it just works but one of the header files calls "Parser.hh" which doesn't seem to exist. Not including it causes everything to break. Is this an actual, known header file or is it just something that the original dev forgot to include in the source he uploaded?
>>
File: Bridget.png (671 KB, 761x899) Image search: [Google]
Bridget.png
671 KB, 761x899
I'm working on a very basic mastermind algoritm on JAVA.
Without changing the code too much, how can I default the number outputed by each random to 0 in its spot.
package javaapplication14;
import java.util.Random;
import java.util.Scanner;


/**
*
* @author ultimateon
*/
public class JavaApplication14 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int mstrmind_random0,mstrmind_random1,mstrmind_random2,mstrmind_random3, input1,input2,input3;
int end;
Scanner keyboard = new Scanner(System.in);
Random random = new Random ();


do {
mstrmind_random0 = random.nextInt(10);
mstrmind_random1 = random.nextInt(10)*10;
mstrmind_random2 = random.nextInt(10)*100;
mstrmind_random3 = random.nextInt(10)*1000;
System.out.println(mstrmind_random0+mstrmind_random1+mstrmind_random2+mstrmind_random3);
end = keyboard.nextInt();
} while (end > 0);




}

}
>>
>>52082500
Because it sometimes doens't output 4 numbers because of it being 0
 
2546
1
284
1
4227
1
6480
>>
>>52082500
>>52082512
It was REALLY difficult to understand your question, but I finally got it. Is english your first language?

random.nextInt(10)
should be
(random.nextInt(9) + 1)
>>
>>52082539
It isn't but I have a hard time explaining my thinking process when programing.
Lets see what happens when we add this then.
>>
>>52082555
>>52082539
Its not printing 0, forgot to mention the number interval has to be between 0-9
>>
>>52080378
Please stop this programming trap meme.
Thanks.
>>
Is there any decent debugger for python?
>>
>>52083288
If you're not using any IDE, try pycharm. If you're a console person, google "pdb". My pythonfag friend says that it's the best shit for python.
>>
Is there a better way to see if a number is whole or not (in C#; Visual Studios)?

bool isWhole(double test)
{
int conv = Convert.ToInt32(test);

if (test > conv || test < conv)
{
return false;
}
else
{
return true;
}
}

>>
>>52083587
It can potentially return false even with actual whole numbers.
>>
>>52083587
Not sure if "whole" is a concept that makes sense for computer floating-point numbers. Maybe you can use fmod and do an epsilon comparison on the result.
>>
>>52083660
In what case?
>>
>>52083700
Loss of precision.
>>
>>52083587
return ((double) (int) test == test);
>>
>>52082158
Parser.hh sounds like it could be a file generated by a parser generator like lex/yacc. If that's the case you'll need to figure out where/how it's getting generated on Windows, and then do something similar on Linux.
>>
>>52083816
That's invalid. % only works on integers, not floats.
>>
File: 4chpython.jpg (115 KB, 969x844) Image search: [Google]
4chpython.jpg
115 KB, 969x844
It's all going to shit mates, I had to put some checkers in to make sure 4chan is actually online. It went down for a few minutes the other night which obviously caused the whole script to shit itself.

So I added a checker at the start to query 4chan.org for a 200 result, along with more board validation as it was originally taking upper case letters and attempting to load a board with G in the url which obviously wont work.

it also now detects if a thread has no replies and automatically loads the next thread instead but therein the whole script has fallen apart.

I started writing some code the other night when I was very tired and now the while and for loops I'm using to load replies and threads is all mixed up. When you want to see more than one reply to a thread it keeps giving the same reply over and over and will eventually kick you out to the thread listing again.

I tried to rectify that by changing one of the for loops to while but then when asking for one reply to a thread the while loop dumps the entire contents of the thread and proceeds to crash the script afterwards.

I wanted to get to work on a numpy image viewer but I have to iron all of this stuff out first. Still interested in learning python though which is the main thing I guess

http://pastebin.com/Y8cEpBUU

Here's the source but it's not much to look at at the moment, it needs a lot of cleaning up
>>
>>52083926
Yes, good idea, fmod returns a double, and it's pretty smart to compare a double to 0.
>>
>>52083857
make it download images from threads into a folder
>>
>>52084105
You're a dumb fuck.
>>
>>52080851
but only cuties allowed
>>
New to programming, going to do the SICP, is it recommended to use the lectures too? I'd prefer to only read through it but if it's worth it might as well.
>>
>>52085304
K I L L Y O U R S E L F
I
L
L
Y
O
U
R
S
E
L
F
>>
a % 0 = a
>>
>>52085640
a = 0 and you need to do your own homework.
>>
>>52085663
0 % 0 = 0
>>
File: rxvt-unicode-256color_054.png (152 KB, 1269x1044) Image search: [Google]
rxvt-unicode-256color_054.png
152 KB, 1269x1044
>>52085671
Yep.
>>
>>52085640
That one guy knows it's shit.
>>
>>52086656
s/it's/its/
>>
>>52083718
If you're losing precision that easily you wouldn't even bother checking something like this.
>>
>>52083587
bool isWhole(double test)
{
int conv = Convert.ToInt64(test);

return test == conv;
}
>>
>>52083722
>>52086732
doubles can hold larger integers than ints you dickbutts
>>
>>52086803
>int conv
should be long conv or whatever it is that you have in C#
>>
>>52086823
How does your post relate to this post >>52086732 at all?
>>
>>52086847
i dunno but it can also return false on int overflow which was my main point.
>It can potentially return false even with actual whole numbers.

>>52086732 has a point though i will admit
>>
Just finished testing my OOP implementation for C. Inheritance, abstract classes, interfaces, virtual / abstract functions, etc. Everything works better than expected.
>>
>>52085273
Some people only read the book, but most people have recommended to me to watch the lectures, as well as, read the chapters.
I just started reading too and watched the first lecture as well as read the first section of chapter 1 and there was some interesting things that were said in the lecture that helped me get rid of some of the confusion I had with LISP.
>>
>>52086999
I hope it's taught you that OOP shouldn't be used as a basis for everything, like certain languages promote.
>>
>>52082137
stackoverflow.com will know.
>>
59th for Go
>>
can /dpt/ calculate the average of two ints in C?
>>
The world needs more irc bots, right? Because I'm just getting started writing one in racket.

Right now it just prints everything it gets from irc server to stdout with different formats depending on what type of message it got. Next up is the framework for writing commands and the system that keeps track of which users have permission to run which commands.
>>
>>52089234
It is literally impossible to average two ints in C.
>>
>>52089234
define average
>>
>>52090000
6' is average height
anyone below this is a manlet
>>
>>52090031
>feelsbadman.jpg
>>
>>52089900

#define avg(a,b) ((a<0)^(b<0) ? ((a+b)/2) : ((a/2)+(b/2)+(((a%2)+(b%2))/2)))
>>
>>52080378
fuck off weebfag
>>
>>52089900
No it isn't, you idiots like to make up arbitrary rules for averaging ints and when someone makes a function to suit your arbitrary rules you make up new arbitrary rules.
>>
>>52090161
>implicit type conversion
>overflow
>underflow

kill yourself
>>
Hey /dpt/ just wanted to post about this amazing course on debugging: https://www.udacity.com/course/cs259. It's seriously blowing my mind with how simple and powerful this stuff can be, i'm really excited.
>>
>>52090224
What the fuck is he even talking about anyway? Is this averaging int thing a new /dpt/ meme? Sorry it's been a while since I visited
>>
y. F# computation expressions provide uniform syntax
that supports monoids, monads [23], monad transformers [11] and applicative
functors [14]. They reuse familiar syntax including loops and exception handling
– the laws of underlying abstractions guarantee that these constructs preserve
intuition about code. At the same time, the mechanism is adaptable and enables
appropriate syntax depending on the abstraction.
Most languages, including Haskell, Scala, C#, JavaScript and Python have
multiple syntactic extensions that improve computational expressivity: queries,
iterators, comprehensions, asynchronous computations are just a few. However,
2 Tomas Petricek and Don Syme
“syntactic budget” for such extensions is limited. Haskell already uses three notations
for comprehensions, monads and arrows [16]. C# and Scala have multiple
notations for queries, comprehensions, asynchronicity and iterators. The more
we get with one mechanism, the better. As we show, computation expressions
give a lot for relatively low cost – notably, without resorting to full-blown macros.

>F# computation zoo
>>
>>52090195
:^)
>>
>>52090276
Pretty much. They'll say avg two ints. You make a function that averages them but then they say to round to even numbers. You do that and then they say only round to even numbers sometimes. Eventually the function gets so convoluted with their arbitrary rules that they say "C can't average 2 ints".
>>
>>52090234

>implicit type conversion
I think you'll find that the type here doesn't matter as long as the type presented is of an integral type.

>overflow
>underflow
If both a and b are of the same sign, then the condition (a<0)^(b<0) is not met, and the fallback method is used. Here, both numbers are divided by two before summing, therefore restricting to a subset of their own integral types, whereby a sum of those two integers will not exceed the minimal or maximal values for their respective types. A correction value is then added, but this is only to correct loss from integer division. If we were to try to average 2147483647 with itself, we would end up with 1073741823 + 1073741823 + 1 = 2147483647.

Yeah, I'm not the best at writing proofs, but I dare you to poke a hole in that.
>>
>>52080378
mcfucking kill yourself

>>52086042
>>
>>52080378
I'm looking any excuse for procrastination, my code is a messy piece of shit and can't read it anymore.
>>
>>52091269
Rewrite it in F#
>>
typedef struct 
{
int Width;
int Height;
int Flags;
int *Data;
} struct_layer;

typedef struct
{
struct_layer GLayer[MAX_LAYERS]; //3
int Width;
int Height;
char *name;
} struct_level;

struct_level GLevel;


i'm having a weird memory increase issue when I load a new level, when I end the current level, I make sure to free the tiles

for ( i=0; i<MAX_LAYERS; i++ ) 
{
GLevel.GLayer[i].Width = 0;
GLevel.GLayer[i].Height = 0;
GLevel.GLayer[i].Flags = 0;
if ( GLevel.GLayer[i].Data )
{
free ( GLevel.GLayer[i].Data );
GLevel.GLayer[i].Data = NULL;
}
}


but when I load a new level, the memory goes up alot; now this is how my tiles are created

if ( GLevel.Width > 0 && GLevel.Height > 0 ) 
{
unsigned int datasize = GLevel.Width * GLevel.Height;
unsigned int l;
for ( l=0; l<MAX_LAYERS; l++ )
{
GLevel.GLayer[l].Data = (int*) malloc ( datasize * sizeof(int) );
}
}


i've never normally had an issue with malloc/calloc before, but I did read something once that it doesn't play very well with something in a struct, might this be the issue?
>>
>>52091344
field names must be lowercase
>>
>>52091467
what you mean senpai?
>>
>>52091344
Maybe the momery is free but not collected by the OS.
>>
>>52091344
Run it through Valgrind or something. Code looks fine as far as what you've posted here goes.

>>52091494
This could be it, as well.
>>
>>52091492
typedef struct {
int width;
int height;
int flags;
int *data;
} struct_layer;
>>
>>52091344
>when I load a new level, the memory goes up alot
What exactly do you mean "up alot"?

Malloc usually allocates entire pages at the time and then uses a page as a pool.
>>
>>52090161
>macro

Kill yourself.
>>
>>52091498
Anime free thread
>>
>>52091576
Report this guy.
>>
>>52090276
>Is this averaging int thing a new /dpt/ meme?
Yes

Search the archives
>>
>>52091504
I ran it through Dr.Memory, not sure what to look for in the text files it made though
>>
>>52083587
https://ideone.com/dmSCCp

Also daily reminder that if your language of choice is not on this list you should probably give up and kill yourself:
- C++
- C#
- Lua
- Python
- Elixir
- Haskell
- Bash
- Clojure
- D
>>
>>52091658
>dr. memeory
>not using a competent tool
MY SIDES
>>
>>52091715

>- C++
>- C#
>- Lua
>- Python
>- Elixir
>- Haskell
>- Bash
>- Clojure
>- D
lmaoo
>>
>>52091658
might have found it in the results.txt

three of the issues are the same, i will post the issue that points to the line of code that malloc's

Error #4: LEAK 1200 direct bytes 0x00cf97d0-0x00cf9c80 + 0 indirect bytes
# 0 replace_malloc [d:\drmemory_package\common\alloc_replace.c:2320]
# 1 NL_ElementStart [E:\projects\test/map.c:263]
# 2 libexpat-1.dll!doContent [../expat-2.1.0/lib/xmlparse.c:2443]
# 3 libexpat-1.dll!contentProcessor [../expat-2.1.0/lib/xmlparse.c:2105]
# 4 libexpat-1.dll!doProlog [../expat-2.1.0/lib/xmlparse.c:4016]
# 5 libexpat-1.dll!prologProcessor [../expat-2.1.0/lib/xmlparse.c:3739]
# 6 libexpat-1.dll!XML_ParseBuffer [../expat-2.1.0/lib/xmlparse.c:1651]
# 7 NL_ReadLevel [E:\projects\test/map.c:154]
# 8 main [E:\projects\test/main.c:105]


map.c:263 is the
GLevel.GLayer[l].Data = (int*) malloc ( datasize * sizeof(int) );


everything else didn't seem to be an issue, as if I comment this out I have no memory increase.
>>
>>52091847
Set a breakpoint in the code that frees the memory. Does it even get called?
>>
>>52091882
I use notepad and GCC
>>
>>52091899
Oh dear. Learn how to use gdb.
>>
>>52091899
GCC comes with GDB, use that.
>>
>>52091715
why would that list not contain C?

you are very not-based
>>
>>52091715
>language of choice
What do you mean? Like, the language you use the most?
Sure, I can say 99,99% of my programming is C, Lua, Python, JavaScript, sh/bash/zsh and fasm
>>
>>52091715
Fixed list for non-autists:
- OCaml
-OCaml
- OCaml
-OCaml
- OCaml
-OCaml
- OCaml
-OCaml
- bash
>>
>>52091995
Language of choice means the language that you'd use if you had freedom to do so without getting fired.
>>
File: heyanon.jpg (15 KB, 306x306) Image search: [Google]
heyanon.jpg
15 KB, 306x306
Hey, we have only one active /dpt/

Weird
>>
>>52089234
No, which brings me to a question.

Is there any language that fulfills these
simple criteria:

-implemented in reasonable C89, no dependencies except make and a standard C compiler, maximally only very few (<5) and very tiny dependencies, also written in C89 (think of suckless.org)
-only one type of number, which is arbitrary
-support for arbitrary length string operations
-statically, strongly typed

Bonus:
-operator right-to-left or left-to-right evaluation (think of apl, j, k)
-functions can return and receive multiple arguments
-first class functions
-not a lisp
>>
>>52092157
Lua, Python, Haxe to get my shit done quickly
(z)sh, sed, awk for random file manipulation and console shit
C, C++, assembly and esolangs in free time
web dev stuff for web dev
Java, ObjectiveC, C# for mobiles, idgaf
There's never one single language of your choice.
>>
>>52091715
My langs of choice:
-rc shell scripting
-c
-lua
-awk
>>
>>52092160
Make more.
>>
>>52092139
nice computation expressions
>>
>>52083288
>>52083336
pudb is better than pdb
>>
>>52092313
>he doesn't know how to use monads!
>>
>>52092400
>computation expressions are just monads
Nice meme m8

Computation expressions are continuations+
>>
>>52092272
There is, unless you're a master memester and your favorite sport is switching language instead of getting stuff done (as you are).
>>
>>52092416
What? You're afraid by someone who know a lot of languages? That's the mark of the true coders.
>>
>>52092261

>No
Except for that macro I just dropped earlier in the thread.

>Only one type of number
Why would you want this? Using the same data type for integer and floating point operations is disgusting.
>>
>>52092416
Well, I think knowing a 'quick and dirty'
language for small scripts and a
statically typed and well structured
language (very rigid compilation and so on)
for large programs is a good minimum.
>>
>>52092437
>>52092416
Why do people act as if knowing many languages is something to be proud of? The syntax of the languages are nothing if the programming paradigm remains the same.
>>
>>52092469
>Why do people act as if knowing many languages is something to be proud of?
because it is.
> The syntax of the languages are nothing if the programming paradigm remains the same.
Knowing a lot of languages is still a good thing regardless.
>>
>>52092442
>only one type of number
Because of the fact that every integer
can be represented by a floating point
number and every integer operation
could be emulated with ceil(), floor() and round() (as far as I know (I would of course
accept a counterargument if it is true)).
And it would be more familiar, 7/2 would result 3.5 and not 2, like in most languages today (not all, of course).
>>
>>52092467
Why not have the best of both worlds in F#?
>>
>>52092525
F# is too good for him
>>
>>52092469
So is knowing how to program in many different paradigms something to be proud of?
>>
>>52092413
They're literally just monads.
>>
>>52092469
As far as I know, there are around
5-12 (imperative, functional, macro-based (lisp), logical (prolog), object-oriented, message-object-oriented (smalltalk), concatenative (forth)(depends on what you include)
programming paradigms around.
So for each paradigm, you have to learn
at least one language. And then there
is still a huge mass of concepts you
could learn, and which are partly only
supported by one language. So yes,
if you want to broaden your viewpoint,
it might not be harmful to learn multiple languages.
>>
>>52092467
Yes, like bash and ocaml.
>>
scala is a good language

although implicits seem evil
>>
>>52092590
Congrats, you're retarded!
>>
>>52092296

I don't get "bash" and "awk". I see these hundred/thousand line unreadable monstrosities that would be far more maintainable as Ruby or Python. Hell, even Perl.
>>
>>52092437
That's not a lot languages though. Yes, true programmers know more than one language and know which one to use in certain situations, just as true carpenters know more than how to use a hammer. Simply using multiple languages doesn't make you a programmer though and I've never said I was one.
In fact, I said I am a meme """"""""coder""""""" whose favourite sport is switching languages instead of getting stuff done.
>C, C++, assembly and esolangs in free time
That's what neckbeards do to feel better than others in something.
>>
>>52092573
Apparently they're syntax for:
>monads (plus)
>monad transformers
>applicatives (alternatives)
>monoids
all in one. Not sure why you need special syntax for applicatives or monoids, but whatever.
>>
>>52092630
>I don't get "bash" and "awk". I see these hundred/thousand line unreadable monstrosities that would be far more maintainable as Ruby or Python. Hell, even Perl.
Bash and awk are by default installed on virtually all NIXes.
>>
>>52092525
I don't know F# in depth yet,
but I know it is statically and
strongly typed.
Is there a way of circumventing
this static strong typing?
As I read in the wikipedia page,
it is ML derived, so I suspect when
I try to write a quick-and-dirty program,
I will have to deal with type warnings
(which is in my opinion generally a good thing). In this case, type warnings are somthing
that slows down the 'quick-and-dirty'
approach. I was more thinking about
languages like python, ruby, lua (which I like a lot) and recently perl6, which is a bit too large in my opinion.
>>
>>52092701
stop
writing
like
this

type inference
>>
Would I look dumb by adding a vtable to my structs and doing shit like
obj[j]->vtable->resize(obj[j], size)
>>
>>52092630
oh no, not thousands of lines!
oh my god, no, I am not an idiot.
Mostly, I use these for scripts <200 lines
(often only 10-20 lines).
For relatively small low-level projects, I use
C, and when I want to build something really
big, I would probably use something statically
and strongly typed.
>>
>>52092701
>I was more thinking about
>languages like python, ruby, lua
they give you type warnings as well. Just at run time. F# gives you them at compile time. The end result is F# is quicker for quick and dirty stuff than those languages.
>>
>>52092720
I am not even talking about type inference, which is of course nice, but the simple fact that there are type errors (which would not be present in any programmable shell) would already slow me down.
blablabla has type foo, expected list of type bar
and so on.
>>
Can anyone explain to me how this works?

a = 30
b = 10

def do():
a = 60
global b
b = 20
print(a+b, end=' ')

do()
print(a+b, end=' ')


The answer is apparently 80 50 but I have no idea where the fuck that number is coming from. Isn't "a = 30" being replaced by 60 in def?
>>
File: 2015-12-28 03.30.02.png (118 KB, 1079x960) Image search: [Google]
2015-12-28 03.30.02.png
118 KB, 1079x960
>>52092658
Python is too as is C
>>
>>52092519

>every integer can be represented by a floating point number.
If you are using arbitrary precision arithmetic for everything, your math will be rather slow. If you're using IEEE for everything, you will not be able to represent every integer that could be represented with an int type of the same size. We have different numerical types for different purposes.

>And it would be more familiar, 7/2 would result 3.5 and not 2, like in most languages today (not all, of course).
First of all, integer division of 7 and 2 is 3, not 2. Second of all, there are times when you want integer division. Why have to run floor() every time you need integer representations when you could instead just have two types? Is it so important to have a really tiny interpreter? Because TinyScheme still manages to have both types despite having an interpreter < 100 KiB. Of course, it's dynamically typed and a lisp, so it falls outside of your requirements.
>>
How do you create an int in Lua?
>>
>>52092752
>>52092658

Look at this shit:

https://github.com/lukas2511/letsencrypt.sh/blob/master/letsencrypt.sh

I mean, if just one of those embedded scripts fail, there's no backtrace and the whole thing is un-debugggable.
>>
>>52092805
C needs compiling and python is only on more recent systems.
>>
>>52092775
Yeah, but when everything is a string, and I treat it as a number and I can be sure that the thing is a number, even if I am in fact using a string, I can tell lua to trust me and treat it as a number.

To think this behaviour is acceptable in languages that are used to write millions and millions of lines of security critical code (cough-js-cough) is a mistake, but sometimes I like that behaviour.
>>
>>52080378
python 2.7 grandpa here

how much of a hard time will i have transferring to 3
>>
>>52092789
> (which would not be present in any programmable shell)
yes they would. they will occur at run time instead, which makes them slower to discover and fix.
>>
>>52092805
C needs compiling and is unsuitable for scripting. Python is not default on every NIX, but maybe common.

Good luck trying to make Python default on busybox for example.
>>
>>52092803
python is statically scoped.
a = 30
b = 10

def do():
a = 60 #different a from above, doesn't touch global a
global b
b = 20 #same b as above, modifies global b
print(a+b, end=' ') #local a + global b

do()
print(a+b, end=' ')
#global a + global b
>>
>>52092857
>but when everything is a string, and I treat it as a number and I can be sure that the thing is a number, even if I am in fact using a string
What are you talking about? If you treat a string as a number in most dynamic languages, you've made a mistake.

>I can tell lua to trust me and treat it as a number.
Even most other dynamic languages accept this is a bad idea. It's very easy to treat a string as a number by mistake, and then very difficult to figure out why your code has a bug and how to fix it. This is the whole reason people make fun of JS's hilariously poor weak typing, and even that doesn't let you treat a string as a number.

>but sometimes I like that behaviour.
You can like whatever you want. But there is no advantage to doing things this way with regards to productivity in any scale of project.
>>
>>52092807
Why does the programmer need to know how numbers are represented? The programmer can think of numbers as arbitrary precision floating point numbers and the compiler can generate code for whatever representation it needs. If we had a jit compiler for the language, we could even know what different values are at runtime so we can optimize for the data instead of just the operations.
>>
>>52092885
I can't believe how I couldn't come up with that logic. Thanks m8, I get it now.
Basically it's B being replaced, not A as I thought
>>
where/what is the code that parses arguments passed in command line to main and assigns the number to arg and the strings themselves to argv? is it compiler dependent? CPP macro? something to do with how programs are executed by the OS?

eg in a simple program that i cbf to write which prints out argc and argv

./shit i eat shit

//output:

4 arguments in argv
------->./shit i eat shit


what is going on under the hood here?
>>
File: camelia-logo.png (67 KB, 261x243) Image search: [Google]
camelia-logo.png
67 KB, 261x243
Daily reminder that Perl 6 is objectively the best array language
>>
>>52092958
It's the shell that does it. Check out the family of functions described in
man 3 exec
>>
>>52092958
it's usually in the c std lib or the os itself
>>
File: slide_18.jpg (117 KB, 960x720) Image search: [Google]
slide_18.jpg
117 KB, 960x720
>>52092930
>>
>>52092930
>Why does the programmer need to know how numbers are represented?
strong typing.

Sometimes the logic of your code is such that you certain numbers to be ints. When you are calculating a number you want to be an integer, you don't want it coming out at 3.000000001 as some floating points do. It is also of course faster and more memory efficient to use ints when necessary.
>>
>>52092993
28 died btw
>>
>>52092807
>math becomes rather slow
True. Maybe 'unsafe' machine integer and float access could be provided, while arbitrary precision would be the default.

>tinyscheme
I actually have it installed and I am very exited about it.

>integer division
Not in math (okay, it's not math but calculating, but that's not the point) actually (and after all, we are trying to perform a calculation). Rounding should be an explicit operation (because obviously, something happens and changes data and so on). Everyone except programmers will tell you that 7/2 equals 3.5. And this is not too hard to implement, bignum libraries already exist.
>>
>>52093019
>Maybe 'unsafe' machine integer and float access could be provided
>Thinks this is safer than safe machine integers like C has.
????
>>
>>52092641
Monads are monoids.
Monads are applicatives.
Monads can transform monads (although that's a particular kind of monad in that case).
So the point that monads can do that stands.
>>
>>52092993
That pic is the result of a programmer making a mistake when manually trying to convert numbers between different types. A number system that does that sort of conversion itself as needed would mean that the programmer couldn't make that sort of error.

>>52093009
Using a function like floor or round or whatever to tell the compiler/interpreter/whatever to drop that extra bit and consider converting to integer instead of floating point would work there.
>>
>>52092986

looks like i'm about to get a crash course on how processes are managed in linooks. thanks, i think
>>
>>52093032
Monads are not monoids, not at the level that programming languages are concerned with.

But yeah, you're right, I wasn't thinking straight about applicatives vs. monads. So that's one less use for computation expressions. The only thing they have over Haskell do-notation is apparently that they support monoids and .Net exception handling.
>>
>>52093051
>Using a function like floor or round
Yes, but now you HAVE to do that every time you want to print the value or round it or whatever. Having an integer type means you never have to do this and you can never make the mistake of forgetting to round it. That's why it's better.
>>
>>52093070
>Monads are not monoids, not at the level that programming languages are concerned with.
Yes they are. All monads are monoids, not all monoids are monads.
>>
>>52093075
I'd argue that it's much less safe to have an integer type because you open yourself up to a whole slew of overflow/underflow errors that are much more work to catch than merely needing to remember to format output properly. Also letting the system use as many bits as it needs to store whatever representation it likes should get rid of all those funky floating point issues like that 3.000000001 thing
>>
>>52093051
>>52093070

"monads can do that" functions that can take functions as parameters can do monads
so we should only ever use C
>>
>>52093029
As an option.
C has fpu-based floating point numbers, which I consider 'unsafe', because 0.1+0.2!=0.3 in C. The same thing with integers of all sizes (32 bit integers), which are unsafe because they overflow, they don't behave like numbers in calculations behave and so on.

So, safe machine C integers are in fact not safe, I consider them unsafe. They are still useful in a lot of cases, but trading this risk for a higher security would be a benefit (not only C, but most languages still suffer from this problem). I mean, most people will admit that garbage collectors prevent critical errors that would happen with manual memory management, but sometimes they are limiting. This is where manual and 'unsafe' concepts can be of course used.

But not per default.
>>
>>52093075
As a note on that, it introduces another kind of important bug: if someone passes 3.333 to your function, did they know your function expected an int-aligned float or not? If not, then they're now obtaining surprising results and their space shuttle is crashing. If yes, then they get no error message despite passing a value that is most likely wrong, such as an incorrect output from a function somewhere up the call stack.
>>
>>52093124
Except there is no syntactic advantage of compute expressions v.s. monads.
>>
>>52093113
Monads are monoids of functors, categorically. But it doesn't make any sense to call them the same thing at the programming language level, firstly because a monoid is a set and a monad is a family of sets.
class Monoid (a :: *)
class Monad (m :: * -> *)
>>
The main usage of computation expressions is in creating a domain specific language

Computation expressions effectively let you create a (parametrisable) language extension, and easily see where that extension is in use
>>
>>52092982
a bit too big and complicated, but good intentions.
I wish the perl 6 people a lot of luck and that some of their ideas are spread.
>>
>>52093121
>you open yourself up to a whole slew of overflow/underflow errors
??? Are you stupid? Do you think floating points dont have equally bad problems? When floating points get big enough it's impossible to increment them by 1 anymore. It's the exact same problem.
>Also letting the system use as many bits as it needs to store whatever representation it likes should get rid of all those funky floating point issues like that 3.000000001 thing
And how do you figure out how many bits a floating point needs? How many bits do you need to store an irrational number like PI? Do you realise how expensive it is to even attempt to figure that out on every single operation? You can also grow the bits needed by an int much easier, which is what things like BigInteger in Java are about.
>>
Working on a 4chan android browser. Still at the very beginning. Getting into Json parsing of the threads, shit looks ridiculously easy.

This is my first hobby side project.It's kinda nice to feel like I'm getting somewhere.
>>
>>52093209
I am not proposing on using floating point numbers for everything, but arbitrary precision bignums.
I hope our dispute is cleared now.
>>
File: 1404328489048.png (114 KB, 694x670) Image search: [Google]
1404328489048.png
114 KB, 694x670
I've been trying to solve project euler problem 11 in C for a couple of months now.
Every time I think I have a good plan of attack it just blows up in my face when I try to implement it, I end up spending hours only to realize that my method was retarded to begin with and then I delete it and start over.
So then I try the straight-foward way, and I end up just writing shit code, sure, it might even work when I'm done but I can't stand writing shit code which leaves me in a nice little pickle because I am a shit programmer who can do nothing but write shit code.
Will there ever come a time when I can do a stupid little problem like this in at most one afternoon just like everybody else or will I always be in way the fuck over my head?
I've been writing C for a couple of years now and this does not seem to be getting any easier.
>>
>>52093209
I'm not arguing against ints, the system should use them wherever possible because they're nice and fast to compute. I'm just arguing that the programmer shouldn't be the one who is in charge of juggling a bunch of different representations. That is a task that the compiler/interpreter can handle.
>>
Rate my large number generator

def make_large_number(length):
large_number = ''
with open('/dev/urandom', 'rb') as f:
while length > 0:
cur = f.read(1)
if cur.isdigit():
large_number += str(int(cur))
length -= 1
return int(large_number)
>>
>>52093287
>arbitrary precision bignums.
okay, so in this language. How big is 1/3 when stored as an arbitrary precision bignums? How many bytes does that need?
>>
>>52093260
Good luck dude!
>>
Why has F# become such a meme lately?
>>
>>52093305
interesting.
Code for generating very large numbers:

nta n m 1 = n+m
nta n m ar = foldr(nta (ar -1)) 1 (rep m n)

mira> nta 5 5 5
<long wait>memory exhausted
mira> 2^(2^65536)
>>
>>52093338
A possible representation that optimizes for memory usage (maybe not the best choice though, it depends on what context this number is being used in and what operations will be performed on it) is to store a number as a fraction with a numerator and a denominator. A system could see that 1/3 is representable using 2 shorts and use that much memory (plus a tag to specify what type it is) for it
>>
>>52093176
You can also use the [<ReflectedDefinition>] attribute for function parameters, which will give you the expression tree passed as a parameter, rather than just the value. You can get the variable name too.

So you could write a function that when you call it like this:
output X
gives you this:
"Value of X is [value]"
>>
>>52093302
>charge of juggling a bunch of different representation
He should, because the can't be abstracted. They are intrinsic to the logic of the application. Let's pretend computers today didn't have special hardware for ints, and everything was just a float to the CPU. If we are programming, it's still handy to look at variables we know will always be ints, and mark them as ints in the languages. This makes sure we never get fractions in these numbers and they always print correct, and functions that accept them can depend on them real integers, even if the CPU treats them as floats in the end. It helps describe the actual logic better.

I agree programs should be highly abstracted when performance isn't a top concern, but being able to state if a number is an integer or if it can have fractions is useful for simply describing the intended behaviour of your code to yourself and other people reading it. It's just a happy co-incidence that the compiler can make handsome optimisations with this information.
>>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif

Why is this code preferable to
#include <stdio.h>
#include <stdlib.h>

?
>>
>>52093338
Depends.
I am not an expert on bignum libraries,
but with my very limited understanding it would take 10 bytes:
-4 for the length of the numerator
-1 for the numerator itself
-4 for the length of the denominator
-1 for the denominator itself

But I am sure there are much more efficient implementations of bignums available. Maybe I'll read a bit about that.
>>
>>52093382
>s to store a number as a fraction with a numerator and a denominator
LOL, yes anon.. you can do that today. But it's not fast or convenient. I'm asking you if i'm trying to produce one of your arbitrary precision bignums, how does that look in memory? My point is almost all fractions would be infinite in length.
>>
>>52093382
Nice that we gave almost the same answer.
>>
>>52093483
both missing the point though. Neither or your answers are floats.
>>
>>52093437
I agree with this. I could see a system where on declaration of a variable, you specify its attributes. Things like
var a is a whole number
or
var a is positive
or
var a is in the range [3, 12)
which can later be checked automatically.
It'd make sense for arguments to functions to be able to specify what are valid values similarly.
>>
>>52093516
That was kinda what 5GLs were supposed to be, but weren't.
>>
>>52093476
This is of course not ultimately speedy, but it is safe, and in most of the cases, your program does not do that much very complicated math that has to be fast.

There is also no need to produce the number directory in memory, the nominator-denominator abstraction works without having to produce the number.
>>
>>52093511
Why does it need to be a float? Because of the FPU?
>>
>>52093348
Thanks man.

If I complete this and ithat's a big if, I'll make it free in every sense of the word.
>>
>>52093511
Because you can't exactly handle 1/3 in memory with floats, and that's what we are trying to do.
>>
>>52093516
The first is the same as specifying that it's an integer.
The second and third are done with refinement types, or more generally, dependent types.
>>
>>52093516
Ada sorta does this.
>>
every language currently invented, found something seriously different that can make one language obselete to all of them, i think i cracked the code for AI, will know soon enough!
>>
>>52093530
because that was his point. Everything being arbitrary big nums. You can't possibly mean bignums are just strings of ints and operations that meant to be performed on those ints. That just defers the calculation into the future. You can to calculate them sometime, and then you still have the precision problem to fix.
>>
>>52093558
Go away, Urbit.
>>
I'm writing automation add in outlook for my boss right now. It's the first time I've used C# and it's a total mess, but it works, so I just need to figure out how to deploy it. I'm not even a programmer, I'm just trying to pad my resume because I hate my job so much.
>>
>>52093568
oh my god
now your conversation is about monads too
>>
>>52093476
>>52093528
>Some programming languages such as Lisp, Python, Perl, Haskell and Ruby use, or have an option to use, arbitrary-precision numbers for all integer arithmetic. Although this reduces performance, it eliminates the possibility of incorrect results (or exceptions) due to simple overflow. It also makes it possible to guarantee that arithmetic results will be the same on all machines, regardless of any particular machine's word size. The exclusive use of arbitrary-precision numbers in a programming language also simplifies the language, because a number is a number and there is no need for multiple types to represent different levels of precision.
Wikipedia, page for arbitrary precision arithmetic.
This sums up my arguments pretty well.
>>
>>52093299
eventually you kind of learn how to think in the right way to solve those problems. do something else and then come back to them after solving "real world problems" and you'll find that they become much easier
>>
>>52093600
>I don't have any idea what a monad actually is
>>
>>52093617
>arbitrary-precision numbers for all integer arithmetic
>integer arithmetic
not floating points anon. It's piss easy to make integers arbitrary is size. Not so much floats.
>>
>>52093552
It's a little different from specifying that it's an integer because calling it an integer is restricting the bit representation of the number to integer. I think it's useful to call it something else so that no confusion arises from the programmer.
>>
>>52093642
see >>52093382 (that's not you, is it?)
>>
>>52093655
Integral? Haskell has a type class for that; doesn't allow division, only quotient/remainder.
>>
>>52093627
>implying a delayed computation isn't a monad
>>
>>52093703
It sure is, but that doesn't make the conversation "about monads".
>>
>>52093703
a monad is a delayed computation. Not visa versa.
>>
>>52093725
not all monads are delayed computations
>>
File: mt-stupid.png (43 KB, 613x481) Image search: [Google]
mt-stupid.png
43 KB, 613x481
>>52093725
>a monad is a delayed computation
>>
>>52093703
I don't understand why we can't just accept state in some cases. I mean, purity is great, but this monad thing seems interesting, but way to complicated.
>>
>>52093121

This is where I get to tell you about the wonders of dynamic typing. In Ruby, we have multiple numeric types. Inheriting the Numeric class are Integer, Float, Rational, and Complex. BigDecimal, a part of the standard library (but which must be "required" like a gem), also inherits Numeric. Each of these classes achieves a different purpose.

Fixnum : Capable of representing any number between -(2 ^ 30) and (2 ^ 30 - 1). These are your fast integer types, and they are actually stored in the object id, meaning there is no indirection to actually fetch them and do operations on them. If there would be an overflow in performing mathematical operations on them, however, they get automatically promoted to Bignum.

Bignum : Arbitrary precision integers. Convert seamlessly with Fixnums as necessary.

Float : For any operation where IEEE floats normally apply. This uses double precision floats. Does not convert to any other class.

Rational : Rationals are basically a/b, where a and b are integers. They provide for accurate math where numbers might not normally divide right in a base 10 number system. Both the numerator and denominator can be any integral class, and the result can be evaluated as Integer (Fixnum, Bignum), Float, or Complex.

Complex : Real + Imaginary components, both can be any other Numeric type.

BigDecimal : Basically what you want. Arbitrary precision Numeric type for decimal and integer operations.

The programmer is given whatever type he needs as is appropriate to the situation, and is guarded from overflow/underflow errors. All possible because the type system will handle these problems at runtime.
>>
>>52093748
You got me. After all these years I don;t know what a monad it : I. I know it has a return and bind... and lets you do some cool shit... but that's about it. Cannot describe what one it.
>>
>>52093767

you can have an impure monad, it's just the haskell cunts will cry
>>
>>52093770
Don't need dynamic typing for that. Just need a static Number type.
>>
>>52093767
Haskell uses monads to emulate linearity, which is the real key to being able to quantify side effects and maintain purity.

>>52093778
No, you've pretty much got the full picture, as far as programming goes. If something has unit, join+map/bind, and satisfies the laws, it's a monad. Lots of things fit this picture, and the monadic structure is the only similarity between all of them.
>>
>>52093770

Also, forgot to mention that Fixnum and Bignum both subclass Integer.
>>
>>52085640
Isn't that dividing by 0?
>>
>>52093770
>Using the same data type for integer and floating point operations is disgusting. >>52092442

>praises Ruby's Numeric system where all number are a single Numeric type >>52093770

XD
>>
>>52093778
>>52093819
Like, capture-avoiding substitution in the lambda calculus can be a monad. That's a pretty extreme and unique example, no?
>>
>>52093377

I got a memory error trying to compute 2^(2^65536)
>>
>>52093874
Is a monad a type of frob?
>>
>>52093338
8 bits.
>>
>>52093824
Separating these was not my idea, but that seems like a good solution to it.

I would rather prefer one arbitrary floating point type and optionally a collection of machine-precision types (uint8, uint16, uint32, uint64, ufloat32, ufloat64 etc).
>>
>>52093846

They're not a single numeric type. All of them have different representations in memory, and many of them must be declared explicitly of a particular type. The only implicit conversions are between Fixnum and Bignum, and between any type and a non-integral type. Numeric is not a single type, it is merely a superclass with some operations supported by all of them. An interface, if you will. And the reason we are able to have any of these at all working so seamlessly is because of a dynamic typing system. If I declare a as 5, I know it is going to be a Fixnum. If I add 6 billion, I know it will become a Bignum. If I multiply it by 7.5, I know it will be a Float. All of these are completely different types.
>>
>>52093884
Yes, because it is a very huge number.
You need 2^65536 bit to represent it, and I assume your computer does not have that much memory.
I am sorry.
>>
>>52093825
x % T = r
where
x = nT + r
>>
File: right.png (71 KB, 1366x768) Image search: [Google]
right.png
71 KB, 1366x768
>>52093923
I guess he is a complete troll, I wouldn't respond to him.
>>
>>52093957
>can't even spell correctly
>>>/trash/
>>
>>52094012
in the screenshot or in the response?
would be nice if you told me, so that I
can recognize and fix my mistake.
>>
>>52094038
comment in right

standartized -> standardised
>>
>>52093445
Don't think that's correct at all. 8 bytes for a pointer to the number and n bytes for the actual number wherever it is in memory and 8 or less bytes for the size. *2 for the denominator.
>>
How do you efficiently did through research papers for the algorithm you need but cant describe because you're young in the field and shitty at formal research formatting
>>
>>52094172
Efficiently sift through*
>>
>>52094077
okay, thanks.
>>52094134
true, but still not too much (js waste...)
>>
File: x4zx0oH.png (104 KB, 1209x798) Image search: [Google]
x4zx0oH.png
104 KB, 1209x798
any of you NEETs know how to modify a memory location of a another application?
I was pointed to strace and looking into /proc/

anyone know anything more?
>>
>>52094298
The purpose of an operating system is to ensure that doesn't happen
>>
>>52094298
Cheat Engine
>>
>>52094374
the purpose of an operating system is to let me do what the fuck i want
>>
>>52094374

top cello lello
>>
>>52094388
thats winblows shit and i want to know how to do it not use some script kiddie shit
>>
>>52094298
Run the program in GDB, pause, type:
set {type} address = value


Continue.
>>
Daily reminder that if you fork the .NET CLR and implement higher kinded polymorphism everyone will have your babies
>>
>>52094038
>i
>>
Daily reminder that F# is the shit version of F*
>>
>>52094134
It only needs 4 bits per digit you fucking tard. 8 bits total.
>>
>>52094565
F* compiles to either ocaml or F#. One day it might be actually a real language (which will deprecate F# instantly) but ocaml will always be the best and F* will never deprecate ocaml.
>>
>>52082500
Use one random, and use a string: short loop would be: for (int i = 0; i<4; I++){random = random.nextInt(10); string += random.toString();}
I'm sorry if this is puzzling cuz I code in c# and havent done Java in a long time
>>
>>52092745
Helppppppp
Thread replies: 255
Thread images: 18

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.