Coding: Fleeting Thoughts

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

heatsink
Posts: 86
Joined: Fri Jun 30, 2006 8:58 am UTC

Re: Coding: Fleeting Thoughts

Postby heatsink » Mon Jun 16, 2014 5:43 pm UTC

You, sir, name? wrote:How do Haskell applications deal with system state? I don't mean short snippets of code from academia, but actual, large applications.


The Yesod book has a chapter about how it uses monads to encapsulate state. Yesod is an infrastructure for building web applications, which are naturally stateful. Yesod has lots of parts, and the chapter is fairly late in the book, so you'll need some patience to read the chapter.

The sledgehammer solution is to write most of the application as IO functions so that arbitrary side effects can be used throughout. But that doesn't scale in a maintainable way, since you're not dividing responsibilities across your program. Everything messes with the same big bag of state.

Large stateful projects use different monads to expose different parts of their state. Their monads wrap IO functions or actions so that they can produce side effects. A monad can restrict its underlying monad's functionality by exposing only a subset of what the underlying monad can do. It can also extend functionality by keeping some additional state and exposing an interface to it.

The Yesod chapter I linked is about monad transformers, which are generic extensions to monad functionality. That is, a transformer is a functionality extension that can be applied to an arbitrary monad.

User avatar
NecklaceOfShadow
Posts: 775
Joined: Sun May 03, 2009 7:40 pm UTC
Location: In the alchemical aether
Contact:

Re: Coding: Fleeting Thoughts

Postby NecklaceOfShadow » Wed Jun 18, 2014 6:21 am UTC

I was going to rant, "I really need to stop trying to do in python what is far better accomplished in bash."

But then after trying to code this up in bash, I realized (again) that doing things in bash is a pain in the ass, and bash can go pound sand.
Significantly less weird than I used to be. Still pretty weird.

οὗτός ἐστιν Ἀγαμέμνων, ἐμὸς
πόσις, νεκρὸς δὲ τῆσδε δεξιᾶς χερός
ἔργον δικαίας τέκτονος. τάδ’ ὧδ’ ἔχει.


User avatar
Xenomortis
Not actually a special flower.
Posts: 1456
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Fri Jun 20, 2014 1:31 pm UTC

A little while ago, I was in a hurry and wrote a class that's at top of several abstraction layers that's used to manipulate some device.
It's got a method called "asynchronousX" but blocks and a method called "getY" that changes state.

I think I'm a bad person.
Image

User avatar
raudorn
Posts: 370
Joined: Mon Jun 13, 2011 11:59 am UTC

Re: Coding: Fleeting Thoughts

Postby raudorn » Fri Jun 20, 2014 3:22 pm UTC

Xenomortis wrote:A little while ago, I was in a hurry and wrote a class that's at top of several abstraction layers that's used to manipulate some device.
It's got a method called "asynchronousX" but blocks and a method called "getY" that changes state.

I think I'm a bad person.


Renounce the way of the dark side and thine sins shall be forgotten, childe.

In other news, yesterday someone linked me to wavepot. I mean, that's almost as evil as linking to tvtropes, right?

User avatar
Xenomortis
Not actually a special flower.
Posts: 1456
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Fri Jun 20, 2014 3:37 pm UTC

raudorn wrote:
Xenomortis wrote:A little while ago, I was in a hurry and wrote a class that's at top of several abstraction layers that's used to manipulate some device.
It's got a method called "asynchronousX" but blocks and a method called "getY" that changes state.

I think I'm a bad person.


Renounce the way of the dark side and thine sins shall be forgotten, childe.

Well I am in the process of rewriting it.
Thing is; we're using a mechanism that is grossly inappropriate for the task at hand and I cannot remember why.
So any rewriting would merely be sticking plasters on a bat that's fallen over and broken everything after being told it's got to run like a dog.
Image

DR6
Posts: 171
Joined: Thu Nov 01, 2012 1:44 pm UTC

Re: Coding: Fleeting Thoughts

Postby DR6 » Fri Jun 20, 2014 5:25 pm UTC

raudorn wrote:
Renounce the way of the dark side and thine sins shall be forgotten, childe.

