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
Bloody
Mar 3, 2013

Awia posted:

what if it doesnt' work and you dont want to try again?

the if statement will get executed once unless enclosed in some wider loop how is that different from the do while block

Adbot
ADBOT LOVES YOU

oh no blimp issue
Feb 23, 2011

yes
but in the do while(false) you'd enter the if and hit the break, leaving the do block and hitting the code after instead of the things you might have wanted to do if the call in the if had done it's job correctly

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat
goto is cool because it pisses off spergs who think they're "doing it the right way" and then linus rips into them for submitting a patch that has 4 levels of indentation in a device driver

Soricidus
Oct 21, 2010
freedom-hating statist shill

CRIP EATIN BREAD was right

raminasi
Jan 25, 2005

a last drink with no ice

AWWNAW posted:

people who write X Considered Harmful blog posts should be shot into space

"Considered Harmful" Essays Considered Harmful

Finster Dexter
Oct 20, 2014

Beyond is Finster's mad vision of Earth transformed.

AWWNAW posted:

people who write X Considered Harmful blog posts should be shot into space

Thanks for giving me an idea for my next blog post, titled:

X considered harmful blog posts considered harmful

e:^^^ gently caress. That'll teach me to reply to something before reading the next page of posts.

BattleMaster
Aug 14, 2000

CRIP EATIN BREAD posted:

thats a pretty common pattern when you dont have goto.

then again i really only use goto when writing kernel device drivers.

i've used goto twice in embedded applications. the first was in a parser and was essentially identical to the do { } while (false) thing so that it could exit with common cleanup code even if there was an error (this saved a nontrivial amount of program space on my 8-bit micro with 32 kb of program space over other solutions, and i actually needed those bytes for other things). the other was to break out of nested switch blocks in the command packet handler for a usb device stack.

i'm not going to whitewash the latter case since it could probably have been done without nested switch-cases, but i would rather use goto in the former case over the do { } while (false)

on the other hand my cs grad boyfriend refuses to accept goto because he learned in school it was bad and he wanted to disown me after i showed him those things back to back

JewKiller 3000
Nov 28, 2006

by Lowtax

sund posted:

one sentence answer please why do people think NULL is a travesty?

a programming language where anything can be null is like a human language where every sentence comes with an attached ", or maybe not"

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

BattleMaster posted:

i've used goto twice in embedded applications. the first was in a parser and was essentially identical to the do { } while (false) thing so that it could exit with common cleanup code even if there was an error (this saved a nontrivial amount of program space on my 8-bit micro with 32 kb of program space over other solutions, and i actually needed those bytes for other things). the other was to break out of nested switch blocks in the command packet handler for a usb device stack.

i'm not going to whitewash the latter case since it could probably have been done without nested switch-cases, but i would rather use goto in the former case over the do { } while (false)

on the other hand my cs grad boyfriend refuses to accept goto because he learned in school it was bad and he wanted to disown me after i showed him those things back to back

just use gotos when you need them. back when dijkstra wrote his letter, goto was the only choice, there was no do-while loop to use instead.

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

Wheany posted:

just use gotos when you need them. back when dijkstra wrote his letter, goto was the only choice, there was no do-while loop to use instead.

i agree. i find gotos very helpful in languages without exceptions when i want to jump to cleanup code when im in a failure state. the kind of gotos that are dangerous are when you program like this is till ancient BASIC and the only kind of flow control you have is goto <line>. that poo poo gets impossible to trace really fast with any kind of complexity in the logic.

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat

BattleMaster posted:

the other was to break out of nested switch blocks in the command packet handler for a usb device stack.

ill admit that the majority of my goto usage was for urb_destroy

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Awia posted:

id probably not use a goto just because at least with break you know it goes to the end of the block instead of somewhere else in the file

ignoring the fact that ctrl+f exists

if you have to ctrl-f the target it's probably too far away. i don't have a problem with local gotos as long as they aren't being used for cthulean control flow, but the jump target really does need to be obvious from the point of the goto and ideally on the same screen

HoboMan
Nov 4, 2010

10 PRINT "i am a bad programmer"
20 GOTO 10

oh no blimp issue
Feb 23, 2011

Plorkyeran posted:

if you have to ctrl-f the target it's probably too far away. i don't have a problem with local gotos as long as they aren't being used for cthulean control flow, but the jump target really does need to be obvious from the point of the goto and ideally on the same screen

quite true i suppose

Condiv
May 7, 2008

