Stream of consciousness is a style of writing that strives to mimic the actual flow of real human thought. Often, stream of consciousness narratives are messy, lack a logical structure, and/ or flout the basic rules of grammar, all because human thought generally does not abide by regular writing rules and conventions. Though stream of consciousness has been used in many different periods and is still popular today, the technique was especially popular among Modernist authors, including Virginia Woolf and James Joyce.
In A Portrait of the Artist as a Young Man, Joyce uses a stream of consciousness narrative very effectively. Throughout the novel, the sophistication of the prose improves as the protagonist, Stephen Dedalus, grows up and matures. Thus, the beginning of the narrative is written to mirror the simplistic consciousness of a very small child, while the end of the novel displays the complex thoughts of a highly educated young man. Joyce therefore uses stream of consciousness because his prose changes style to mirror the different, evolving consciousnesses of a growing person. Accordingly, it's hardly surprising that the novel is known for being difficult to read, although it's not quite as challenging as Joyce's next novel, Ulysses, which also employs a masterful stream of consciousness narrative.