In other news, yesterday someone linked me to wavepot. I mean, that's almost as evil as linking to tvtropes, right?



I can confirm.

User avatar
chridd
Has a vermicelli title
Posts: 846
Joined: Tue Aug 19, 2008 10:07 am UTC
Location: ...Earth, I guess?
Contact:

Re: Coding: Fleeting Thoughts

Postby chridd » Fri Jun 20, 2014 5:44 pm UTC

raudorn wrote:In other news, yesterday someone linked me to wavepot. I mean, that's almost as evil as linking to tvtropes, right?
...I just get a solid brown screen. Not a particularly pleasant color of brown, but that wouldn't be enough to make it evil...
Not sure what was supposed to happen.
Unless it's all those CSS errors on the console that are supposed to be evil? (Also says AudioContext is not defined.)
Edit: or the horrible formatting in the JavaScript?
~ chri d. d. /tʃɹɪ.di.di/ (Phonotactics, schmphonotactics) · she · Forum game scores
mittfh wrote:I wish this post was very quotable...

speising
Posts: 2367
Joined: Mon Sep 03, 2012 4:54 pm UTC
Location: wien

Re: Coding: Fleeting Thoughts

Postby speising » Fri Jun 20, 2014 5:53 pm UTC

i got a sort of code editor. not sure what's supposed to happen when i press that play symbol, but it does nothing. maybe the puzzling is the timesink?

DR6
Posts: 171
Joined: Thu Nov 01, 2012 1:44 pm UTC

Re: Coding: Fleeting Thoughts

Postby DR6 » Fri Jun 20, 2014 6:55 pm UTC

chridd wrote:...I just get a solid brown screen. Not a particularly pleasant color of brown, but that wouldn't be enough to make it evil...
Not sure what was supposed to happen.
Unless it's all those CSS errors on the console that are supposed to be evil? (Also says AudioContext is not defined.)
Edit: or the horrible formatting in the JavaScript?


That's your problem. I'm on Firefox, try there. Also, have audio on and all the stuff.

User avatar
raudorn
Posts: 370
Joined: Mon Jun 13, 2011 11:59 am UTC

Re: Coding: Fleeting Thoughts

Postby raudorn » Fri Jun 20, 2014 7:30 pm UTC

I've heard it doesn't run on many browsers (works fine on vanilla FF 30.0). It's likely a ridiculous amount of various javascript frameworks stacked upon each other, so it's not surprising something doesn't work.
It's a code editor where you define a function that is called as fast a possible with the time since the beginning of playback as parameter and the output of your function (capped to (-1,1)) is fed into the audio buffer. Pretty basic, but ofc people started to derive whole orchestras from it.

User avatar
chridd
Has a vermicelli title
Posts: 846
Joined: Tue Aug 19, 2008 10:07 am UTC
Location: ...Earth, I guess?
Contact:

Re: Coding: Fleeting Thoughts

Postby chridd » Fri Jun 20, 2014 8:44 pm UTC

DR6 wrote:
chridd wrote:...I just get a solid brown screen. Not a particularly pleasant color of brown, but that wouldn't be enough to make it evil...
Not sure what was supposed to happen.
Unless it's all those CSS errors on the console that are supposed to be evil? (Also says AudioContext is not defined.)
Edit: or the horrible formatting in the JavaScript?


That's your problem. I'm on Firefox, try there. Also, have audio on and all the stuff.
I'm using Firefox, too (version 16.0.2, the last version that will run on my version of Mac OS).
~ chri d. d. /tʃɹɪ.di.di/ (Phonotactics, schmphonotactics) · she · Forum game scores
mittfh wrote:I wish this post was very quotable...

User avatar
Xanthir
My HERO!!!
Posts: 5426
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Coding: Fleeting Thoughts

Postby Xanthir » Fri Jun 20, 2014 8:46 pm UTC

Then yes, you're super-screwed, as you're almost two years out of date.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5101
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Fri Jun 20, 2014 8:51 pm UTC

I think I've become complacent.

