#dosomethingelse
Explore tagged Tumblr posts
flyhighfreebirb · 5 months ago
Text
while (imminentDeadline != true) {
openAssignment();
bool pissedOff = true;
closeAssignment();
doSomethingElse();
}
“Don’t wait until the last minute to do your assignments!”
listen. I don’t. But I am always trapped in a vicious cycle.
Tumblr media
And the only thing that breaks this cycle is the dread of an imminent deadline
84K notes · View notes
j0ecool · 10 months ago
Text
When you're making a game engine, there's a tradeoff when it comes to working on dev quality-of-life features vs game-facing features.
A factor I don't usually see discussed is the project's PITA Budget. It may take more swe-hours to implement a shortcut that saves 5 seconds at a time than it will ever pay back, but the qualitative difference in working without that 5s annoyance reduces the mental-strain cost of continuing to work on the project at all. As a motivation-bottlenecked solo dev, having good tools not only makes asset creation more efficient, but effectively gives you more hours in the month to work with.
today's small thing is interpreting a UI Label of just "\n" to be a shortcut for a linefeed, which lets us change this from
Tumblr media
to
Tumblr media
cutting lines-of-code in half
It's the sort of thing that makes actually* zero difference in the finished product, but it makes the daily life of being a game developer fractionally less frustrating, so that's satisfying.
*: If compilers can optimize across strcmp, which I strongly suspect they can, then they would literally compile into the same code
For funsies (because I'm stoned) let's pretend we're compiler engineers again. Why should this be optimizable? ui.labels() is a variadic template function that emits one call to ui.label() per argument, which has overloads for each type. the const char* overload has a clause at the top of it:
Tumblr media
With inlining, we would get if (strcmp("\n", "\n") == 0), which a human programmer can clearly see is always true. Can compilers? Well, given that strcmp is a C Standard Library function, compilers are free to make special assumptions about how they work that may not be obvious from the type signature. We also would not be able to inline strcmp, because it's compiled separately (unless you're building your own libc from source, or if your libc ships bitcode which would be weird)
Anyway! So it stands to reason that some enterprising young lad may have realized that they can save 0.2ms on some benchmark by constant-folding strcmps, or by precomputing string manipulations, or whatever. How can we check? Godbolt.
Tumblr media
Sure enough, even at -O1 clang is able to constant-fold the strcmps and turn test("foo") into just doSomethingElse()
This ramble didn't really have much of a point. C++ is a language built around zero-cost abstractions. There's something really satisfying about knowing enough about how the optimizer works, and what the language's semantics are, including its cost model, and thus being able to reason about what will actually get optimized away in practice.
0 notes
creationtvstation · 2 years ago
Text
 we all procrastinate sometimes.
