Jump to content

DevBlox

Member
  • Posts

    251
  • Joined

  • Last visited

Everything posted by DevBlox

  1. Hmm, another option would be that findViewById returns the view, but the cast is wrong, because what it returns is not EditText, but still a subclass of View, so the compiler is silent.
  2. Most likely IMO: final EditText a = (EditText) findViewById(R.id.popEdit1); final EditText b = (EditText) findViewById(R.id.popEdit2); final EditText c = (EditText) findViewById(R.id.popEdit3); One of these does not return the view, instead returning null. Check if your id's are right (like case sensitive things and whatnot), maybe you need to rebuild the entire project, because some files that are meant to be auto-regenerated are not.
  3. The principle behind programming languages and compilers is dead simple, others have explained it well. You can write a simple compiler basically overnight. I wrote an Assembly decompiler (converts from machine code to Assembly) in Assembly (almost at inception level here, lmao) for Intel 8088 processor overnight, though it's not able to do some things haha. Actually you might be surprised to hear that the C compiler is written with C, the Computerphile video linked above explains that if I remember right Creating a modern and cross-platform compiler is a task of monstrous proportions. Your compiler has to be able to compile for different CPU architectures (x86, ARM etc), and even those can have multiple extra instruction sets (SSE3, SSSE3, SSE4.x, AMD's 3DNow!, etc). If there is some existing code that could benefit from those new instruction sets, you recompile that code with a new and upgraded compiler and you're done. Nowdays, JIT compiled languages like C# and Java do this run-time basically, the virtual machines they run in can detect what the processor is and what instructions it has, executing code accordingly, though the machine itself still has to be compiled for new architectures, the JIT compiled code can be portable in most cases. Another important scenario to put things in perspective: imagine you manufacture some new micro-controller or CPU, the developers won't be able to compile their existing code on the new chip without a compiler, so the author company/person either writes one from scratch or implements their new instruction sets to existing awesome compilers and suddenly empower developers to do great things and re-use all (at least most) of their code.
  4. Who knows really, it's closed source, protected from the light of day. If you're very curious try calling on some developer from Nvidia or AMD they might tell you, I don't think it's all that confidential to cover the scale of the project anyway. Another option would be to check out open-source drivers that are present in the linux kernel code, that might tell you something, but they are minimalist mostly, the in-house drivers will be much bigger I bet. Decompiling won't tell you anything either, these kind of tools cannot decompile code design.
  5. Well, TL;DR, there is, there are people like that in the industry (some actually have degrees e.g. in physics, and are full fledged coders, so even a wrong degree is a non problem), at least in Europe, where I live. But it's hard to learn to code very well yourself, because nobody is by your side enforcing it on you, so you do not know what you are doing wrong, so it might take way longer than usual and being a professional takes years (more or less, depends on how fast of a learner are you). Oh and universities/colleges don't really teach the right things, they teach basic concepts, sciency things, only few of them are important, but teaching how to design your systems is lacking heavily. Though I believe a lot might depend on where you would be studying. What companies really value - stable, clean, concise systems, so nobody will want a guy that just knows the syntax of a few languages. There is online material, some great books that can give you tons of knowledge on this, but the thing you really want to do (at least what I would try to do) is at least get into internships (I got into an awesome one, taught me a lot, but there are too many that suck, it's a bit like taking a blind pick if you have no inside knowledge), then work your way out of there into the industry and up your career path. You have to be really passionate about it and learn all the time. Show your passion to the company! It's not easy to keep up the pace, so it's a good idea to specialize. As I am much younger than you, this is basically all I can share from observing my surroundings and experiences. Best of luck to you!
  6. Oh I see, I imagined your system to do quite a different kind of role, wasn't quite on the same page, so I questioned this design. I imagined it to be more like a decentralized monitoring system that you are trying to achieve, but this is more like an event system. This also started looking like how Android or IOS achieve their real time push notifications, if that's something what you're looking for, looking up how it's implemented might actually answer some questions for you . Thanks for the kind words, I might actually write a blog sometime, need to get a habit of documenting anything new I try . Good luck with the system, seems really interesting how it will turn out!
  7. Oh dang, I see what are you trying to do now. Don't make your clients have port forwarding, not only this is a potential security hole and weakness, this is bad design of the system. For every new user, ALL of your devices will experience a load increase, every one of them. Eventually you will have nowhere to scale out, and you will have to either upgrade all of your devices or kill the project completely, not nice. You need to reduce impact here. Whatever you do, you need a server, like I described in option 2, whether you choose if the devices should report the data themselves or listen does not matter at this point, it's whatever you decide, I'll describe that situation later. You need to have the server to handle all of the users, that is, listening on their requests, not the other way around. Even more so, because you can't force users update their configs every time you add a device, or have your devices update their configs every time a new user pops up, that's just plain dumb design (don't take it personally, we've all done bad design :D). Users have to have a single domain name(!) only, that's the master server that will service them. Use domain names at this point, if your servers should change location or something and you cannot use the same ip, don't force the user to update anything. You get the idea I hope. The code the user runs must be as immovable as possible. Okay, so I see you know how networking works to some extent. So I will just clarify for you and explain for you or anyone else who might read. You understand already that port forwarding needs to happen someplace if your servers or devices are behind routers. You only need to port forward the services and programs that are acting as servers, that are actually listening on ports. Forget about the client needing a port, at least in the HTTP protocol case. That is because the client, that connects to the server, is sending the request, and it needs to know where it should land. In the case of your home, if a request lands from the outside (the WAN wire), it hits your router, which acts like a firewall for everything in your local network, so everything there is invisible from the outside basically. You do port forwarding on your routers port to a port on a specific computer or server inside the network, so that when a request from the outside hits the router on that port, it gets put through to the server behind it, so it can respond to it. This does not need to happen for the end that makes the request. Imagine needing to port forward in every new network you enter with your laptop just to browse the internet. Ew! That's why option 1 has a terrible limitation if any of your devices will not be in your local network, You need to port forward everything, and even that in some cases is not guaranteed to work, that's a real pain in the ass. Option 2, on the other hand, only requires the server to be port forwarded if needed, so the devices can be anywhere where there is internet connection and they will happily send requests t your server and receive it's responses. Don't even worry about being on the same network with a bunch of devices and servers, everything has a local ip address, even your phone when you connect to WiFi. Also since everything is there, you just connect to the local ip address that you want to. That's why hosting, let's say, Minecraft for a lan party is a piece of cake, you just connect to the host's local ip. So your devices being in the same network as the main server can just send requests to it's local ip. About the deciding which port is which, you just about need to listen on and know about one. The one that is on your main server. All the devices will communicate with that one. If you really need to differentiate, get a second one. Then it's one port for the devices, and the other one for the app. If your concerns are that you need a port for a single device, i have an example. Imagine Facebook handling all of those requests from all of those people. A computer only has 65536 ports, but millions of people are connecting to just one, that's port 80 (imagine Facebook has only one server for this example's sake). If you don't get what am I saying, you really need to set up and experiment with how networking works, and read some wikipedia articles, whole books are a bit overkill for the short term. Your main server (or app) will still bear all the load with option 1, it will do all the work with data reported anyway and it will keep a whole bunch of connections open, this is more of a decision to be made according to other limitations and the concept itself of who is the server and who is the client :). Don't even worry about the load going with option 2, a well written server program on a simple laptop can carry many many thousands of requests per second, in a few milliseconds even. I once written one that handled 7k and it did multiple lookups in a few data structures. I got to test my own Java server application on Raspberry Pi Model B some time ago, turns out it can handle a few hundred a second, on a freaking ARMv6 chip! take Of course, you did not mention about what data amounts we're talking about and what the devices will be reporting, so I imagine not a whole lot of data is involved, if the reporting frequency is this high. 10's of kilobytes for a single frequent request is not even that much. if the devices have to report them even 10 times a second (even though in most cases that's a bit useless, 1 second is gold for real time reporting), you'll be fine. The app could query the server once a second too, so the worst worst case delay for such a system is 2 seconds, not a whole lot, I bet you will never reach that big of a delay. Keep in mind that requests last mere milliseconds. I bet you could still achieve this 2 second worst case with devices and the main server being on different continents! ---------------- So there we go, my take on the current situation. Draw some flowchats and graphs while making birth to this thing :). As for what to use, I achieved my numbers with HttpListener, but I have heard SignalR is great, you will have to make your own investigation :).
  8. Option 1: With this logic your devices are actually acting as servers and you will send http requests to them with your app, the response will contain z data that contains their current status etc, anything else is over-engineering and not necessary. That's simple enough to achieve, your devices will have to listen on a port and handle these requests, this part will be operational indefinitely no matter is the app is there or not, think of it as in stand by mode. The app will then make http requests to these endpoints and retrieve z data, it could just act on a time delay and you will achieve what you want. The downside of this is that you will need to have your devices written down in the app's config, it will have to change every time a new device is added or an old one is gone, this means more things to change if anything like that happens, minor thing if there won't be more than 10-20 of them. Your explained idea will suffer from this as well as will be terribly over-complicated. Option 2: If you will have lots and lots of these devices, you could have a master server, to which every device will "call home" to, these requests could be POST's and contain z data, or they could just ask the master for commands. Note that your app will not be able to be a master, because the master always has to be reachable and available, meaning a static ip or at least a domain that will stay constant, your app will be a client of the master and will request it for data. The master will have all the logic in the world that you will want, this means the logic you have to code for the master will be the most complicated thing in the system, it will have to listen on a port and handle these requests while providing data to the app via another port and everything in between, the devices just periodically request the master for things or just push their data to it. The upside is that every new device have a single ip or dns to call home to on deployment, meaning deploying new ones is a piece of cake, it's a more scalable system overall, but the master has to handle their disappearances and similar things in it's logic, it should not have the config with all of them listed, it's counter productive to this architecture. That's two ways how I would do it, the multithreading part will all be in the master code, it will be challenge to create i reckon
  9. Constant polling of a pin is not optimal, you need to use ISR on a pin that executes a function of yours, that's the best way to implement such a thing. Refer here.
  10. Look at some implementations for linked lists, they often use recursion for navigating through the list.
  11. Implementations of those 10 methods maybe can't be static, but a factory method can
  12. You can check out Project Rider from Jetbrains, it's their new C# IDE. It's still just in early access stage and is not perfect, but it works for me and I like it. Some download links so you don't need to register: Windows: http://download.jetbrains.com/resharper/riderRS-144.5171.exe OS X: http://download.jetbrains.com/resharper/riderRS-144.5171.dmg Linux: http://download.jetbrains.com/resharper/riderRS-144.5171.tar.gz
  13. I guess you're starting to warm to the idea that html and css don't empower you completely. Good. A functional webpage is no good without a backend, that's what PHP is for, backends - they operate with your database, get and put things from and to the webpage as the page loads or the user interacts with it, it's the brain - the business logic, that keeps the machine rolling. But I would advise strictly against PHP if you will be doing more than casual web pages (as much as I wish PHP would die, it's a bit easier to learn starting from no experience, so for personal use, whatever). I (and lots of other people too) consider PHP to be quite outdated, it's flawed as a language even, it should stay the hell away from any important things, but yet... Right now I'd point you to learn a proper language that does not put too much pressure on you, a good choice would be to learn Python or Javascript (then after JS maybe TypeScript, it's way cooler than JS, you'd get why after some time) and write great backends instead of those PHP ones.
  14. Do like @Nineshadow said. Just make sure you don't mess up your equality operators. And keep in mind that C++ is statically compiled, that means each variant of structure use with that template has to be compiled separately, this messes up code encapsulation somewhat, you will need to put all the template code in a header file.
  15. When you can design and build large systems that are actually reliable, unlike what a lot of PHP programmers are capable of, who by my experience are copy-paste masters and can't write a damn thing themselves.
  16. From a design standpoint it depends what kind of validation you're doing here. If it's directly associated with the health of the class and something could break if value is bad, use exceptions (eg. throw an ArgumentException with a your own message). If it's something to do with overall data integrity and validity, this belongs in a separate validator class (SomethingSomethingValidator or so), you don't want setters doing things other than set values because that's not what setters do, let a validator class do validator things, you can make it return error messages depending on the data, and the event handlers in a form should handle the case where data is invalid, not letting the user proceed, showing a message box with a message and such, you know - handler things. All this will make your application easier to test, and I suggest you should really try getting a hang of TDD (Test Driven Development), you will feel when your class starts doing too much.
  17. Not even close. It is improving continuously, the features of Java 8 for example are a great gift that improved my code a great deal, there's still a long way to go to perfection so I'm waiting for what they still have in store. It will stay for a long long time, at least in server applications domain, where IMO it is at it's best. Though I agree it went places it shouldn't have (like applications that ran in a browser and had a million security holes), but it never took off there anyway, luckily. I always get a bit frustrated when people try to tell me that Java is slow, but can't explain why, or their explanations are off by 10-20 years. I suggest not listening if you don't know better. Java is 'slow' because it is a JIT compiled language, the same kind of 'slow' that any other similar language (like C# and friends) experience, but has the added bonus of being one of the first (if not the first) of this kind. That means there are people that used it 20 years ago, maybe for a short while only and hated it. No wonder - at the time it was cutting edge and it was running on old hardware that had a habit of running out of juice. Fast forward to now and I still wonder if they're the same people or not that complain about it being a memory hog and slow, when it's marginally different in performance to similar languages. It has it's shortcomings compared with Microsoft's solution, naturally, newer solutions tend to be better if they mature enough. The added benefits of such a system (Java, .Net and alike) outweigh all of their shortcomings, especially considering that hardware is cheap these days compared to then and programmers can be more laid back with their resource management. It speeds development up massively. But it does not stop from fast services being written in Java. Heck, where I work as a developer we have some new shiny high-load back-end applications written in-house with Java, and they are brilliant, you won't hear any undue performance complaints towards Java from me.
  18. Connecting an app straight to database seems very sketchy to me. IMO you should write a server-side API that does all the database work. You will then use json/xml protocols (whichever you want) to communicate with the API. This will also allow you to ensure backward compatibility between versions better.
  19. It depends on many factors. Like how experienced you are, how complicated the language is, how much time you spend and how you learn. Also as mentioned, you can learn to code in a language fairly quickly, but fluency comes over time. I would not sweat those details (the h8ers lol), put effort into it and you will succeed, if you are passionate about coding you will never hate it.
  20. As with most languages it's good with some things and bad at others, but as a language it's quite okay, it's the grandfather of many modern languages and it still kicks butt in low level programming.
  21. It does not matter functionally which method of encapsulation to use, it's all the same in the end. Though style-wise, I'd say you better use properties, they reduce a lot of useless code and looks a lot cleaner. This is a feature I would love that Java had lol.
  22. Maybe it could take some of that space, because Go is rather versatile from what I have seen and such a flexible platform definitely has a chance. Though C will always be the at the core of all things IMO, I don't know another language that could take over C anytime soon.
  23. No wonder it does not work, that break does not belong to the if block (which consists of a single line, because nothing is enclosed in curly brackets). So you're basically saying to the compiler: if this, do this (the single line), then break regardless of anything, then else (compiler is going "wat? where the f is it's if?" at that moment and gives you the error). Else has to go immediately after the if block, so put your brackets accordingly, or rethink the place entirely if this does not work logically. EDIT: Why is it bad? It's the expected behavior by looking at this code. You break out of the infinite while cycle and immediately print "Have exceeded..." line. I guess you're probably confused by your own messy code, proper indentation is devised for a reason you know.
  24. It's not slow, it is just suited to other tasks. It can be faster than say C in some cases (stands for any statically compiled language), because compiled C code is completely static, while Java code is interpreted by a very clever virtual machine that optimizes code in run-time. That means complex tasks are dynamically micro-optimized, meaning it no longer has static performance, it is potentially higher than let's say C. This also makes return in (time) investment of Java humiliatingly larger than C basically. That's why more people write business software with Java than with C (*khem* nobody sane enough writes them with C *khem*). There are cons to it though. Like the garbage collector. And in general some algorithms/cases require things that Java is bad at and can't solve with Java gracefully. Things like: > Creating many tiny objects continuously and dismissing them almost immediately (means GC will work overtime and your application will stutter, because "stop the world" pauses happen, eg. Minecraft). > Working with system resources and "hard real-time" problems. As I mentioned Java has it's garbage collector that destroys your objects, when they are no longer in use. This means an object's lifetime is no longer deterministic, and it will often free resources whenever it feels like it. This is bad in certain and mentioned situations, when resources have to be quickly freed up for some other process/thread to use. That's why normal people use C++ for these things (it is built upon RAII paradigm, which is why it is so good for resource handling). These are only couple of things from the top of my head. These are also reasons why games written in Java suck performance wise, why nobody writes operating systems in Java (while in theory you could). Also such a system has more easily detectable security holes, which is why Java is not considered safe even now when a lot of problems are solved (and comparing it to .NET is bullshit, because .NET was created to build upon Java's failures, of course it is better, I like C# as a language more, but I still code Java whenever I can, because I don't have to deal with Mono on my Linux machine, it's definitely usable though, but not perfect). Also needing to JVM for a Windows desktop program is bullshit, so DON'T write one with Java, 'cause I will be mad, write it with C# on Mono instead if you want it to be multi-platform. Rant over lolz. TL;DR: Stupid people use whatever tools for whatever and then complain that they are slow. That's why Java is "slower" than C or C++. EDIT: Actually I figured I'd add a point or two to stop people from thinking I'm a complete lunatic for thinking Java perf > C perf all day everyday. > The virtual machine is big and takes time to start up. > Since JVM optimizes run time there is a warmup period for applications. > Eats RAM more than C/C++, as .NET would do too (.NET is a bit more clever at that point though, I could expand on this), but it is definitely worth it these days (besides it's not that terribly much) Also Java gives you the opportunity to nail it on the code quality and design, so no need to hold back, because you're hurting yourself.
  25. No school ever will stuff the right aptitude in your head to become a good programmer, only proficient at "academic stuff" aptitude, which does not translate into robust and well designed real world applications quite as well. That's why I feel there are many programmers on the face of the earth, but not that many that can actually write good and maintainable code. You have two ways to learn this, it's best to utilize them both. Those are: work in enterprise for awhile where you can learn the trade from seniors and read books, there are great books about code design that are for advanced programmers, you have to have the right way of thinking around the problems when you read those (get some books for that too, and then code code code a lot), because the next step is to write code that will put people in awe when they read it.
×