When I get told "Do this". I look into how to do it, and uncover these terrible things like "\\Only needed in sprint Y remove in sprint X", and X was over a year ago.

And then I find out the terrible way they've done things, and at this point, there's no other sane way to do it so I just add to the horribleness.

User avatar
Jplus
Posts: 1721
Joined: Wed Apr 21, 2010 12:29 pm UTC
Location: Netherlands

Re: Coding: Fleeting Thoughts

Postby Jplus » Fri Jun 20, 2014 11:06 pm UTC

chridd wrote:version that will run on my version of Mac OS).

You might like to learn about TenFourFox.

As an aside, the site runs fine on Safari 7.
"There are only two hard problems in computer science: cache coherence, naming things, and off-by-one errors." (Phil Karlton and Leon Bambrick)

coding and xkcd combined

(Julian/Julian's)

User avatar
PM 2Ring
Posts: 3715
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Sydney, Australia

Re: Coding: Fleeting Thoughts

Postby PM 2Ring » Mon Jun 23, 2014 6:34 am UTC

NecklaceOfShadow wrote:I was going to rant, "I really need to stop trying to do in python what is far better accomplished in bash."

But then after trying to code this up in bash, I realized (again) that doing things in bash is a pain in the ass, and bash can go pound sand.


I can relate to that. Bash is ok if you're using it all the time, otherwise it's hard to remember the arcane intricacies of word splitting and expansion. OTOH, I admit that it's generally a PITA when a bash script has to cope with pathnames that contain spaces and/or quotes. I try to make life simpler by avoiding such things on my computer - I have a Python script that cleans up that sort of crap, which I use mostly on audio & video files.

As an alternative to using Python as an enhanced bash, maybe you should give awk a go. True, awk has its own quirks, but its syntax for interacting with shell programs is pretty clean. I've mostly neglected awk since I learned Python, but I still find it handy for line-oriented text processing.

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5101
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Tue Jun 24, 2014 9:03 pm UTC

Code: Select all

new Dictionary<List<int>, string>();
Wait... what...

Code: Select all

dict.Keys.ToList()[0].Contains(foo)
No... no no no... wait. There's only one "key"? WHY?

Code: Select all

new Dictionary<decimal, Dictionary<List<int>, string>() { ... omitting the horrible lookup table... }
Can we redefine "dictionary attack" to be an assault on your fellow developers?

User avatar
Sizik
Posts: 1261
Joined: Wed Aug 27, 2008 3:48 am UTC

Re: Coding: Fleeting Thoughts

Postby Sizik » Tue Jun 24, 2014 9:52 pm UTC

Leaving automation to run over the weekend + Code getting stuck in a loop + Selenium generating ~50 lines of debug message per second = 12 gigabyte log file.
she/they
gmalivuk wrote:
King Author wrote:If space (rather, distance) is an illusion, it'd be possible for one meta-me to experience both body's sensory inputs.
Yes. And if wishes were horses, wishing wells would fill up very quickly with drowned horses.

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6598
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Tue Jun 24, 2014 10:07 pm UTC

I generally recommend avoiding infinite loops.
Summum ius, summa iniuria.

Volcano99
Posts: 56
Joined: Wed Dec 16, 2009 10:10 pm UTC
Location: 350 km SW of The Castle

Re: Coding: Fleeting Thoughts

Postby Volcano99 » Wed Jun 25, 2014 9:33 am UTC

PM 2Ring wrote:I admit that it's generally a PITA when a bash script has to cope with pathnames that contain spaces and/or quotes. I try to make life simpler by avoiding such things on my computer - I have a Python script that cleans up that sort of crap, which I use mostly on audio & video files.


The same could be accomplished by this unix tool:

Code: Select all

rename "s/\s+/_/" *


The amount of unix tools is amazing. Post more unknown tools!

User avatar
PM 2Ring
Posts: 3715
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Sydney, Australia

Re: Coding: Fleeting Thoughts

Postby PM 2Ring » Wed Jun 25, 2014 10:30 am UTC

Volcano99 wrote:
PM 2Ring wrote:I admit that it's generally a PITA when a bash script has to cope with pathnames that contain spaces and/or quotes. I try to make life simpler by avoiding such things on my computer - I have a Python script that cleans up that sort of crap, which I use mostly on audio & video files.


The same could be accomplished by this unix tool:

Code: Select all

rename "s/\s+/_/" *



I quite like rename, and I used to use it for cleaning up ripped CD filenames, but I decided that I wanted something a little more sophisticated. And rather than writing a bash script calling rename with an arcane regex so I decided to do it in Python, so that I could transform the filename in several stages. My script supports the -n and -v options of rename, but it doesn't (yet) check if the filename already exists.
[EDIT: I just remembered that rename supports multiple commands inside its perlexpr argument, so the regex stuff could be done in stages rather than in one horrible expression. Oh well. :) ]

