Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
cinci zoo sniper
Mar 15, 2013




Mr SuperAwesome posted:

i looked up that SO post and what the actual gently caress :wtc:

right, you tell me. i understand the code (more or less), but all i got out of it and similar posts this evening is an interest in studying mypy docs for a bit to see how it differs/supplements type hints

Adbot
ADBOT LOVES YOU

cinci zoo sniper
Mar 15, 2013




looks like ive been using mypy all along, since it is just a ~more flexible~ version of static analyser built in pycharm, which references the same typing and hints things that i do

what im saying is that i have no loving idea the gently caress i am doing, as usual

mystes
May 31, 2006

Yeah pycharm alrady does that stuff. Mypy is theoretically useful if you want type checking in vs code or whatever, although in practice it's pretty frustrating and you should probably just decide if you want to use python or a statically typed language.

cinci zoo sniper
Mar 15, 2013




mystes posted:

Yeah pycharm alrady does that stuff. Mypy is theoretically useful if you want type checking in vs code or whatever, although in practice it's pretty frustrating and you should probably just decide if you want to use python or a statically typed language.

imo its a decent way to document code and catch some glaringly stupid stuff

Xarn
Jun 26, 2015
MyPy is good, but the type hints should be (at least optionally) runtime checked and asserted on.

Luigi Thirty
Apr 30, 2006

Emergency confection port.

okay i figured out why my jaguar thingy works in the emulator but not a real console

the LOAD instruction in the GPU requires long-aligned data. the emulator doesn't take this into account. the compiler, a 68k compiler, is word-aligning my sprite metadata. on the real device it bugs out because of this and reads bad data from RAM. there's no alignment attribute in my compiler... and I can't switch to GCC without the proper 68k jaguar libc headers for GCC.

welp. shot an email off to the guy who writes VBCC, see if he can do anything about that. he fixed the last few bugs I found when doing Jag stuff. all mallocs are long-aligned so I could work around it by copying the sprite data from ROM to RAM but I’d rather not.

Luigi Thirty fucked around with this message at 21:41 on Oct 14, 2017

Mr SuperAwesome
Apr 6, 2011

im from the bad post police, and i'm afraid i have bad news

mystes posted:

Yeah pycharm alrady does that stuff. Mypy is theoretically useful if you want type checking in vs code or whatever, although in practice it's pretty frustrating and you should probably just decide if you want to use python or a statically typed language.

:agreed:

ynohtna
Feb 16, 2007

backwoods compatible
Illegal Hen

Luigi Thirty posted:

okay i figured out why my jaguar thingy works in the emulator but not a real console

the LOAD instruction in the GPU requires long-aligned data. the emulator doesn't take this into account. the compiler, a 68k compiler, is word-aligning my sprite metadata. on the real device it bugs out because of this and reads bad data from RAM. there's no alignment attribute in my compiler... and I can't switch to GCC without the proper 68k jaguar libc headers for GCC.

welp. shot an email off to the guy who writes VBCC, see if he can do anything about that. he fixed the last few bugs I found when doing Jag stuff. all mallocs are long-aligned so I could work around it by copying the sprite data from ROM to RAM but I’d rather not.

hack the linker luigi

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
can you just put a pointer before your sprite metadata or something?

like literally before might work if the compiler spits globals out in order, which it totally might

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
very few languages bother directly supporting explicit-range integers. in c++ it's not hard to write a template to do that, though, and that'll even store it with an optimally-compact type

Luigi Thirty
Apr 30, 2006

Emergency confection port.

rjmccall posted:

can you just put a pointer before your sprite metadata or something?

like literally before might work if the compiler spits globals out in order, which it totally might

It does not.

the metadata structs are 24 bytes long so another solution would be to just put them in their own long-aligned section in the linker.

Luigi Thirty
Apr 30, 2006

Emergency confection port.

