After a night of debugging friend's code...
![]()
Take off the >10 on there, if you're checking if it is less than 10, then the greater than 10 is superfluous(also would cause a problem on exactly 10. Beyond that, I don't know the Visual Basic syntax.
I still did it and no cigar.
If Val(TextBox1.Text) < 10 Then
Label6.Text = 1
ElseIf
Val(TextBox1.Text) < 41
Label6.Text = 2
End If
It says an error right at 41.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim earnings As Double
Dim earnings2 As Double
Dim earnings3 As Double
If Val(TextBox1.Text) < 10 Then
Label6.Text = 1
ElseIf Val(TextBox1.Text) < 41 Then
Label6.Text = 2
ElseIf Val(TextBox1.Text) < 100 Then
Label6.Text = 4
ElseIf Val(TextBox1.Text) > 100 Then
Label6.Text = 8
End If
earnings = Val(TextBox1.Text) * 10
earnings2 = Val(TextBox1.Text) / 1000
earnings3 = Val(TextBox1.Text) * Val(Label6.Text) / 10
Label5.Text = String.Format("{0:C}", earnings)
Label7.Text = String.Format("{0:C}", earnings3)
End Sub
End Class
I'm trying to remember a word I recently used to describe code in which the focus is the result, not the implementation. Such code should be concise, and readable because it doesn't repeat implementation details over and over.
I think the word began with a 'C'. It's driving me mad. Any thoughts?
Declarative programming tends to exhibit this property when done well, but I'm thinking of a more general adjective.Declarative programming?
I've put a webserver on it, but it wasn't public-facing. And I only loaded it a few times to see if it worked.Anyone ever heard/used a raspberry pi as a webserver? I have two domains and I figure the pi should be enough to handle some messing about with for now.
Anyone ever heard/used a raspberry pi as a webserver? I have two domains and I figure the pi should be enough to handle some messing about with for now.
I've put a webserver on it, but it wasn't public-facing. And I only loaded it a few times to see if it worked.
I was using Go, which has its own webserver in the net/http module and it's easy to compile for ARM.
My brother has one that he uses at a webserver but I don't know what exactly he does with it. I'll ask and report back.
Correct. If your code only uses standard libraries, it should build without issue in gcc or clang. (If you don't have a preference, use clang.) At most, they might warn you about some things which VS does not notice. Going the other way, developing on gcc or clang and trying to later build with VS doesn't necessarily go as smoothly. VS lacks support for a lot of standard language and library features. Most of that difference should disappear when VS2013 arrives though.Question on C/C++
If I'm coding in VS and using it to compile. Assuming I'm only using the standard libraries, the code is essentially portable if I rebuild the source in say linux with GCC. Correct?
Correct. If your code only uses standard libraries, it should build without issue in gcc or clang. (If you don't have a preference, use clang.) At most, they might warn you about some things which VS does not notice. Going the other way, developing on gcc or clang and trying to later build with VS doesn't necessarily go as smoothly. VS lacks support for a lot of standard language and library features. Most of that difference should disappear when VS2013 arrives though.
clang is designed to be modular and to expose its capabilities easily to other tools. It's just one purpose of many that editors or their plugins can use clang to power their C++ syntax highlighters, intelligent autocompletion, etc. To carry out those tasks perfectly, a tool would actually have to understand all the nooks and crannies of C++. That has been a completely infeasible task for people writing editors or plugins, because it amounts to writing a substantial part of a full C++ compiler. So the usual thing to do has been to fake some level of understanding with a few simple approximation rules that get it right 95% of the time and fail the rest of the time. Since clang is a compiler and understands 100% of the language, allowing tools to tap into its knowledge enables them to produce perfect results.Oh neat, glad I asked. Also what makes clang so great. I know in some regard it's precompile can give a sort of heightened syntax highlighting and error detection correct?
Declarative programming was the obvious one, but: constraint programming? Logic programming? Just plain old functional programming? Haskell?I'm trying to remember a word I recently used to describe code in which the focus is the result, not the implementation. Such code should be concise, and readable because it doesn't repeat implementation details over and over.
I think the word began with a 'C'. It's driving me mad. Any thoughts?
UPDLOCK blocks on update. Based on http://msdn.microsoft.com/en-us/library/ms173763.aspx (your query is set to READ COMMITTED), my guess is that there are individual row locks interfering between the two transactions. Are you positive that concurrent updating is really going to improve efficiency if you select all the same rows? SQL Server has to acquire locks on the physical pages of the hard disk when it writes to them so unless the table is spread across multiple disks it may not be possible to physically commit the data to disk simultaneously. See http://blog.sqlauthority.com/2011/0...latch_sh-pagelatch_up-wait-type-day-12-of-28/. SQL Server is extremely complex and I strongly recommend you get a DBA at your company to take a look at what you're doing.Have fun with it. The parsing and storing of the data is just sort of ridiculous. If you have a global feed it's just so much data that it's hard to deal with. If you're getting it in raw NMEA format parsing it can be tough, and from my experience the open source parsers are pretty slow.
I was hoping to be able to concurrently update/insert AIS positions to the database, but whenever 2 transactions happen at once I get deadlocks galore. I'm not sure what I am doing wrong. I don't even know if JDBC supports snapshot isolation levels either. I basically have 1000 of those store proc calls in a single batch transaction. I was hoping to be able to execute multiple transactions at once to reduce the overhead from I/O across the network. I've basically just had to increase the batch size so that no actual concurrency occurs because of the frequency of the deadlocks.
while(stuff) {
//do stuff
} finish {
//stuff to finish after loop
}
What's wrong withdo any languages have a logical control that is something like
Code:while(stuff) { //do stuff } finish { //stuff to finish after loop }
essentially an elegant way of doing one time concluding tasks, like updating a field after building it, or closing buffers. Surprised I have never seen stuff like this.
Wondering because it would make readability in my code a lot better (java/groovy atm)
while(stuff) {
// do stuff
}
// stuff to finish after loop
What's wrong with
?Code:while(stuff) { // do stuff } // stuff to finish after loop
if(condition to check) {
while(same condition) {
}
finish stuff
}
try/catch/finally?
do any languages have a logical control that is something like
Code:while(stuff) { //do stuff } finish { //stuff to finish after loop }
essentially an elegant way of doing one time concluding tasks, like updating a field after building it, or closing buffers. Surprised I have never seen stuff like this.
Wondering because it would make readability in my code a lot better (java/groovy atm)
I'm trying to remember a word I recently used to describe code in which the focus is the result, not the implementation. Such code should be concise, and readable because it doesn't repeat implementation details over and over.
I think the word began with a 'C'. It's driving me mad. Any thoughts?
My brother has one that he uses at a webserver but I don't know what exactly he does with it. I'll ask and report back.
import com.twitter.scalding._
import scala.util.parsing.json._
class BigDataCount(args : Args) extends Job(args) {
TextLine( args("input") )
.map('line -> ('id, 'isBig)) { line : String => countThings(line) }
.filter('id) { id : Integer => id >= 0 }
.groupBy('id) { _.max('isBig) }
.flatMap('isBig -> 'counter) {
isBig : Boolean => {
if (isBig) {
List("any", "big data")
} else {
List("any")
}
}
}
.groupBy('counter) { _.size }
.write( Tsv( args("output") ) )
def countThings(text : String) : (Integer, Boolean) = {
var result = JSON.parseFull(text)
result match {
case Some(map : Map[String, Any]) =>
(
map.get("id") match {
case Some(id : Double) => id.toInt
case _ => -1
},
map.get("product_desc") match {
case Some(desc : String) => desc.toLowerCase contains "big data"
case _ => false
}
)
case _ => (-1, false)
}
}
}
procx((X,Y,R),TopNext) :-
procx((X,Y),R,(0,0,0),TopNext),
!.
procx((X,R),TopNext) :-
!,
procx((X),R,(0,0,0),TopNext).
procx(X,TopNext) :-
procx((X),0,0,0,_,_,TopNext).
procx(X,(Y,Z,R),(U,Bot,Top),TopNext) :-
!,
procx(X,U,Bot,Top,UNext,BotNext,TopNextTemp),
procx((Y,Z),R,(UNext,BotNext,TopNextTemp),TopNext).
procx(X,(Y,Z),(U,Bot,Top),TopNext) :-
!,
procx(X,U,Bot,Top,UNext,BotNext,TopNextTemp),
procx(Y,Z,(UNext,BotNext,TopNextTemp),TopNext).
procx((_,_),_,_,_) :-
!,
fail.
procx(X,Y,(U,Bot,Top),TopNext) :-
procx((X,Y),U,Bot,Top,_,_,TopNext).
procx((X,Y),U,Bot,Top,UNext,BotNext,TopNext) :-
!,
procx((Bot - U) * 100 + X * 10 + Y,Top,UNext,BotNext,TopNext).
procx((X),U,Bot,Top,UNext,BotNext,TopNext) :-
procx((Bot - U) * 10 + X,Top,UNext,BotNext,TopNext).
procx(Bot,Top,UNext,BotNext,TopNext) :-
BotNext is Bot,
SideNext is 2 * Top,
between(1,10,VMax),
(VMax * (SideNext * 10 + VMax) > Bot -> true ; VMax is 10),
!,
VNext is VMax - 1,
UNext is VNext * (SideNext * 10 + VNext),
TopNext is Top * 10 + VNext.
I'm actually doing cross-platform development with VS 2012 and Clang right now and I noticed a feature missing from Clang that worked in VS 2012 (the put_time() function, which is part of the standard library and is still missing from the libstdc++ implementation) Apart from that, Clang as of version 3.3 or so supports all of the C++11 standard and I believe they already started on some of C++14's features.Correct. If your code only uses standard libraries, it should build without issue in gcc or clang. (If you don't have a preference, use clang.) At most, they might warn you about some things which VS does not notice. Going the other way, developing on gcc or clang and trying to later build with VS doesn't necessarily go as smoothly. VS lacks support for a lot of standard language and library features. Most of that difference should disappear when VS2013 arrives though.
What about C# finally statement?do any languages have a logical control that is something like
Code:while(stuff) { //do stuff } finish { //stuff to finish after loop }
essentially an elegant way of doing one time concluding tasks, like updating a field after building it, or closing buffers. Surprised I have never seen stuff like this.
Wondering because it would make readability in my code a lot better (java/groovy atm)
Prolog (square root function)
It results in really natural representations for a lot of problems in AI. Square root is a really bad example of something to do in PrologMaybe the way I got introduced to it was bad, but for me Prolog is hell. I honestly didn't think one time "man, this is easier than in other languages".
Not quite what he wants. What he wants is actually really strange. Consider the following C program:What about C# finally statement?
http://msdn.microsoft.com/en-us/library/zwc8s4fz(v=vs.71).aspx
[b]extern[/b] [b]void[/b] dummy ([b]void[/b]); [i]/* Not defined -- used to force optimizer not to collapse loops, etc. */[/i]
[b]void[/b] main ([b]unsigned[/b] [b]int[/b] argc) { [i]/* We use argc because the optimizer forward propagates constants */[/i]
[b]if[/b] (argc) {
[b]while[/b] (argc) {
--argc;
dummy ();
};
dummy ();
}
}
[b]testl[/b] %ebx, %ebx
[b]je[/b] .L1
.L6:
[b]decl[/b] %ebx
[b]call[/b] dummy
[b]testl[/b] %ebx, %ebx
[b]jne[/b] .L6
[b]call[/b] dummy
.L1:
In general, if you want a smooth framerate you can't use a constant sleep time. You have to determine how long the processing in (e.g.) your rendering loop took, and then sleep for less or more time depending on that. For example, if you wanted 60 frames per second, and rendering took no time at all, you'd want to sleep for 1000 / 60 seconds (call it 17 ms), but if you collected the current time just before you started rendering, and just after, and 10 ms had elapsed, you would only want to sleep for 7 ms. And of course it gets more complicated from there--for example, if the rendering takes longer than 17 ms on some systems, you could choose to just render as fast as possible (inconsistent framerate, but closest to 60 fps), or you might want to make the target framerate configurable, so players with slower machines could experience a smooth framerate of, say, 30 fps (33 ms).Hey guys,
I'm currently writing a game in SFML 2.0 (c++). So far everything is going well but one thing confuses me the most. My game has a bunch of states where something is displayed i.e splash, main menu, stage select, game, etc.
Each state has a loop in which I've thrown a sleep function in there but I'm wondering for how many milliseconds should I sleep my game for during a loop?
I ideally want this game to run at 60 fps max/stable.
Is it normal to have states sleep at a different amount of milliseconds? Or should the whole game be consistent with it's milliseconds of sleeping?
I'm just a bit unsure how to progress with that little topic there.
Thanks!
What about C# finally statement?
http://msdn.microsoft.com/en-us/library/zwc8s4fz(v=vs.71).aspx
while(some case) {
//stuff that potentially happens
} finish {
//stuff that is needed to be done after the loop runs, if and only if the loop was actually entered. also a 1 time sort of thing that doesn't belong in the loop.
}
In general, if you want a smooth framerate you can't use a constant sleep time. You have to determine how long the processing in (e.g.) your rendering loop took, and then sleep for less or more time depending on that. For example, if you wanted 60 frames per second, and rendering took no time at all, you'd want to sleep for 1000 / 60 seconds (call it 17 ms), but if you collected the current time just before you started rendering, and just after, and 10 ms had elapsed, you would only want to sleep for 7 ms. And of course it gets more complicated from there--for example, if the rendering takes longer than 17 ms on some systems, you could choose to just render as fast as possible (inconsistent framerate, but closest to 60 fps), or you might want to make the target framerate configurable, so players with slower machines could experience a smooth framerate of, say, 30 fps (33 ms).
(There are also things like screen tearing and double buffering to consider, since the hardware has its own processes with their own timers... not to mention concerns like your physics loop being out of sync with your main loop, etc. It can get quite complicated to make things really smooth.)
That's the thing... it's really not fundamentally a clean way of representing local control flow without gotos. It actually requires generating two different comparison statements, one of which is hidden, because there are now two states to deal with--the 'initial comparison' state, and the 'loop comparison' state. Representing that explicitly isn't unclean codefinally always runs after a try, or try catch block. It is usually handling clean up, or closing out of things that have a potential to fail and through an error.
What I'm talking about doesn't really give new functionality but is a clean way of conveying a certain logical flow of control. Similarly how loops have breaks and continues to cleanly alter a loops functionality in an easily conveyable way, I was hoping while loops might have something similar to my finish suggestion.
So that could easily be done with a follow up if statement by setting some Boolean flags or what have you, but that is always unclean in code if you ask me. Guess I should write in good ol' barney and get this added to C++15
The best way to learn it is probably to read through code in existing games, and just generally gain a lot of experience on working with graphics programming. Because so much of timing is machine-dependent--including, believe it or not, the accuracy of the timer itselfLooks like I have some reading to do. I'm guessing I'll need a class solely dedicated to handling a clock and/or dealing with the framerate stuff.
That's the thing... it's really not fundamentally a clean way of representing local control flow without gotos. It actually requires generating two different comparison statements, one of which is hidden, because there are now two states to deal with--the 'initial comparison' state, and the 'loop comparison' state. Representing that explicitly isn't unclean code![]()
First off, there's such a thing as feature bloatWell we have compilers for a reason. Firstly (atleast in my mind) it makes the source code very clean and conveys exactly it's meaning. Second, it would be a matter of the compiler adding the flags and if structure around the loop, of course this would all cleanly be done in goto statements that we would never have to read.
The mere fact that there would be an extra comparison or states is really a non issue. Its such a small amount of memory on the stack, running in constant time. Not saying they should waste there time adding it, but if they had a magic wand there would be no reason not to wave it.
[b]extern[/b] [b]void[/b] dummy ([b]void[/b]); [i]/* Not defined -- used to force optimizer not to collapse loops, etc. */[/i]
[b]void[/b] main ([b]unsigned[/b] [b]int[/b] argc) { [i]/* We use argc because the optimizer forward propagates constants */[/i]
[b]if[/b] (argc) {
[b]do[/b] {
--argc;
dummy ();
} [b]while[/b] (argc);
dummy ();
}
}
[b]#define[/b] while_finally(x,y,z) [b]if[/b] (x) { [b]do[/b] { y } [b]while[/b] (x); z; }
[b]extern[/b] [b]void[/b] dummy ([b]void[/b]); [i]/* Not defined -- used to force optimizer not to collapse loops, etc. */[/i]
[b]void[/b] main ([b]unsigned[/b] [b]int[/b] argc) { [i]/* We use argc because the optimizer forward propagates constants */[/i]
while_finally (argc, {
--argc;
dummy ();
}, {
dummy ();
})
}
I disagree. I don't think it's very clear at all how "finish" would behave after a while loop just by looking at it. In fact, most people in the thread were confused even after you explained it.finally always runs after a try, or try catch block. It is usually handling clean up, or closing out of things that have a potential to fail and through an error.
What I'm talking about doesn't really give new functionality but is a clean way of conveying a certain logical flow of control. Similarly how loops have breaks and continues to cleanly alter a loops functionality in an easily conveyable way, I was hoping while loops might have something similar to my finish suggestion.
As a bonus, here's your construct as a macro:
Not only does this accomplish exactly what you wanted the operator to, if you want to you can add an else after the while_finally to execute code only if you never enter the loop.Code:[b]#define[/b] while_finally(x,y,z) [b]if[/b] (x) { [b]do[/b] { y } [b]while[/b] (x); z; } [b]extern[/b] [b]void[/b] dummy ([b]void[/b]); [i]/* Not defined -- used to force optimizer not to collapse loops, etc. */[/i] [b]void[/b] main ([b]unsigned[/b] [b]int[/b] argc) { [i]/* We use argc because the optimizer forward propagates constants */[/i] while_finally (argc, { --argc; dummy (); }, { dummy (); }) }
Macros are quite powerful. Here's a variant that looks almost exactly like your proposed version (though it can only be called once per function--as far as I can tell, there is no way to quite get NEW_LABEL to do what we want, since even the GNU extensions that allow for declaring local label variables require them to be defined within a block):Ok, both of your points are very good and sound. I still sort of want to defend it, because it makes sense in my mind from a code conveyance stance. But perhaps it shouldn't become standard to any language.
and thank you, this is neat to see. I've never really looked into doing things like this.
[b]#define[/b] CAT(x, y) x ## y
[b]#define[/b] DEFER_CAT(x, y) CAT (x, y)
[b]#define[/b] NEW_LABEL(label) DEFER_CAT (try_while_, label)
[b]#define[/b] try_while(x) [b]if[/b] (!(x)) [b]goto[/b] NEW_LABEL (3); [b]goto[/b] NEW_LABEL (2); NEW_LABEL (1): [b]if[/b] (x) { NEW_LABEL (2):
[b]#define[/b] finally [b]goto[/b] NEW_LABEL(1); } [b]if[/b] (0) { NEW_LABEL(3): /* noop */; } [b]else[/b]
[b]extern[/b] [b]void[/b] dummy ([b]void[/b]); [i]/* Not defined -- used to force optimizer not to collapse loops, etc. */[/i]
[b]void[/b] main ([b]unsigned[/b] [b]int[/b] argc) { [i]/* We use argc because the optimizer forward propagates constants */[/i]
try_while (argc) {
--argc;
dummy ();
} finally {
dummy ();
}
}