just get back into it and start again.
0 notes
Photo
Tumblr media
I can also help you with designing a different billboard - thank you to Samuele - already 8 years back . . . #billboards #differentdesigns #graphicartsstudio #branding #creatingstories #dosomethingelse #artiseverywhere #businessowner #becomevisible #bewise https://www.instagram.com/p/CiszvKItOWi/?igshid=NGJjMDIxMWI=
0 notes
mrjlogic · 4 years ago
Video
😂🤣😂💯🎯 @tpain is a LEGEND for this! Ps. His Twitch streams through this pandemic have been highly entertaining, AND educational! If you haven’t followed, go follow him. ••••••••••••••••••••••••••••••••• 🔁• @dnice @Tpain, I can’t stop watching this. 😂😂😂 #dosomethingelse ••••••••••••••••••••••••••••••••• #tpain #hiphop #music #musictoday #era #hiphoptoday #beoriginal #originalart #originalmusic #originality #copycats #carboncopy #followers #bealeader #facts #100 #factstho #keepitreal #keepit100 #keepingitreal #sotrue #truth #true #truestory #musician #producer #twitch #rant https://www.instagram.com/p/CRhzNBsHsBn/?utm_medium=tumblr
0 notes
ohheyclaryy · 7 years ago
Photo
Tumblr media
“ We were all trash at one point in time. If you’re still trash ..... there’s hope.” -Tre Melvin . 📷 : LMAO bitchmond @oh.bb.rich . . . . . . . . . . . . . . . . . . . . . . . #basiccabanaphotowithskylineandsunset #somanyshadows #shadowposessionjutsu #idontknowwhattodowithmyhands #theslothfingersareback #canyounotlooksodistressedorbitchy #icantmyfacenaturallylookssadfam #dosomethingelse #dooneofyourasianposes #^_^V #shootswithrich #shoottokill #killmyselfconfidenceLMAOO #shootyourshot #onhowmanydifferentpeoplesphonesthoughLOL #realfriends (at Cabana Pool Bar)
1 note · View note
gregdetisigrowth · 8 years ago
Photo
Tumblr media
Trouble we start believing that we are stuck which is just a temporary perspective. If we want change we can have it. It starts with knowing WHAT and WHY! Get that straight and take action from there on in. #changeitup #changeit #change #changes #life #career #sochangeit #kickass #dosomethingelse #dosomethingdifferent #perspective #view #perception #aim #focus #goals
0 notes
hieristhailand · 8 years ago
Photo
Tumblr media
Hmmm, die paraplu helpt niet echt. Tijd om een massage te gaan nemen misschien? 🌧😏 #rainyseason #thailand #rainonholiday #dosomethingelse 📷@ploy_zei
0 notes
maisondufutur · 3 years ago
Text
WALKS -Beispielformate “HereOnAir”,u.a.  DER SPAZIERGANG. Beispiele von “Visual Radio”
Projektblog (dieser interne Blog wird im Dezember 2022 dauernd aktualisiert, aufgrund von Urheberrechten (Robert Walser u.a. ) richtet sich der Blog nur an Projektbeteiligte, die Videos sind alles “interne Links”)  Als ein Beispielformat, wie  das “HereOnAir”-Programmatik von 400asa/Maison du Futur sich anfühlen wird, haben wir DER SPAZIERGANG/THE WALK entwickelt. Zusammen mit dem Verein Churer Ensemble. Spaziergänge sind 2023 im Kanton Graubünden, Kanton Bern zu erleben. Beachten sie auch den Podcast zu DAVID FRANKFURTER in Davos, am Ende des Beitrags. Die Audio-Erfahrung vor Ort ist wichtig, aber auch ein Substitut zu schaffen für Leute, die nicht vor Ort sein können. Oder zu “faul” sind um Spazieren. 
 Bei THE WALK/DER SPAZIERGANG spielen Theater, Radio-Kunst, Stadtraums-Erkundung, Naturerlebnis-und physisches Zusammenkommen des Publikums zusammen. Hier setzen wir auch die Leitpunkt des Manifests aus Harvard um. Siehe hier auch LINK, Manifest für eine Bühne der Zukunft (Praxis nach Corona) 
Natürlich nehmen wir auch Entwicklungen vorweg, die gerade auch bei den öffentlich-rechtlichen Sendern  - wie SRF - wichtig werden (Visual Radio) 
Natürlich ist das “Spazieren”, nun nicht 100% nacherlebbar über Video, u.a. die besonders synästhetische Erfahrung (Kälte, Wärme, Luft, Geruch etc)  die während der körperliche Bestätigung gemacht wird.  Das Projekt steht aber beispielhaft für unseren Zugriff. Wir beschäftigen uns hier sehr stark auch mit den Folgen der Pandemie auf unsere Kulturpraxis.  Die sprunghafte Anstieg von Podcast-Rezeptions-Praxis zum Spazieren gehört dazu (siehe auch Link),  als auch die Möglichkeit, etwas zeitversetzt zu erleben. 
Gerne laden wir sein, eine dieser Vorstellungen (siehe Daten unten)  zu besuchen oder in diese Video konzentriert reinzuschauen. Schlüsselthema sind “Immersion” und “Resilienz”, also beglückende Erfahrungen mit literarischen und musikalischen Inhalten -  in Bewegung.  Das Video schaut sich am besten auf einem kleinen Screen an und am besten mit Kopfhörern.   Wir testen, mit welcher Kamera und Software sich die physische Erfahrung vor Ort am besten übersetzt.  Ziel der Videos ist  es, eine Form zu finden für Menschen, die anstatt reiner Audiopodcast auch eine visuelle Erweiterung suchen, oder auch neue Formen von Internet-Bühnen. Natürlich sind es auch Übungen für kommenden Anwendungen im Metaverse, wenn diese visuellen, analogen Reize (Feuerwerk, Wolken, Leuchtballone etc) auf neuste Hololenses übertragen werden können.  Zusätzlich entsteht so auch - auch Material auch für “kleine Clips”, die das ganze Format auf Social Media bewerben können. 
Aber auch die längere Videos entwickeln einen immersiven Reiz, da sich Location und Inhalt auf einander beziehen. SPAZIERGANG/BEISPIEL 1:  Ausschnitte aus dem WALK mit Simon Froehling Ausschnitte. Hier kann man das grundsätzliche Prinzip der Lesungen erkennen (gekürzt, mit Zwischentiteln) 
youtube
                           Prototyping mit Simon Froehling (Ausschnitte) 