First it removes single and double quotes, commas and dots (apart from a final dot, so the filename extension is preserved), then it capitalizes words, then converts ampersands to '+' (or 'And'), converts ' - ' to '_', then finally removes any remaining spaces. It accepts multiple arguments (including glob patterns, since they are expanded by the shell). It can process single files, or whole directories; when renaming a directory, the contents of the directory are renamed first.

Volcano99 wrote:The amount of unix tools is amazing. Post more unknown tools!

I hope that rename isn't unknown! But I admit that I'd been using Linux for at least a year before I stumbled on it.

But one amazing command line program that many people have but don't know about is dot and its relatives in the graphviz family, which draw graphs from a description given in a fairly simple plain text format.
Last edited by PM 2Ring on Wed Jun 25, 2014 1:00 pm UTC, edited 1 time in total.

Wonderbolt
Posts: 212
Joined: Thu Mar 13, 2014 12:11 pm UTC

Re: Coding: Fleeting Thoughts

Postby Wonderbolt » Wed Jun 25, 2014 11:35 am UTC

Is C++ still worth learning? I know a dozen nice languages, and don't really expect (or hope) to have to use C++ at some point in my career, but it *is* one of the biggest languages. Other than its use and strength in industry, is there any good reason to learn the language?

PM 2Ring wrote:I hope that rename isn't unknown! But I admit that I'd been using Linux for at least a year before I stumbled on it.

I've been using Linux for yeaaaaars, and this is the first time I heard of it. :oops:

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Wed Jun 25, 2014 12:05 pm UTC

Absolutely. The beauty of C++ is that it offers the ability of writing high level code while you're still able to tell how that code is actually executed on your processor. In addition to that C++ is arguably the most flexible (imperative, compiled) programming language.

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Wed Jun 25, 2014 6:39 pm UTC

The other day, I wrote a bash script that ran an awk program generated with bash using an awk program generated with bash.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5101
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Wed Jun 25, 2014 8:46 pm UTC

Code: Select all

Math.Max(0, Math.Abs(fee))

That sure is some important maximizing.

User avatar
Aaeriele
Posts: 2127
Joined: Tue Feb 23, 2010 3:30 am UTC
Location: San Francisco, CA

Re: Coding: Fleeting Thoughts

Postby Aaeriele » Thu Jun 26, 2014 1:09 am UTC

Sizik wrote:Leaving automation to run over the weekend + Code getting stuck in a loop + Selenium generating ~50 lines of debug message per second = 12 gigabyte log file.


Could be worse:

Code: Select all

$ grep -R foo . > output.txt


(Yep, I accidentally did that once.)
Vaniver wrote:Harvard is a hedge fund that runs the most prestigious dating agency in the world, and incidentally employs famous scientists to do research.

afuzzyduck wrote:ITS MEANT TO BE FLUTTERSHY BUT I JUST SEE AAERIELE! CURSE YOU FORA!

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6598
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Thu Jun 26, 2014 1:44 am UTC

Aaeriele wrote:
Sizik wrote:Leaving automation to run over the weekend + Code getting stuck in a loop + Selenium generating ~50 lines of debug message per second = 12 gigabyte log file.


Could be worse:

Code: Select all

$ grep -R foo . > output.txt


(Yep, I accidentally did that once.)


Umm... I'm not sure I understand the problem. What did you intend?
Summum ius, summa iniuria.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Thu Jun 26, 2014 3:24 am UTC