Sorry to undo the effort of paying a domestic abuser $10 to own this poster, but I am going to lose my dang mind if I keep seeing multiple posters who appear to be Baloogan.

With love,
a mod


I imagine people treated for and while the same way they currently treat option types

" why bother with while and for when I have goto :confused:"

qntm
Jun 17, 2009
The point is, ladies and gentlemen, that goto, for lack of a better word, is good. Goto is right, goto works. Goto clarifies, cuts through,

qntm
Jun 17, 2009

JewKiller 3000 posted:

a programming language where anything can be null is like a human language where every sentence comes with an attached ", or maybe not"

gonadic io
Feb 16, 2011

>>=

Condiv posted:

I imagine people treated for and while the same way they currently treat option types

" why bother with while and for when I have goto :confused:"

Soricidus
Oct 21, 2010
freedom-hating statist shill
kotlin looks kinda nice, definitely a more palatable java replacement than scala. maybe I'll give it a go for my next terrible side project

Condiv
May 7, 2008

Sorry to undo the effort of paying a domestic abuser $10 to own this poster, but I am going to lose my dang mind if I keep seeing multiple posters who appear to be Baloogan.

With love,
a mod


Soricidus posted:

kotlin looks kinda nice, definitely a more palatable java replacement than scala. maybe I'll give it a go for my next terrible side project

i love scala. does kotlin have any type class capability?

HoboMan
Nov 4, 2010

ok bad programmer braintrust, riddle me this: i have a String object that i need to be a regular string, should i just cast it or call ToString()?

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat

Soricidus posted:

kotlin looks kinda nice, definitely a more palatable java replacement than scala. maybe I'll give it a go for my next terrible side project

it targets jvm 1.6 so it works on blandroid (lol), but also will compile to javascript.

also it has inline functions, overloading of methods with generic parameters (although only during compile time), and has some other nice stuff.

i like it.

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat

Condiv posted:

i love scala. does kotlin have any type class capability?

no, but it has extension functions and you can add extension functions to a class without inheriting it so you can have some of that functionality

AWWNAW
Dec 30, 2008

HoboMan posted:

ok bad programmer braintrust, riddle me this: i have a String object that i need to be a regular string, should i just cast it or call ToString()?

is it a String or an object? String is string. if it's an object, just call object.ToString() as long as it's not null, IT'S NOT NULL IS IT?

netcat
Apr 29, 2008

HoboMan posted:

ok bad programmer braintrust, riddle me this: i have a String object that i need to be a regular string, should i just cast it or call ToString()?

string and String are the same thing

HoboMan
Nov 4, 2010

not according to visual studio apparently

e: i got a thing that needs a string and when i pass it a String it's complaining about getting an object

HoboMan fucked around with this message at 22:11 on Mar 25, 2016

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

netcat posted:

string and String are the same thing

not quite. String is the .net implementation of the string object. strictly speaking, string is the C# alias to String. right now if you declare a string you'll get a String, but this isnt required to be the case and you could see a change of implementation in the future :)

Condiv
May 7, 2008

Sorry to undo the effort of paying a domestic abuser $10 to own this poster, but I am going to lose my dang mind if I keep seeing multiple posters who appear to be Baloogan.

With love,
a mod


today i learned how to define a list that holds objects that implement a specific typeclass in scala

code:
// my typeclass
trait Buttlike[A] {
	def touchIt(a: A): String
}

//wrapper to smuggle the type in, thanks type erasure
case class Ev[TC[_], A](a: A)(implicit val ev: TC[A])

class BigButt

class TinyButt

//implementing the typeclasses for the butts
implicit object BigButtIsButtlike extends Buttlike[BigButt] {
	def touchIt(a: BigButt) = "fart"
}

implicit object TinyButtIsButtlike extends Buttlike[TinyButt] {
	def touchIt(b: TinyButt) = "poo poo"
}

//my list!
val l = List(Ev(new BigButt), Ev(new TinyButt))

//gonna touch those butts
l.map(_ match { case e @ Ev(a) => e.ev.touchIt(a)}) //List("fart", "poo poo")
:lsd:

Condiv fucked around with this message at 22:21 on Mar 25, 2016

HoboMan
Nov 4, 2010

let me say that all the sample code that is all butts and turds and farts makes me laugh every time

Soricidus
Oct 21, 2010
freedom-hating statist shill

Condiv posted:

i love scala. does kotlin have any type class capability?

i hope not, because the main thing i don't like about scala is that it has too many features. i mean fancy type system hacks where you write the cleverest code you can are great fun and all, but at the end of the day i just want to be writing code that i'm going to be able to understand again in six months' time, and i personally find that having something with limitations - like java - is useful for that.