it turns out i'm a dumbass and the sprite data itself is aligned properly. the pointer to the sprite data wasn't long aligned... in the node struct I wrote. i added 2 bytes of padding and now i have 50 sprites bouncing around on my TV again. took 2 days to figure that out :(

brap
Aug 23, 2004

Grimey Drawer
you're not dumb, you're just doing programming

toiletbrush posted:

Swift is good because when I feel clever using it, it's because I've been super pedantic about everything and so if it builds it will probably work.

if this is true for you I assume this swift code you speak of is not calling into UIKit

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today

mystes posted:

If you don't need this to actually be part of the type system and just want some sort of overkill way to effectively do assertions, Eiffel.

Otherwise this is territory where you need dependent types, so Idris or something.
this is false, you do not need anything remotely like real dependent types for simple fixed range restrictions on integers.

i wish more dynamically typed languages would adopt refinement types.

Master Stur
Jun 13, 2008

chasin' tail
npm sucks and 5.3+ are annoyingly broken because they rushed feature parity with yarn

bob dobbs is dead
Oct 8, 2017

I love peeps
Nap Ghost
5.2- is annoyingly broken because it's npm

Master Stur
Jun 13, 2008

chasin' tail
true, something after 5.2 breaks though and the only given solution is to downgrade or delete node_modules and your lockfile every time lol

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

i just scripted some file renaming

i used java :getin:

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

Master Stur posted:

true, something after 5.2 breaks though and the only given solution is to downgrade or delete node_modules and your lockfile every time lol

the solution is to use yarn

VikingofRock
Aug 24, 2008




rjmccall posted:

very few languages bother directly supporting explicit-range integers. in c++ it's not hard to write a template to do that, though, and that'll even store it with an optimally-compact type

Could you expand on this?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

carry on then posted:

i just scripted some file renaming

i used java :getin:

did you check it in

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

pokeyman posted:

did you check it in

well, the results, yes

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

VikingofRock posted:

Could you expand on this?

sure, an explicitly-bounded integer is something like “10..20” as a type, the idea being that you should just state your requirements and the language will figure out how to implement them efficiently on the hardware. it was a much bigger thing in older languages, and it does seem to make some sense at first, but it actually has a lot of problems the more you think about it. like if you have a statment like x=x+y, what type is the addition performed in? the most natural answer is to say that it’s done in infinite precision and then the result is coerced to the type of x, but that pretty quickly scales in complexity for the implementation, which has to do heroic optimizations to try to avoid every addition turning into an allocation. or you pick some arbitrary type, but now the choice of that type is extremely important for the semantics of the program and the whole thing doesn’t seem so elegant anymore. c did a lot to convince language designers that programmers mostly didn’t care and it wasn’t worth introducing all that complexity trying to hide that kind of machine detail from the programmer, because the important cases of fixed-range integers were mostly cases where people actually just wanted a symbolic enum

or did you mean about how to do it in c++

rjmccall fucked around with this message at 04:16 on Oct 15, 2017

mod saas
May 4, 2004

Grimey Drawer

Mr SuperAwesome posted:

i looked up that SO post and what the actual gently caress :wtc:

that SO post posted:

Bear typing is dramatically more efficient in both space and time than all existing implementations of type checking in Python to the best of my limited domain knowledge. (More on that later.)

mmmmods!??

VikingofRock
Aug 24, 2008




rjmccall posted:

or did you mean about how to do it in c++

Yes--I guess I should have been more specific. But I appreciated the post anyways! :cheers:

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

VikingofRock posted:

Yes--I guess I should have been more specific. But I appreciated the post anyways! :cheers:

i just like talking about the language design stuff

in c++ it's just something like

C++ code:
template <typename bound_type, bound_type minimum, bound_type maximum>
struct best_int_type_for_int_between {
  // exercise for the reader: pick a type with the signedness of bound_type that can
  // losslessly represent all values between minimum and maximum
  using type = ...;
};

template <typename bound_type, bound_type minimum, bound_type maximum>
class basic_int_between {
  static_assert(minimum <= maximum, "type must be non-trivial");
  // Here we're just directly storing the original value using the smallest type that can
  // represent the full range, but we could also have used an implementation that used an
  // offset from the minimum.
  using int_type = typename best_int_type_for_int_between<bound_type, minimum, maximum>::type;
  int_type value;
  struct known_valid_token {};
  constexpr explicit basic_int_between(int_type value, known_value_token _) : value(value) {}
public:
  static bool in_range(bound_type value) { return minimum <= value && value <= maximum; }
  explicit basic_int_between(bound_type value) : value(value) { assert(in_range(value)); }
  basic_int_between operator ""(bound_type value) { return basic_int_between(value); }
  bound_type value() const { return value; }
};

// Provide relational operators that work regardless of the static bounds.
// Don't allow mix-sign comparisons, though.
template <typename bound_type, bound_type lmin, bound_type lmax, bound_type rmin, bound_type rmax>
inline bool operator==(basic_int_between<bound_type, lmin, lmax> l, basic_int_between<bound_type, rmin, rmax> r) {
  static_assert(lmin <= rmax || rmin <= lmax, "comparing two integers whose range is statically known not to overlap");
  return l.value() == r.value();
}
template <typename bound_type, bound_type lmin, bound_type lmax, bound_type rmin, bound_type rmax>
inline bool operator!=(basic_int_between<bound_type, lmin, lmax> l, basic_int_between<bound_type, rmin, rmax> r) {
  return l != r;
}

template <int64_t minimum, int64_t maximum>
using int_between = basic_int_between<int64_t, minimum, maximum>;

template <uint64_t minimum, uint64_t maximum>
using uint_between = basic_int_between<uint64_t, minimum, maximum>;

...
uint_between<10, 99> twoDigitNumber;

Gul Banana
Nov 28, 2003

i do occasionally miss bounded integers from PL/X, but they were only implemented efficiently thanks to hardware support for BCD. even then we usually ended up having to switch to bit-lengths when someone wanted more transactions per second

cinci zoo sniper
Mar 15, 2013




rjmccall posted:

sure, an explicitly-bounded integer is something like “10..20” as a type, the idea being that you should just state your requirements and the language will figure out how to implement them efficiently on the hardware. it was a much bigger thing in older languages, and it does seem to make some sense at first, but it actually has a lot of problems the more you think about it. like if you have a statment like x=x+y, what type is the addition performed in? the most natural answer is to say that it’s done in infinite precision and then the result is coerced to the type of x, but that pretty quickly scales in complexity for the implementation, which has to do heroic optimizations to try to avoid every addition turning into an allocation. or you pick some arbitrary type, but now the choice of that type is extremely important for the semantics of the program and the whole thing doesn’t seem so elegant anymore. c did a lot to convince language designers that programmers mostly didn’t care and it wasn’t worth introducing all that complexity trying to hide that kind of machine detail from the programmer, because the important cases of fixed-range integers were mostly cases where people actually just wanted a symbolic enum

or did you mean about how to do it in c++

that would do it for me, since something as simple as range limiter would only be good for multiple choice input arguments imo. and now that im checking, python did actually add enums in 3.4 :eyepop: that's a whole load of refactoring that i can do, and the syntax isn't the worst, by that meaning

code:
Animal = Enum('Animal', 'ANT BEE CAT DOG')
rather than

code:
class Animal(Enum):
    ant = 1
    bee = 2
    cat = 3
    dog = 4

Xarn
Jun 26, 2015

rjmccall posted:

very few languages bother directly supporting explicit-range integers. in c++ it's not hard to write a template to do that, though, and that'll even store it with an optimally-compact type

I am actually giving my students something similar as an optional assignment this semester :v:

Going to be fixed size only (int I guess?), and won't support modulo (because lol at deriving new bounds for modulo given two weird rear end ranges with possibly negative values).

The jury is still out on division, mostly I think I will just specify rounding behaviour and disallow division by ranges that include 0.

VikingofRock
Aug 24, 2008




rjmccall posted:

i just like talking about the language design stuff

in c++ it's just something like

This is very cool. Thanks!

redleader
Aug 18, 2005

Engage according to operational parameters
terrible programmer question: what are the differences between smalltalk-style message passing oop, and java/c#-style oop? what does smalltalk do that java doesn't?

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

cinci zoo sniper posted:

im using type annotations with python 3.6, it is completely unrelated to what i am asking, which is which languages have a specific mechanism of enforcing types and values of objects

my python poo poo is straightforward enough to avoid being bitten in the rear end by its type system

Common Lisp and CLOS let you work with constrained types

Lisp is generally a strongly typed language, just not explicitly typed; you can’t reinterpret bits in memory without jumping through a bunch of hoops (strong typing), but you don’t have to declare every variable or function’s type (explicit typing) and you can have variables and functions either be open ended in type or constrained (dynamic by default, static possible)

it doesn’t look like C at all but it can do type constraints and modern compilers will use them to good effect, too, both to warn or error on code that violates them and to do optimized code generation that can be competitive with C

the infix syntax for Dylan was an attempt to basically make a cleaned up CLOS with Pascal-style syntax for type declarations specifically to make it more attractive to programmers used to Pascal and C

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

hackbunny posted:

pascal was my first too and it was good, but it belongs in the past

real-world Pascal is barely any different than C when you look at their semantics, their syntax is just superficially distinct

they’re like VB.Net and C# in that way

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

redleader posted:

terrible programmer question: what are the differences between smalltalk-style message passing oop, and java/c#-style oop? what does smalltalk do that java doesn't?

in Smalltalk literally everything is an object and everything is a message send (aka dynamic dispatch), both (what other languages treat as) primitives and classes are also true objects

so when you written x := 3 + 4. it’s sending + to the instance 3 of class Integer with the instance 4 of class Integer as an argument, and the method that handles that message can do what it wants including introspect the context in which the message was sent

practically speaking you also have really aggressive optimization so if the compiler and runtime can prove there’s no dynamic behavior that will be invoked, it can generate more aggressive code—but back that out of later on, dynamic behavior is needed (for example because you added a subclass of Integer)

in Java instance messages like foo.doSomething(bar, baz) work like this, down to the back-out-optimizations behavior (which came from Sun hiring the Smalltalk developers who created Self & Strongtalk, and having them create Hotspot) but there are also primitive types that don’t have methods and also there’s no such thing as dynamic dispatch to a class so you can’t override a class method in a subclass and have the override called

despite syntactically derived from C++, Java was semantically modeled on Objective-C, which makes the same kind of object vs primitive split but kept classes as objects and class methods from Smalltalk, as well as the keyword-style syntax for OO stuff

Smalltalk also doesn’t dispatch messages to methods based on all argument types, it dispatches purely on the receiver type, though there have been plenty of extensions to the language over the years to enable this; Java got this from C++, which I think got it from New Flavors and/or CLOS, or one of the functional languages

C# like C++ makes you choose whether instance methods should be dynamically or statically dispatched, rather than assume all the world is dynamic and rely on runtime optimization for performance

feedmegin
Jul 30, 2008

cinci zoo sniper posted:

pascal was the first language i learned but i remember jack poo poo about it

My first language that wasn't BASIC was Modula-2 (what Wirth did next after Pascal) - mainly because the compiler for the Atari ST cost about half as much as a C compiler (remember when compilers costed money?).

It was alright I guess. The module system is nicer than C, and it's where I first learned what a pointer was and how to do inline assembler. Dead as a doornail now tho.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

feedmegin posted:

(remember when compilers costed money?)

im trying to come up with some downside to this transition and ive got nothing

usually seems that when something goes to free you lose something, like "now one company controls the project and only their pet features get any work"

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

pokeyman posted:

im trying to come up with some downside to this transition and ive got nothing

usually seems that when something goes to free you lose something, like "now one company controls the project and only their pet features get any work"

:rms2:

Sweevo
Nov 8, 2007

i sometimes throw cables away

i mean straight into the bin without spending 10+ years in the box of might-come-in-handy-someday first

im a fucking monster

feedmegin posted:

My first language that wasn't BASIC was Modula-2 (what Wirth did next after Pascal) - mainly because the compiler for the Atari ST cost about half as much as a C compiler (remember when compilers costed money?).

It was alright I guess. The module system is nicer than C, and it's where I first learned what a pointer was and how to do inline assembler. Dead as a doornail now tho.

i had to learn modula-2 instead of pascal when i started college, and the only thing i remember is that four weeks in the tutor switched us to pascal because the modula-2 compiler was a giant pile of poo poo that hardlocked the computer if you did things like have text after the semicolon on a line

Sweevo fucked around with this message at 16:37 on Oct 15, 2017

Xarn
Jun 26, 2015
ctps: Bashing my ahead against CMake

How the gently caress is this poo poo getting to be the de-facto c++ build generator? It somehow manages to combine the worst parts of various plangs to become worse than all of them.

Adbot
ADBOT LOVES YOU

Phobeste
Apr 9, 2006

never, like, count out Touchdown Tom, man

Xarn posted:

ctps: Bashing my ahead against CMake

How the gently caress is this poo poo getting to be the de-facto c++ build generator? It somehow manages to combine the worst parts of various plangs to become worse than all of them.

c++ build systems are so weird because the language itself is so invested in types and catching incorrect behavior before the program is run and then when it comes to the tooling around it everybody just shrugs and declares stringly typed shell style bullshit "good enough"

i think it's because there's so little formalism around how c++ projects are structured. there's no modules, include files can be wherever the hell you want, everything ends up being so system dependent and has so much implied state that even build systems that are in real languages like SCons in python all fall back to hidden global state anyhow

plus it's a vicious cycle where build systems suck so nobody wants to deal with them for longer than they have to lest they become known as a build systems person so nobody improves them so they keep sucking. probably the endpoint of the build system is further building things in to toolchains and having those toolchains get a little more opinionated about how things should be structured so the build system has to do less and less other than invoke the compiler once for each output object.

  • Locked thread