My favorite that I've done was something like tar cvf stuff.tar .

There are some easily-detectable conditions that I really wish that Unix utilities would detect and at least give you a warning about...

User avatar
Xanthir
My HERO!!!
Posts: 5426
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Coding: Fleeting Thoughts

Postby Xanthir » Thu Jun 26, 2014 5:33 am UTC

You, sir, name? wrote:The other day, I wrote a bash script that ran an awk program generated with bash using an awk program generated with bash.

Please parenthesize this sentence, as it has several valid parses, and I'm wondering which one is intended.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

User avatar
Aaeriele
Posts: 2127
Joined: Tue Feb 23, 2010 3:30 am UTC
Location: San Francisco, CA

Re: Coding: Fleeting Thoughts

Postby Aaeriele » Thu Jun 26, 2014 7:32 am UTC

Thesh wrote:
Aaeriele wrote:
Sizik wrote:Leaving automation to run over the weekend + Code getting stuck in a loop + Selenium generating ~50 lines of debug message per second = 12 gigabyte log file.


Could be worse:

Code: Select all

$ grep -R foo . > output.txt


(Yep, I accidentally did that once.)


Umm... I'm not sure I understand the problem. What did you intend?


The goal was to find all of the lines containing "foo" that were in files in the current directory, and write those lines to another file.
The result was to find all of the lines containing "foo" in the current directory, and write those lines to another file...in the current directory.
Can you figure out why this was bad? :)
Vaniver wrote:Harvard is a hedge fund that runs the most prestigious dating agency in the world, and incidentally employs famous scientists to do research.

afuzzyduck wrote:ITS MEANT TO BE FLUTTERSHY BUT I JUST SEE AAERIELE! CURSE YOU FORA!

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6598
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Thu Jun 26, 2014 7:47 am UTC

Ah, that slipped past me...
Summum ius, summa iniuria.

User avatar
Diadem
Posts: 5654
Joined: Wed Jun 11, 2008 11:03 am UTC
Location: The Netherlands

Re: Coding: Fleeting Thoughts

Postby Diadem » Thu Jun 26, 2014 9:10 am UTC

Wonderbolt wrote:Is C++ still worth learning? I know a dozen nice languages, and don't really expect (or hope) to have to use C++ at some point in my career, but it *is* one of the biggest languages. Other than its use and strength in industry, is there any good reason to learn the language?

Absolutely yes.

In addition to what korona wrote, C++ is still unparalleled in performance, among languages at a similar or higher level. It also has better tooling than any other language, because it is so widely used.

The beauty of C++ is that it is low level enough that you can still see what is going on at the hardware level. This is very useful knowledge for programmers, making experience with C++ or other low level languages very useful, even for programmers who otherwise always write high-level stuff. This low level approach also allows you to squeeze almost every drop of performance out of your computer. At the same time C++ is high level enough to allow you to write very complex programs with a very high level of abstraction.

This makes C++ a language that may not always be the best tool for the job, but always a good tool for the job. A time-critical application may be best written in assembler, of some hardware-specific language, but you can write it in C++ with only a small hit in performance. A small script may be best written in python or bash, but you can write it in C++ in a reasonable amount of time. A user-interface may be best written in C# or Java, but you can write it in C++ without too much additional effort. This huge flexibility is unique to C++.

C++ also has a number of disadvantages. The main one being that so many C++ programmers refuse to write C++, but instead write "C-with-classes", which can quickly turn any structured program into a huge pile of premium grade manure. But C++ has advantages that no other language has, and as long as that is the case (and there are no signs of this changing in the near future), C++ will remain in heavy use in the industry.
It's one of those irregular verbs, isn't it? I have an independent mind, you are an eccentric, he is round the twist
- Bernard Woolley in Yes, Prime Minister

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Thu Jun 26, 2014 5:51 pm UTC

Xanthir wrote:
You, sir, name? wrote:The other day, I wrote a bash script that ran an awk program generated with bash using an awk program generated with bash.

Please parenthesize this sentence, as it has several valid parses, and I'm wondering which one is intended.


