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
Shaggar
Apr 26, 2006
if you throw away all the unix stuff the unix philosophy isn't bad.

Adbot
ADBOT LOVES YOU

tef
May 30, 2004

-> some l-system crap ->

Shaggar posted:

if you throw away all the unix stuff the unix philosophy isn't bad.

(yep, there's a lot of crud there but it advocates building systems out of a component architecture, but a radically simpler one based around binary streams between chunks)

Luigi Thirty
Apr 30, 2006

Emergency confection port.

Shaggar posted:

y'all need to go back and read some wpf tutorials and stay away from stack overflow until you get the tutorials to work.

some days I can't get out of bed and some days I furiously work on thing for 12 hours straight with no breaks and that was one of those days

BONGHITZ posted:

just make a command line program, all the best programs are command line programs

i have only ever done this and web things which is why uis are stupid and confusing

Bloody posted:

i still use winforms for my half hour long bespoke serial port bangers

the Internet told me winforms is dead and do everything in wpf from now on

Careful Drums
Oct 30, 2007

by FactsAreUseless
hey is wpf like the same thing for metro/wp8 apps? because i tried that once and it looked a lot like that xaml there.

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

Careful Drums posted:

hey is wpf like the same thing for metro/wp8 apps? because i tried that once and it looked a lot like that xaml there.
they're very similar, but there are some important differences. first is that there's a bunch of WinRT interfaces that you can call from Win8 apps but not from WPF apps. metro UI stuff falls in this category. second is that there's a huge range of .NET interfaces, libraries and general functionality that isn't available from Win8 apps. code generation for example is completely verboten, which torpedoes stuff like mocking libraries

Luigi Thirty
Apr 30, 2006

Emergency confection port.

Shaggar posted:

the whole thing you're doing with the static instance is really weird, dude.

if you're gonna use a static instance (idk why you would) then set it as the data context of your view

in MainWindow.xaml.cs:
C# code:

public MainWindow()
{
	InitializeComponent();
	this.DataContext = BlackjackViewModel.Instance;

}
Then in MainWindow.xaml
XML code:
<Window x:Class="BlackjackGame.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:classes="clr-namespace:BlackjackGame"
        Title="MainWindow" Height="480" Width="640">
    <Grid>
        <Label x:Name="lblPlayerTotal" Content="{Binding PlayerTotal}" HorizontalAlignment="Left" Margin="10,264,0,0" VerticalAlignment="Top" Width="38"/>
        <Label x:Name="lblDealerTotal" Content="{Binding DealerTotal}" HorizontalAlignment="Left" Margin="10,160,0,0" VerticalAlignment="Top"/>
    </Grid>
</Window>
{Binding PropertyName} causes the binder to look for that PropertyName as a path on the local data context. Since we set the local data context to an object of type BlackjackViewModel, those paths should be readily available. UpdateSourceTrigger=PropertyChanged is redundant since its the default.

Also, since .net 4, the compiler will automatically add the INPC cruft to basic properties so your viewmodel can be simplified to this:

C# code:
class BlackjackViewModel
{
	private static BlackjackViewModel __instance = null;

	static BlackjackViewModel()
	{
		__instance = new BlackjackViewModel();
	}

	public int CardsRemaining { get; set; }
	public int PlayerTotal { get; set; }
	public int DealerTotal { get; set; }

	public static BlackjackViewModel Instance
	{
		get { return __instance; }
	}

}
also, to make INPC a little easier, create an abstract class like this:

C# code:
public abstract class NotifyPropertyChanged : INotifyPropertyChanged
{
	public event PropertyChangedEventHandler PropertyChanged;

	protected virtual void OnPropertyChanged(string propertyName)
	{
		if (this.PropertyChanged != null)
		{
			this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
		}
	}
}
and then if you want to do notifications, have your viewmodel extend NotifyPropertyChanged instead of implementing INotifyPropertyChanged. You can then call the OnPropertyChanged method like you're doing currently, but you don't need to write it over and over in each viewmodel.

NOPE THEY'RE ALL STILL 0

i swear to god i'll paypal 5 dollars to whoever can make these loving labels update i am absolutely furious and i'm never touching wpf again without a 1500 page loving reference book that i bought off the loving internet

Careful Drums
Oct 30, 2007

by FactsAreUseless
fiverr.com

oh no blimp issue
Feb 23, 2011

coffeetable posted:

i didnt think much of code complete & the pragmatic programmer. lotta pages that say very little

ones i have been impressed by so far
  • The Practice of Programming. its everything that prag prog and code complete covers, but in <300 pages. tef's standard recommendation.
  • Working Effectively with Legacy Code. its claimed subject is fixing other people's fuckups, but in doing so it has a lot to say about how to design & structure yr programs. think suspicious dish recommended me this one
  • The Algorithm Design Manual. best algorithms book around. fuuuuuuuck CLRS.
  • Learn You A Haskell. not to actually learn haskell (though its v cool), but just so's you properly understand there are alternatives to OO
but more generally, just cultivate an interest in some pet topic and practice.

i shall remember these, thanks!

tef posted:

any book spine wider than your thumb is probably a reference manual, or reads like one. or worse, somewhere between a manual and a textbook and suitable for neither.

if you have some specific goal in mind of where you want to practice programming, we can probably give you better recommendations. "How do i make faster software" "how do i make maintable software"

but a lot of technical problems often boil down to social problems, so learning to work in a team and communicating well are probably the skills you want to hone the most to set you apart.
i was honestly being a bit facetious, but generally i was looking for algorithms books, which coffeetable sorted me on
i havent coded enough to know what i actually need to know, thats why i was looking more for books on general topics

Blinkz0rz
May 27, 2001

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

coffeetable posted:

reactiveui's documentation is non-existent, but off the top of my head
- use ObservableForProperty to get an observable for listview.SelectedItem
- subscribe your command to the shiny new observable

e: oh cool you don't need ObservableForProperty any more, the .WhenAny extension method will now construct it implicitly when you call it on an object

i can't decide if i'm stupid or if reactive is doing something dumb

i have a reactivelist<viewmodel>() with an reactivecommand<ienumerable<model>> subscribed to text in a textbox. when the text changes i'm using a throttled whenanyvalue call to invoke the command.

all i want to do is invoke another command when an item in the reactivelist is selected. it feels like this should work
code:
this.WhenAny(x => x.List, m => m.Value)
    .Throttle(TimeSpan.FromMilliseconds(500), RxApp.MainThreadScheduler)
    .InvokeCommand(UpdateNewList);
but obviously the second reactivecommand isn't firing. in my xaml i have a selecteditem binding but i can't figure out how to do anything with that either

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

Luigi Thirty posted:

NOPE THEY'RE ALL STILL 0

i swear to god i'll paypal 5 dollars to whoever can make these loving labels update i am absolutely furious and i'm never touching wpf again without a 1500 page loving reference book that i bought off the loving internet
aight. that thing is a horror show and a shining example of what happens when you try to program by pattern-matching against Google results.

let's talk about how bindings work in WPF: by writing Content={Binding PlayerTotal}, you request that the program searches up the UI tree until it finds a UI element with a DataContext object that has an PlayerTotal property.

when it finds such an object with such a property, it does two things: first, it uses the property's current value to set the Content attribute. second, if the object implements IPropertyNotifyChanged, it'll subscribe to the PropertyChanged event. when someone raises the PropertyChanged event, they supply the name of the property that's been changed, and anyone who's interested in that property will then check to see what the new value is.

so the convention is that you raise the PropertyChanged event from inside the setter for each property you want to bind to. most MVVM frameworks have some way to make this simpler: in ReactiveUI's case, you inherit from ReactiveObject and write your properties as
code:
string name;  
public string Name {  
    get { return name; }
    set { this.RaiseAndSetIfChanged(ref name, value); }
}
now, using this knowledge, here's how to fix your labels:
  • set the DataContext object somewhere in your visual hierarchy to an instance of BlackjackViewModel. AN INSTANCE OF. not a static. INotifyPropertyChanged isnt a static interface (because they don't exist in C#), so it can't possibly be implemented by a static.
  • implement INotifyPropertyChanged on BlackjackViewModel
  • rewrite the properties of BlackjackViewModel so they raise the PropertyChanged event
  • every time a card is dealt, update the value of the relevant property in your instance of BlackjackViewModel. and just to be clear, that's THE SAME INSTANCE AS THE ONE YOU SET THE DATA CONTEXT TO.
if you don't understand these steps, do not blindly loving implement them. ask for clarification.

Bloody
Mar 3, 2013

sounds like a pain in the rear end how is it any better than the old pain in the rear end way of doing it

Shaggar
Apr 26, 2006

Careful Drums posted:

hey is wpf like the same thing for metro/wp8 apps? because i tried that once and it looked a lot like that xaml there.

yes. they are the same from a syntax and usage standpoint but the metro/wp8 runtime has different, metro specific ui components. the biggest difference is Microsoft has certain ui guidelines for metro apps that you're supposed to follow. w/ wpf apps you can do w/e

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY
this bit
code:
var observable = this.WhenAny(x => x.List, m => m.Value)
    .Throttle(TimeSpan.FromMilliseconds(500), RxApp.MainThreadScheduler)
creates an IObservable, which is a posh way of saying "a sequence of objects in time". what you want is for UpdateNewList to be called every time a new object arrives. to do that, you want to subscribe to the observable, which you do by writing
code:
observable.Subscribe(x => UpdateNewList(x))
or at least, i think so. it's hard to tell w/o seeing the whole program.

as an aside, Introduction to Rx is $1.32 on Amazon and both a good read and a light read. well worth it if you're gonna be mucking about with Rx a lot.

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

Bloody posted:

sounds like a pain in the rear end how is it any better than the old pain in the rear end way of doing it

Malcolm XML posted:

winforms suffers from being totally loving horrible for anything complex

Blinkz0rz
May 27, 2001

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

coffeetable posted:

this bit
code:
var observable = this.WhenAny(x => x.List, m => m.Value)
    .Throttle(TimeSpan.FromMilliseconds(500), RxApp.MainThreadScheduler)
creates an IObservable, which is a posh way of saying "a sequence of objects in time". what you want is for UpdateNewList to be called every time a new object arrives. to do that, you want to subscribe to the observable, which you do by writing
code:
observable.Subscribe(x => UpdateNewList(x))
or at least, i think so. it's hard to tell w/o seeing the whole program.

as an aside, Introduction to Rx is $1.32 on Amazon and both a good read and a light read. well worth it if you're gonna be mucking about with Rx a lot.

all good, i figured it out. turns out i wasn't binding to the view.list.selecteditem so the whenany wasn't actually firing

i really wish the dude who does reactive would produce some decent docs because his library is great except trying to parse his xml documentation is a special kind of hell

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Luigi Thirty posted:

i have only ever done this and web things which is why uis are stupid and confusing


umm excuse me??? web things and CLIs ARE user interfaces stupid!

BONGHITZ
Jan 1, 1970

we are all webapps

Shaggar
Apr 26, 2006

Luigi Thirty posted:

NOPE THEY'RE ALL STILL 0

i swear to god i'll paypal 5 dollars to whoever can make these loving labels update i am absolutely furious and i'm never touching wpf again without a 1500 page loving reference book that i bought off the loving internet

that's pretty bad dude, but there are 2 problems. the biggest one is the viewmodel you're changing isn't the one you set as your data context.

either change

static BlackjackViewModel blackjackViewModel = new BlackjackViewModel();
to
static BlackjackViewModel blackjackViewModel = BlackjackViewModel.Instance;

or change this.DataContext=BlackjackViewModel.Instance;
to
this.DataContext=blackjackViewModel;

You are basically creating a static field on your view named blackjackViewModel and that's what you're doing all your updates do but you are initializing it using a protected constructor instead of accessing the singleton you created for Instance. you shouldn't be using a singleton at all but w/e.

the second, is that for some reason w/ this project its not updating the viewmodel w/out INPC. I fixed the datacontext above and then added the notify change stuff back in and it works.

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS
idk why he's using a static viewmodel (he might have mentioned it before) but it basically sounds like he wants a singleton instead

Shaggar
Apr 26, 2006
hes doing both and neither.

his viewmodel is sort of supposed to be used as a singleton, but hes also accidentally creating a separate static instance inside his view. hes doing it so his goofy event handling can access the viewmodel.

luigi, when it is done right this is what MainWindow.xaml.cs should look like

C# code:

namespace BlackjackGame
{

	public partial class MainWindow : Window
	{
		public MainWindow()
		{
			InitializeComponent();
			this.DataContext = new BlackjackViewModel();
			
		}
	}
}

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

coffeetable posted:

i didnt think much of code complete & the pragmatic programmer. lotta pages that say very little

ones i have been impressed by so far
  • The Practice of Programming. its everything that prag prog and code complete covers, but in <300 pages. tef's standard recommendation.
  • Working Effectively with Legacy Code. its claimed subject is fixing other people's fuckups, but in doing so it has a lot to say about how to design & structure yr programs. think suspicious dish recommended me this one
  • The Algorithm Design Manual. best algorithms book around. fuuuuuuuck CLRS.
  • Learn You A Haskell. not to actually learn haskell (though its v cool), but just so's you properly understand there are alternatives to OO
but more generally, just cultivate an interest in some pet topic and practice.

seconding The Algorithm Design Manual. it's very straight to the point, the stories are fun to read and the second chapter is the best reference on algorithms in general that I've seen.

I faintly recall that someone recommended it to Pollyanna and she didn't like it :(

Nomnom Cookie
Aug 30, 2009



tef posted:

(yep, there's a lot of crud there but it advocates building systems out of a component architecture, but a radically simpler one based around binary streams between chunks)

the loose coupling part of The Unix Philosophy* is good. the fetishizing of byte streams and the utopian ideal of a single namespace with identical semantics for all members, not so good. i think the useful principle you can extract from that is to use the dumbest transport which will get the job done

* haven't read the book, just going by the rantings of kooks on LWN and reddit

BONGHITZ
Jan 1, 1970

Symbolic Butt posted:

seconding The Algorithm Design Manual. it's very straight to the point, the stories are fun to read and the second chapter is the best reference on algorithms in general that I've seen.

I faintly recall that someone recommended it to Pollyanna and she didn't like it :(

books r hard 2 read

Luigi Thirty
Apr 30, 2006

Emergency confection port.

okay i rewrote it to get rid of the dumb event processing, the half-rear end singleton, and made the viewmodel non-static among other things. now i can see my totals and they update when i set them in the viewmodel!

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

Luigi Thirty posted:

okay i rewrote it to get rid of the dumb event processing, the half-rear end singleton, and made the viewmodel non-static among other things. now i can see my totals and they update when i set them in the viewmodel!

wow its like if u buy into the mvvm pattern wpf is great!!!!

Shaggar
Apr 26, 2006

Luigi Thirty posted:

okay i rewrote it to get rid of the dumb event processing, the half-rear end singleton, and made the viewmodel non-static among other things. now i can see my totals and they update when i set them in the viewmodel!

I would also separate your game logic into another class. I might write up a basic example when I get home.

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

Luigi Thirty posted:

okay i rewrote it to get rid of the dumb event processing, the half-rear end singleton, and made the viewmodel non-static among other things. now i can see my totals and they update when i set them in the viewmodel!
great. now take a minute to sit back and think about how your way of approaching the problem cost you 6hrs yesterday, and what you should do differently in future

Luigi Thirty
Apr 30, 2006

Emergency confection port.

Malcolm XML posted:

wow its like if u buy into the mvvm pattern wpf is great!!!!

here lies luigi

shaggar was right

PleasureKevin
Jan 2, 2011

angular or ember?

Shaggar
Apr 26, 2006
neither. use knockout

PleasureKevin
Jan 2, 2011

i'm going to just infer from knockout's bad website that it's terrible.

Shaggar
Apr 26, 2006
the only javascripts you should use are jquery and knockout. and even knockout is only for weird edge cases where you don't have a web application server to write your pages for you.

Shaggar
Apr 26, 2006
angular is beyond overkill

MeruFM
Jul 27, 2010
i've come around on the superframeworks like angular and ember

they make sites feel a lot faster when done well

MeruFM
Jul 27, 2010
angular has bad documentation of decent features
ember has well documented bad features

Mr. Bonkers
Sep 21, 2006

You're wrong and you're a grotesquely ugly freak
knockout is angular done right.

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison

Shaggar posted:

the only javascripts you should use are jquery and knockout. and even knockout is only for weird edge cases where you don't have a web application server to write your pages for you.

ayy lmao

Fuck them
Jan 21, 2011

and their bullshit
:yotj:

Shaggar posted:

the only javascripts you should use are jquery and knockout. and even knockout is only for weird edge cases where you don't have a web application server to write your pages for you.

What do you mean by web application server to write pages for you exactly? Are you talking about the foreach?

Also, besides a gun to my head, is there any reason to gently caress with gridviews or other forms poo poo if dataTables and webAPI continues to exist?

Forms is loving weird.

Shaggar
Apr 26, 2006
iis/tomcat/etc... are web app servers. they run web app frameworks like ASP.net MVC or Spring MVC.

Generate your page from the server. Don't generate your page with javascript.

Adbot
ADBOT LOVES YOU

Shaggar
Apr 26, 2006
stay away from asp forms poo poo. use MVC and the templates that come w/ it. or write your own templates or get templates from somewhere else. someones probably already written a library to add razor helpers for generating jquery datatables.

altho if you really want to you could do just html/js and then use webapi to deliver the data into a datatable. but now u have html sitting somewhere, unattended and untemplated.

  • Locked thread