SPAZIERGANG/ BEISPIEL 2: 
Lesung mit der Autorin Julia Weber (Ganze Lesung). Hier haben wir eine andere  Kamera benutzt (hochauflösende Pocket 2), hier können sie den Flow einer ganzen Lesung erleben. Das Format ist ein Audiopodcast, kann aber auch als Visual Podcast erlebt werden über Youtube. 
youtube
                                     Ganze Lesung mit Julia Weber
Besondere Momente bei Spaziergang mit Julia Weber: Rund Ballon-Momente….(Minute 19 bis 20:30 und am Ende der letzten Lesung  - Und natürlich der Song der Cobra Killer (Minute 57 bis 63  und gleich folgende Lesung Julia Weber
--- MEHR VIDEOS MIT KATJA BRUNNER, DONAT BLUM: LINK hier
Die Lesungen waren gebunden an die Aktion #dosomethingelse es ging darum, während der WM  in Katar etwas “anderes” zu tun. 
Veranstaltungstipp der Republik: Siehe hier: https://www.republik.ch/2022/12/02/journal?share=10
Und auf einen Blick alle Daten:
Tumblr media
VARIANTE (Zugfahrt mit prominentem Gast)
In März 2022 testeten wir ein ähnliches Format auch mit einem Gesprächs-Podcast- Der Intendant des Schauspielhaus Zürich Nicolas Stemann spricht über Dürrenmatt, Pandemie und Krieg, während einer Zugfahrt. Auch hier ist der Mensch, der den Podcast rezipiert, frei ihn als reinen Audiopodcast anzuhören (überall wo er will), als immersiver Podcast auf der Zugfahrt - oder eben auch als “Visual Radio-Format, welches die Zugfahrt überträgt. Die Fahrt ins Emmental entwickelt - u.a. auch wegen den Lichtstimmungen - zunehmend einen immersiven Reiz, dem man sich aussetzen kann - oder auch nicht. So wird ein ganz eigenes Format etabliert, bei dem Gespräche über Literatur, Ausschnitte aus Literatur sich verbinden mit der Schweizer (Kultur)-Landschaft.  Gesprächspodcast mit Nicolas Stemann. Folgende Momente eignen sich für die Rezeption, wenn wenig Zeit vorhanden:
WICHTIGE MOMENTE Einfahrt nach Ostermundigen: Minute 6:30 - Minute 8.00 Reflexionen über Nestlé: Einfahrt/Abfahrt in Konolfingen  Minute 21:30-39:00 (Reflexionen über Nestlé) 
youtube
Nicolas Stemann zu Dürrenmatt, Krieg und Pandemie (März 2022)
VARIANTE: ERINNERUNGRAUM Ein weiteres Beispiel für ortsspezifisches Podcasting und Visual Radio ist auch das #DIGITALDENKMAL für David Frankfurter in Davos, das wir im Sommer 2022 implementiert haben. Auch hier kann sich ein Effekt herstellen, wenn man “cor Ort” ist, das kleine Audiostück besteht aber auch für sich. PODCAST ZU DAVID FRANKFURTER in Davos.
youtube
In Kooperation mit dem Verein Churer Ensemble
Tumblr media
Weitere Videos mit  Spaziergängen: LINK hier
0 notes
3projh · 4 years ago
Text
Check out this video on Clapper.
Check out this video on Clapper.
#dosomethingelse #differentmusic
#lol #videoviral
.*.
2 #ninjas named #baby
#lil #everybody
😎😈😤🕳😂😂😂🕳😤😈😎
Check out this video on #Clapper
.*.
0 notes
jfastereft · 6 years ago
Photo
Tumblr media Tumblr media
"(My Man) OG." a poem  October 9, 2019 (Wednesday)
Delores McPherson Amundsen Angee, said that: "I'veFound  the'Perfect'Fella  for me;
He's kindly & gentle, artistic & passioned; myOtherHubbieSal wasOften'BadFashioned.'
Thank goodness Sal's gone, he was awfully stupid;
Every womanGOThIM; he was always WELL CUPID'D.
I'm SO GLAD to be ridOfHim, so glad he's long gone,
And now I've got OG; we two get along.
OG's my ideal; he's a comfortable gent; I'mSoAttractedToHim; HEis HEAVEN SENT."
So, here is THE MOOD   of thisHereLittle poem:
"Get to knowAnyOne and, bebe fore  long,
You'll rea lize   they'reLacking  inMany       Ar E a[u]s,
Just like YOUR FAVORITEnephew  or Uncle or 'CUZ.' "
"Well, maybe I'm right      or maybe I'm wrong;
(Yet) my OG makes me swoon when he sings me a song,
(ButI'veNoticedNow) HeDoes  things that (sometimes) make me go: 'GOLL,'
And I wish SOMETIMES he might doSomethingElse, somethingMorelike Sal.
FOR INSTANCE:  I had an operation   just the other day;
I was stitched up and bruised; I was in An  aw ful  way,
And when my OG saw me, well, almostOverHeFell,
For he swooned with admiration.  Yes, he gives Love SoWell."
"I (almost) didn' recognize you, Hon," he said; "[you're]SoPrettyNow."
ME?   I've got blood and stitches;  his    Sight's "OFF"   some how;
It seems the more harried and weird that I look,
That OG sees me MORE PRETTY, even when I sook.*
Thing is, beingLockedAway withOG   for a day or two,
Makes me feel like Liz Taylor;     then,    do you know    what we'll do?
WE WILL GO FOR A WALK 'ROUND THE PARK, AND PEOPLE RUN,
AND SCREAM, (pause)  and one lady shotAtMe      with her "45" gun,
'Cause I looked quite a lot like an alien from H   L L,
But MY OG's loving eyes,   well, they'll NEVER this    tell,
So, I can't rely on OG   or my dog   very well,
To tellMe the neighbors'Reaction, whenI lookLikeI'veBeenDraggedFromAwell.
Dear Old Sal, atLeastHeWouldHaveLookedAtMe,   looked at me and puked,
And told me I looked ghastly, and sometimes  BlessedSal evenRebuked,
ME  for "looking just like me," or, sometimes a little better,
But now I got  myOG, who is like an Irish Setter,
Who sits and looks and looks at me   all throughout The Days,
And tells me I am pretty   in a million different ways.
Moral:  So, THERE ARE DISADVANTAGES   even to myMan named OG;
I better get used to him, I guess;  he's like a loveStruckLittle dog.
fin  ♥
https://www.youtube.com/watch?v=QMI1MSw2JCw
* - SOOKING: the state of pouting
0 notes
phulkor · 5 years ago
Text
Implement feature switches with spring
A feature toggle is a technique in software development that attempts to provide an alternative to maintaining multiple branches in source code, such that a software feature can be tested even before it is completed and ready for release. Feature toggle is used to hide, enable or disable the feature during runtime.
It often happens in our code that we need to provide extra calls to a function or an external system based on certain coditions. These conditions can be: * when a system property is set * depending on the environment we are in * on a condition in a parameter of a request
The code then becomes bloated with constructs like:
if (feature.isActive()) callExternalSystem();
if (object.isOfType()) doSomething(object); else doSomethingElse(object);
if (env == Env.DEMO) doSomething(object);
This complexifies the code and is not easy to maintain.
... comes the strategy pattern!
Strategy pattern
We'll implement a feature to scan files only when this feature is turned on. We'll use the document repository as an exmple.
@Service public class VirusScanService { @Overide boolean scan(byte[] toScan) { // scan the data for mischievous content return false; } }
And the service - DocumentService - that calls our virus scan:
@Autorwired private MetadataRepository metadataRepository; @Autorwired private VirusScanService virusScanService; @Autorwired private FileRepository fileRepository; @Transactional public uploadDocument(Metadata metadata, byte[] data) { String documentId = metadataRepository.save(metadata); virusScanService.scan(data); fileRepository.save(documentId, data); }
In this example, the virusScanService is always called, let's strategify it.
Implement the strategy
The first step is to introduce an interface
public interface VirusScanService { boolean scan(byte[] toScan); }
Then we'll provide two implementations, a null implementation that does nothing and our actual implementation
@Service public class NullVirusScanService implements VirusScanService { @Overide boolean scan(byte[] toScan) { // do nothing return false; } }
@Service public class UvscanVirusScanService implements VirusScanService { @Overide boolean scan(byte[] toScan) { // call the command line 'uvscan' command return false; } }
Now, if nothing else changes, spring will not be able to chose which implementation of our VirusScanService to inject in DocumentService.
Sprinkle some spring powder
We'll configure the application to inject NullVirusScanService by default and turn on the UvscanVirusScanService with the application property feature.virus-scan: uvscan.
@Service @ConditionalOnProperty(name = "feature.virus-scan", havingValue = "null", matchIfMissing = true) public class NullVirusScanService implements VirusScanService { }
@Service @ConditionalOnProperty(name = "feature.virus-scan", havingValue = "uvscan") public class UvscanVirusScanService implements VirusScanService { }
Notice the matchIfMissing in NullVirusScanService that tells spring to use this implementation if no property feature.virus-scan is found.
You can now configure which implementation you want with a simple configuration, this can also be useful to provide fake implementations for your tests.
Happy coding !!
0 notes
leroge · 4 years ago
Photo
Tumblr media
Where is the lie? I’m tired of hearing it! #DoSomethingElse! ( @tpain voice 🗣)Via @mehcadbrooks 💯 (at The Keeper of the Plains) https://www.instagram.com/p/CSkmJA_FOlN/?utm_medium=tumblr
0 notes
t-baba · 7 years ago
Photo
Tumblr media
PHP Integers, Floats and Number Strings
Working with numbers in PHP seems to be a trivial concept but it can be quite confusing. It looks easy at first because PHP provides automatic type conversion. For example, you can assign an integer value to a variable and the type of that variable will be an integer. On the next line, you can assign a string to the same variable and the type will change to a string. Unfortunately, this automatic conversion can sometimes break your code.
There are a lot of types for numeric values as well. In this tutorial, you'll learn about  integers and floats in PHP, as well as the functions which can be used to determine the type of numbers that we are dealing with and convert between them. You'll also learn how to convert integers and floats to and from numerical strings.
Different Types of Numbers in PHP
Integers
The most basic type of number in PHP is the integer. As you might already know, integers are numbers without any decimal part. For example, 2 is an integer and so is 235298 or -235298. On the other hand, 2.0 and 3.58 are floats. We will discuss them in more detail later.
One important thing to remember is that it is not necessary that a number be of type int if it does not have a decimal part. For example, 16 * 2.5 is exactly 40 but the type of this result will still be a float. When you are multiplying numbers, the final result will be of type float if at least one of the operands was a float. It doesn't matter if the final number has a decimal part or not.
Also, the maximum possible value an integer can have in PHP on your system can be obtained using the constant PHP_INT_MAX. A value greater in magnitude than the value returned by PHP_INT_MAX will be stored as a float even if it looks like an integer.
Generally, you would expect the result of multiplication of two variables of type int to be of type int. However, it is not true in case of overflow. Multiplication of five or six different numbers can easily take you outside the bounds of int type. For example, the result of 128*309*32*43*309 is a float on my system because it exceeds the value of PHP_INT_MAX which is 2147483647.
You can use the is_int($value) function to check if a number is of type integer. There are two aliases of this function called is_integer($value) and is_long($value). Both of them will give the same result.
Floats
The next most common type of number that you will deal with is a float. Unlike integers,  which were simply numbers without decimal points in most cases, a number of type float can be represented in a variety of ways. The values 3.14, 12.0, 5.87E+10 and 3.56E-5 are all floats.
PHP will automatically convert a number to type float whenever decimals or very large numbers are involved. The float type can commonly store numbers with magnitude approximately equal to 1.7976931348623E+308. However, this is platform dependent.
The value 1.7976931348623E+308 may seem like a very large value—and it is!—but floats have a maximum precision of only about 14 digits. Any number with more digits than that will lose its precision. That means you can store a very large number, but you won't be able to keep the information about its exact value—in many cases, a float is only an approximation.
There are two functions which can be used to determine if the value you are dealing with is a float. These functions are is_float() and is_double(). Actually, is_double() is just an alias of is_float() so you can use any one of them and get the same result.
Infinity and NaN
There are two more kinds of numerical values that you might have to deal with when writing programs related to Mathematics. These values of infinity and NaN (not a number). Both these values require a little explanation because they are different from what you might expect.
Infinity in PHP is different from infinity in real life. In PHP, any numerical value above approximately PHP_FLOAT_MAX on a platform is considered infinity. So, 1.8e308 will give you float(INF) on var_dump(). You can check if a numerical value is finite or infinite using the is_finite() and is_infinite() functions.
Similarly, NaN stands for Not a Number but it doesn't check if a value is numerical or not. The value NaN is used for result of mathematical operations which are not possible in mathematics. For example, log(-1) will be NaN. Similarly, acos(5) will also be NaN. You can check if the value returned by a mathematical operation is not number by using the function is_nan().
Numerical Strings in PHP
Just like PHP dynamically change the type of different numbers based on how their values are used or assigned, it can also infer the value of different numerical strings for you to convert them to numbers.
The function is_numeric() can help you determine if a string or variable is indeed numeric or not. This function will return true for numbers written in octal, binary or hexadecimal notation. It will also return true if the numbers are written in exponential notation like +16.52e39.
Starting from PHP 7.0.0, when you pass a string to is_numeric(), it only returns true if the string consists of an optional sign, some digits, an optional decimal and an optional exponential part. This means that a numerical string written in hexadecimal or binary format will return false from PHP 7.0.0 onward.
PHP will implicitly cast any valid numerical string to a number when need arises. The following examples should help you understand this process better.
<?php $num = "3258712" + 12380; // Output: int(3271092) var_dump($num); $num = "3258712" + "12380"; // Output: int(3271092) var_dump($num); $num = 3258712 + "12380"; // Output: int(3271092) var_dump($num); $num = 3258712 * "12380"; // Output: float(40342854560) var_dump($num); $num = 3258712 / "12380"; // Output: float(263.2239095315) var_dump($num); $num = 3258712 / "8"; // Output: int(407339) var_dump($num); $num = "53.9e4" + 10; // Output: float(539010) var_dump($num); $num = "398.328" + 10; // Output: float(408.328) var_dump($num); $num = "398328" + 0xfedd24; // Output: int(17101084) var_dump($num); $num = 398328 + "0xfedd24"; // Output: int(398328) var_dump($num); ?>
As you can see, all valid numerical string were converted to their respective values before addition or other operations were performed. The type of $num in the end depends on its final value.
In the last case, the hexadecimal string "0xfedd24" is not converted to its decimal value because PHP 7 does not consider it to be a valid numerical string.
Casting Strings and Floats to Integers
Every now and then, you will need to cast one type of numerical values into another. PHP has a variety of functions and techniques to do so. Most of the time, the conversion will be implicit and you won't have to worry about it. However, if you have to do the conversion explicitly techniques mentioned here will definitely help.
You can use (int) or (integer) to convert any value to an integer. In case of floats, the values will always be rounded towards zero. Another way to cast strings and floats to integers is with the help of intval() function. Both (int) and intval() work in exactly the same manner.
<?php $float_a = 3598723.8258; $int_cast = (int)$float_a; // Output: 3598723 echo $int_cast; $string_a = "98723.828"; $int_cast = (int)$string_a; // Output: 98723 echo $int_cast; $string_b = "987233498349834828"; $int_cast = (int)$string_b; // Output: 2147483647 echo $int_cast; $float_b = 21474836473492789; $int_cast = (int)$float_b; // Output: -6507212 echo $int_cast; ?>
You should note that casting overflowing strings to integers will set the final value to the maximum permissible integer value. However, casting a float whose value is more than the maximum permissible integer value will result in the value oscillating between -2147483648 and 2147483647!
In certain situations, you might need to deal with very large numbers without loosing any precision. For example, it is impossible to get accurate result of multiplication of 987233498349834828 and 3487197512 using the * operator. It will give you 3.4426781992086E+27 after float conversion. Calculating the actual answer, which is 3442678199208600117812547936, will require use of libraries like BCMath. BCMath works by storing numbers as strings and doing arithmetic operations on them manually. Just remember that if you use BCMath, you will be dealing with strings instead of integers and floats.
Certain libraries will want you to only pass numbers of type int to their methods but you might unknowingly supply them a float value. This might happen because the value seems like an int because it doesn't have a decimal part. This would almost certainly result in an error if the library uses a function like is_int() to check if the passed number is of integer type. In such cases, it is always wise to first cast that number to int using either (int) or intval() and then pass it to any functions or methods of the library.
One example of when such a situation could come up would be when you are dealing with Mathematical functions like floor() and ceil() etc. floor() and ceil() will always return a float, even if you pass them an int!
<?php $int_a = 15*12; // Output: int(180) var_dump($int_a); $num = floor($int_a); // Output: float(180) var_dump($num); ?>
One problem with casting floats to integers is that you will lose the decimal part of the numbers. This may or may not be desirable. In such cases, you can use functions like floor() and only cast the number to int type if its actual value is equal to the value returned by floor().
<?php $number = 16*2.5; if(floor($number) == $number) { $fraction->setNumerator((int)$number); } else { echo 'Did not set the numerator.'; doSomethingElse(); } ?>
Let's say you have a library which allows you to do fractional arithmetic and it throws exceptions when you pass a number to its setNumerator() method that is not of type int. A variety of operations might turn a number in type float even if it is still an integer within the minimum and maximum bounds of type int. Using something like the code above will help you deal with such cases easily.
Final Thoughts
This tutorial has covered different ways in which PHP stores numbers and how you can determine if a number of a particular type. For example, you can use functions like is_int() and is_float() to determine the type of a number and proceed accordingly.
As you saw in the tutorial, PHP supports automatic type conversion. This means that sometimes smaller integers like 5 or 476 could have been stored as floats without you realizing it. Using these numbers in functions which only accept int values might result in exceptions or errors. We learned that a simple solution to this problem is be to explicitly cast such numbers to int if they don't have a decimal part and their values don't change upon casting.
After reading this tutorial, you should be able to determine the type of a number or the final type of a result after using a variety of operations using predefined functions and also explicitly cast them to a specific type after doing some checks.
As always, if you have any questions or additional tips, you are welcome to comment.
by Monty Shokeen via Envato Tuts+ Code https://ift.tt/2FbgPpp
0 notes
trainsinanime · 8 years ago
Text
Friendly reminders: - If your preferred frameworks uses the naming convention where interfaces start with the letter I, then ISomething should always be an interface, not an abstract class. There are important differences between the two. - If you have a call of the type a.doSomething().doSomethingElse(), and the line fails, then always make sure which of the parts is actually failing. These will save you a lot of debugging work.
0 notes
rodderz125 · 11 years ago
Video
It's long arguing with somebody who has Hot breath #DoSomethingElse #ChuckAMintIn #SometimesTakeTheLBecauseYourWorthIt
0 notes