I wrote a program in bash.
The program invoked awk.
The awk program was generated with bash, in part using awk.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

bittyx
Posts: 194
Joined: Tue Sep 25, 2007 9:10 pm UTC
Location: Belgrade, Serbia

Re: Coding: Fleeting Thoughts

Postby bittyx » Thu Jun 26, 2014 6:19 pm UTC

Diadem wrote:
Wonderbolt wrote:Is C++ still worth learning? I know a dozen nice languages, and don't really expect (or hope) to have to use C++ at some point in my career, but it *is* one of the biggest languages. Other than its use and strength in industry, is there any good reason to learn the language?

Absolutely yes.

In addition to what korona wrote, C++ is still unparalleled in performance, among languages at a similar or higher level. It also has better tooling than any other language, because it is so widely used.

The beauty of C++ is that it is low level enough that you can still see what is going on at the hardware level. This is very useful knowledge for programmers, making experience with C++ or other low level languages very useful, even for programmers who otherwise always write high-level stuff. This low level approach also allows you to squeeze almost every drop of performance out of your computer. At the same time C++ is high level enough to allow you to write very complex programs with a very high level of abstraction.

This makes C++ a language that may not always be the best tool for the job, but always a good tool for the job. A time-critical application may be best written in assembler, of some hardware-specific language, but you can write it in C++ with only a small hit in performance. A small script may be best written in python or bash, but you can write it in C++ in a reasonable amount of time. A user-interface may be best written in C# or Java, but you can write it in C++ without too much additional effort. This huge flexibility is unique to C++.

C++ also has a number of disadvantages. The main one being that so many C++ programmers refuse to write C++, but instead write "C-with-classes", which can quickly turn any structured program into a huge pile of premium grade manure. But C++ has advantages that no other language has, and as long as that is the case (and there are no signs of this changing in the near future), C++ will remain in heavy use in the industry.


Another yes on this topic!