all i really want from a new language is java but with most of the warts removed and some modest improvements like var and properly designed nullable types

HoboMan
Nov 4, 2010

so c#?

Soricidus
Oct 21, 2010
freedom-hating statist shill
c# doesn't have properly designed nullable types (only for value types), and also i should perhaps have specified that by "java, but with ..." i mean it runs on the jvm and builds with maven.

Condiv
May 7, 2008

Sorry to undo the effort of paying a domestic abuser $10 to own this poster, but I am going to lose my dang mind if I keep seeing multiple posters who appear to be Baloogan.

With love,
a mod


Soricidus posted:

i hope not, because the main thing i don't like about scala is that it has too many features. i mean fancy type system hacks where you write the cleverest code you can are great fun and all, but at the end of the day i just want to be writing code that i'm going to be able to understand again in six months' time, and i personally find that having something with limitations - like java - is useful for that.

all i really want from a new language is java but with most of the warts removed and some modest improvements like var and properly designed nullable types

utilizing the typesystem to make union types, or type functions, etc is p nice when i have a project that needs a strong type system

raminasi
Jan 25, 2005

a last drink with no ice

HoboMan posted:

not according to visual studio apparently

e: i got a thing that needs a string and when i pass it a String it's complaining about getting an object

post some code, somethin' ain't right

HoboMan
Nov 4, 2010

Soricidus posted:

c# doesn't have properly designed nullable types (only for value types), and also i should perhaps have specified that by "java, but with ..." i mean it runs on the jvm and builds with maven.

oh sorry i missed the "properly designed" part.

gently caress i love maven. it's the only thing i miss about being a java dev. is there anything remotely similar for c#?

e: ^i just called ToString() and called it a day. this is the terrible programmers thread

HoboMan fucked around with this message at 22:48 on Mar 25, 2016

raminasi
Jan 25, 2005

a last drink with no ice

HoboMan posted:

oh sorry i missed the "properly designed" part.

gently caress i love maven. it's the only thing i miss about being a java dev. is there anything remotely similar for c#?

e: ^i just called ToString() and called it a day. this is the terrible programmers thread

nuget, depending on how flexible you're willing to get with "remotely"

fritz
Jul 26, 2003

Condiv posted:

today i learned how to define a list that holds objects that implement a specific typeclass in scala
:lsd:

ive been meaning to learn a scala, what's that Ev stuff about

Condiv
May 7, 2008

Sorry to undo the effort of paying a domestic abuser $10 to own this poster, but I am going to lose my dang mind if I keep seeing multiple posters who appear to be Baloogan.

With love,
a mod


fritz posted:

ive been meaning to learn a scala, what's that Ev stuff about

basically, typeclasses in scala are not a first class form of polymorphism. I can't say "val x: List[Buttlike] = List(new TinyButt, new BigButt)" because neither TinyButt or BigButt are subtypes of Buttlike. since my list is composed of multiple types with no common supertype other than Any (scala's slightly more powerful Object), the type of my list will end up as Any if I put them in the list normally. the Ev class is there to contain type evidence (basically, to prevent the underlying types from being completely erased) so i can still use the types in the list with the typeclass Buttlike.

anyway, none of this is really very important to get use out of scala. i'm just mucking about with the type system to see what i can get scala to do while still maintaining type safety

Condiv fucked around with this message at 01:13 on Mar 26, 2016

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:

compilers won't even warn you if you forget to check though

the clang static analyzer can actually, and you can use its annotations on your own code too

one problem in the UNIX world though is that there's almost 40 years of code now that assumes allocation can't fail due to VM overcommit, so nobody actually checks the result of malloc/calloc/realloc or anything built on top of them

then you run on a system without a pager and oops! you just need to have processes die instead of gracefully recover because evidently the knowledge of how to do that went away with the 80s

Adbot
ADBOT LOVES YOU

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?

LeftistMuslimObama posted:

at least 0 as null has historical reasoning behind it. outside of some exceptional architectures the page starting at 0x0 is off-limits typically so if you dereference a pointer with a value of 0 it's likely you've messed up.

this historically wasn't the case though, it's a recent thing; many systems used low-memory globals because CPUs had specific instructions for accessing the zero page

68K kept its vector table at 0, for example, 6502 had short zero-page instructions, and TMS9900 didn't even have registers just shorthand (and on-chip cache) for locations 0-15

  • Locked thread