I've started programming when I was young, starting with BASIC and Pascal, and later in high school I studied C, C++, Assembler, Prolog, and a few others. Of course, this was high school, so the courses weren't aiming for a deep understanding of the languages, the focus was mostly on programming concepts, structures and algorithms and stuff like that. I now work as a web developer - ie. mostly PHP, Javascript, and random scripting in various languages, whichever seems easy to use when I need something done. Obviously, the work I do today has nothing to do with the low-level stuff done in ASM, I've never had to solve the knapsack problem, I've rarely had to use recursion to solve a problem - most of my work comes down to designing a database, and figuring out the most suitable architecture for implementing a project - but I still consider the experience I've had with those languages invaluable to understanding programming and computers on a deeper level, and making it easy to figure out new concepts when I run into them. A bit of a contrived example maybe, but the first time I wrote some PHP code that interacts with a database (which was a long time ago), it was intuitive to me that I shouldn't run SQL queries within a loop, and I immediately understood why it was a bad idea. While this may seem trivial, my experience tells me that it isn't so obvious to many people, including some very talented developers I've worked with, who just haven't been exposed to certain concepts early one - they definitely get it once it's explained to them, or once they spend more time thinking about it on their own, it's just that it's not immediately obvious to them (I've chosen the example because it's fairly common to mention it to new developers, under the assumption that it's not intuitive for them).

I understand you've said that you're already familiar with a bunch of languages, so perhaps this doesn't apply to you, but you didn't mention which ones, and I just wanted to expand on the topic of "having experience with a low level language is extremely useful, even when writing very high-level code". From beginner's concepts like pointers, memory allocation, etc. to advanced object-oriented ideas like polymorphic classes or pure virtual functions, or templating - all are extremely useful for gaining a deeper knowledge of how computer programs work, even if you don't use them directly in your everyday work (I realize that some of this also applies to C, but I've mentioned it because others also seemed to include it in their answers). And by no means do I consider myself an expert on C++ (I don't even consider myself intermediate - for example, I can't even read some of the template craziness Yakk seems to write here from time to time), but the little knowledge I have of the language is still something I think has helped me a lot in my programming career.

Cheers!

Wonderbolt
Posts: 212
Joined: Thu Mar 13, 2014 12:11 pm UTC

Re: Coding: Fleeting Thoughts

Postby Wonderbolt » Thu Jun 26, 2014 10:34 pm UTC

Yeah, I should probably have specified which languages I was fluent in. When I need to write low-level code, I use either C or sometimes (if I'm on an x86 CPU) assembly. For higher level programs, I use Haskell, Python, or (mostly in projects at uni, because I'm not a fan of the verbosity) Java. I'm also familiar with quite a lot of other languages, but C and Haskell are what I prefer for most things.

Given this, I don't really see the point of learning C++ (personally, of course), even given the points people have raised. If I want to get low-level access to memory and hardware, I like something simple like C. If I want to write a bigger, more high-level program, I use Haskell. If I need to combine both, I use Haskell's FFI to access C functionality directly. I mean, C++ might add some little things in some places, but I've seen a lot of C++ code, and it really doesn't look like the kind of language I'd enjoy programming in.

User avatar
Jplus
Posts: 1721
Joined: Wed Apr 21, 2010 12:29 pm UTC
Location: Netherlands

Re: Coding: Fleeting Thoughts

Postby Jplus » Fri Jun 27, 2014 9:09 am UTC

If you switch to C++ for the things you currently use C for, that's already an instant win.

C++ is unique because it combines powerful abstraction facilities (on par with Haskell and Ocaml, but in my opinion with a better designed standard library) with systems/hardware programming and tons of support. Combining Haskell with C just to avoid C++ to me seems like... well, doing something arduous and hopelessly hypocritical (not to mention suboptimal) just to avoid C++.

That other people write ugly code in C++ (the drawback of it being rich and popular at the same time) does not mean that you have to do the same. C++ allows you to write elegant and concise code, especially since C++11.

However, you'll have to accept that you remain an absolute beginner for at least the first several years. Even if you're already a 1337 programmer.
"There are only two hard problems in computer science: cache coherence, naming things, and off-by-one errors." (Phil Karlton and Leon Bambrick)

coding and xkcd combined

(Julian/Julian's)

User avatar
jestingrabbit
Factoids are just Datas that haven't grown up yet
Posts: 5967
Joined: Tue Nov 28, 2006 9:50 pm UTC
Location: Sydney

Re: Coding: Fleeting Thoughts

Postby jestingrabbit » Fri Jun 27, 2014 3:48 pm UTC

Xeio wrote:

Code: Select all

Math.Max(0, Math.Abs(fee))

That sure is some important maximizing.


What does is it do if fee is NaN?
ameretrifle wrote:Magic space feudalism is therefore a viable idea.

User avatar
ahammel
My Little Cabbage
Posts: 2135
Joined: Mon Jan 30, 2012 12:46 am UTC
Location: Vancouver BC
Contact:

Re: Coding: Fleeting Thoughts

Postby ahammel » Fri Jun 27, 2014 5:31 pm UTC

I think I'm going to try working with extremely minimal syntax highlighting. Comments and strings (or just docstrings) in a slightly lighter face than the rest of the code.
He/Him/His/Alex
God damn these electric sex pants!

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5101
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Fri Jun 27, 2014 6:47 pm UTC

jestingrabbit wrote:
Xeio wrote:

Code: Select all

Math.Max(0, Math.Abs(fee))
That sure is some important maximizing.
What does is it do if fee is NaN?
In this case fee is a decimal, so NaN doesn't exist.

Though Math.Max returns NaN if either argument is NaN so it would still not make any sense that way either.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11129
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Sat Jun 28, 2014 3:44 am UTC

Jplus wrote:If you switch to C++ for the things you currently use C for, that's already an instant win.
C with RAII and typed_malloc and auto and std::sort and vector and range-for is a big win.

At least that is what I find when I modify C-like code to update it.

C++ is 3-5 languages in one (template, vanilla, and preprocessor obviously: I could make a case for constexpr, expression templates, and a few other techniques as being sufficiently alien asto constitute a distinct dialect), but you can make do with cargo-culting everything except vanilla and still get a language with large advantages over C for low level code.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 8 guests